Skip to content

Commit

Permalink
web service MDL-12886 if the groupid doesn't exist, groups_remove_mem…
Browse files Browse the repository at this point in the history
…ber and groups_add_member return now exception (not a boolean as before)
  • Loading branch information
jerome committed Mar 9, 2009
1 parent 15b60b6 commit 9c000a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions admin/uploaduser.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,11 @@
$gid = $ccache[$shortname]->groups[$addgroup]->id;
$gname = $ccache[$shortname]->groups[$addgroup]->name;

if (groups_add_member($gid, $user->id)) {
$upt->track('enrolments', get_string('addedtogroup', '', $gname));
} else {
try {
if (groups_add_member($gid, $user->id)) {
$upt->track('enrolments', get_string('addedtogroup', '', $gname));
}
} catch (moodle_exception $e) {
$upt->track('enrolments', get_string('addedtogroupnot', '', $gname), 'error');
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions group/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function groups_add_member($groupid, $userid) {
}

if (!groups_group_exists($groupid)) {
return false;
throw new moodle_exception('cannotaddmembergroupiddoesntexist');
}

if (groups_is_member($groupid, $userid)) {
Expand Down Expand Up @@ -68,7 +68,7 @@ function groups_remove_member($groupid, $userid) {
}

if (!groups_group_exists($groupid)) {
return false;
throw new moodle_exception('cannotaddmembergroupiddoesntexist');
}

if (!groups_is_member($groupid, $userid)) {
Expand Down
6 changes: 3 additions & 3 deletions group/simpletest/testexternal.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
require_once(dirname(dirname(dirname(__FILE__))) . '/user/lib.php');

class group_external_test extends UnitTestCase {
/*
/*
var $realDB;
var $group;
var $group2;
Expand Down Expand Up @@ -201,8 +201,8 @@ function testTmp_add_group_members() {
function testTmp_add_group_members2() {
//the group id doesn't exist
$params = array(array("groupid" => 6465465, "userid" => $this->userid3), array("groupid" => $this->group->id, "userid" => $this->userid4));
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
$result = group_external::tmp_add_groupmembers($params);
$this->assertEqual($result, false);
}
function testTmp_delete_group_members() {
Expand All @@ -215,8 +215,8 @@ function testTmp_delete_group_members() {
function testTmp_delete_group_members2() {
//the group id doesn't exist
$params = array(array("groupid" => 6465465, "userid" => $this->userid1), array("groupid" => $this->group->id, "userid" => $this->userid2));
$this->expectException(new moodle_exception('cannotaddmembergroupiddoesntexist'));
$result = group_external::tmp_delete_groupmembers($params);
$this->assertEqual($result, false);
}
function testTmp_delete_group_members3() {
Expand Down

0 comments on commit 9c000a9

Please sign in to comment.