Issue Details (XML | Word | Printable)

Key: MDL-16816
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Dan Poltawski
Reporter: Gerd Goetschalckx
Votes: 0
Watchers: 1
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Function 'role_assign' does not return the id of the assignment

Created: 07/Oct/08 10:27 PM   Updated: 09/Oct/08 09:54 PM
Component/s: Enrolments
Affects Version/s: 1.9.2, 2.0
Fix Version/s: 2.0

Environment: Solaris 10, Oracle 10.2.0.2, version 1.9.2+ build 20080716

Database: Oracle
Participants: Dan Poltawski and Gerd Goetschalckx
Security Level: None
Resolved date: 09/Oct/08
Affected Branches: MOODLE_19_STABLE, MOODLE_20_STABLE
Fixed Branches: MOODLE_20_STABLE


 Description  « Hide
The documentation of the function 'role_assign' says that the function returns the new id of the assignment, but actually the function returns 'true' if successfull, false otherwise. I would suggest to change the implementation to match the documentation. When unsuccessfull, the function should still return false. This should not break existing code, as the id is > 0, and therefore will evaluate to true. I can provide a patch. This is a problem for us, as we need the id to integrate with our other backend systems.

The issue is not visible. In order to experience it, write code that calls the function 'role_assign' with valid arguments, then print out the return value. But it is probably a lot easier just reading the code.
The actual result is true, the expected result is $ra->id



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Dan Poltawski added a comment - 08/Oct/08 04:12 AM
Hmm, this is a pretty simple fix worth considering..

diff --git a/lib/accesslib.php b/lib/accesslib.php
index 84a731d..847897e 100755
— a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -2803,7 +2803,7 @@ function role_assign($roleid, $userid, $groupid, $contexti

events_trigger('role_assigned', $ra);

  • return true;
    + return $ra->id;
    }

Dan Poltawski added a comment - 08/Oct/08 04:16 AM
Hi Gerd,

Thanks for the report - I'm going to fix this in HEAD and we can then leave it a while to see if it breaks anything major before considering applying to 1.9.

I suspect it was an oversight in the 1.9 accesslib overhaul.


Dan Poltawski added a comment - 09/Oct/08 09:54 PM
I've fixed this in HEAD - I would not like to attempt this fix in 1.9 at the moment