/** * Test get_enrolled_users */ public function test_enrol_users() { global $DB; $this->resetAfterTest(true); $user = self::getDataGenerator()->create_user(); $this->setUser($user); $course1 = self::getDataGenerator()->create_course(); $course2 = self::getDataGenerator()->create_course(); $user1 = self::getDataGenerator()->create_user(); $user2 = self::getDataGenerator()->create_user(); $context1 = context_course::instance($course1->id); $context2 = context_course::instance($course2->id); $instance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST); $instance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST); // Set the required capabilities by the external function. $roleid = $this->assignUserCapability('enrol/manual:enrol', $context1->id); $this->assignUserCapability('moodle/course:view', $context1->id, $roleid); $this->assignUserCapability('moodle/role:assign', $context1->id, $roleid); $this->assignUserCapability('enrol/manual:enrol', $context2->id, $roleid); $this->assignUserCapability('moodle/course:view', $context2->id, $roleid); $this->assignUserCapability('moodle/role:assign', $context2->id, $roleid); allow_assign($roleid, 3); // Call the external function. enrol_manual_external::enrol_users(array(array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course1->id), array('roleid' => 3, 'userid' => $user2->id, 'courseid' => $course1->id))); $this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid' => $instance1->id))); $this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid' => $instance2->id))); $this->assertTrue(is_enrolled($context1, $user1)); $this->assertTrue(is_enrolled($context1, $user2)); // Call without required capability. $DB->delete_records('user_enrolments'); $this->unassignUserCapability('enrol/manual:enrol', $context1->id, $roleid); try { enrol_manual_external::enrol_users(array(array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course1->id))); $this->fail('Exception expected if not having capability to enrol'); } catch (moodle_exception $e) { $this->assertInstanceOf('required_capability_exception', $e); $this->assertSame('nopermissions', $e->errorcode); } $this->assignUserCapability('enrol/manual:enrol', $context1->id, $roleid); $this->assertEquals(0, $DB->count_records('user_enrolments')); // Call with forbidden role. try { enrol_manual_external::enrol_users(array(array('roleid' => 1, 'userid' => $user1->id, 'courseid' => $course1->id))); $this->fail('Exception expected if not allowed to assign role.'); } catch (moodle_exception $e) { $this->assertSame('wsusercannotassign', $e->errorcode); } $this->assertEquals(0, $DB->count_records('user_enrolments')); // Call for course without manual instance. $DB->delete_records('user_enrolments'); $DB->delete_records('enrol', array('courseid' => $course2->id)); try { enrol_manual_external::enrol_users(array(array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course1->id), array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course2->id))); $this->fail('Exception expected if course does not have manual instance'); } catch (moodle_exception $e) { $this->assertSame('wsnoinstance', $e->errorcode); } }
/** * Test allowing of role assignments. */ public function test_allow_assign() { global $DB, $CFG; $this->resetAfterTest(); $otherid = create_role('Other role', 'other', 'Some other role', ''); $student = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST); $this->assertFalse($DB->record_exists('role_allow_assign', array('roleid' => $otherid, 'allowassign' => $student->id))); allow_assign($otherid, $student->id); $this->assertTrue($DB->record_exists('role_allow_assign', array('roleid' => $otherid, 'allowassign' => $student->id))); // Test event trigger. $allowroleassignevent = \core\event\role_allow_assign_updated::create(array('context' => context_system::instance())); $sink = $this->redirectEvents(); $allowroleassignevent->trigger(); $events = $sink->get_events(); $sink->close(); $event = array_pop($events); $this->assertInstanceOf('\\core\\event\\role_allow_assign_updated', $event); $mode = 'assign'; $baseurl = new moodle_url('/admin/roles/allow.php', array('mode' => $mode)); $expectedlegacylog = array(SITEID, 'role', 'edit allow ' . $mode, str_replace($CFG->wwwroot . '/', '', $baseurl)); $this->assertEventLegacyLogData($expectedlegacylog, $event); }
/** * Test allowing of role assignments. * @return void */ public function test_allow_assign() { global $DB; $this->resetAfterTest(); $otherid = create_role('Other role', 'other', 'Some other role', ''); $student = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST); $this->assertFalse($DB->record_exists('role_allow_assign', array('roleid' => $otherid, 'allowassign' => $student->id))); allow_assign($otherid, $student->id); $this->assertTrue($DB->record_exists('role_allow_assign', array('roleid' => $otherid, 'allowassign' => $student->id))); }
/** * function that creates a role * @param name - role name * @param shortname - role short name * @param description - role description * @param legacy - optional legacy capability * @return id or false */ function create_role($name, $shortname, $description, $legacy = '') { // check for duplicate role name if ($role = get_record('role', 'name', $name)) { error('there is already a role with this name!'); } if ($role = get_record('role', 'shortname', $shortname)) { error('there is already a role with this shortname!'); } $role = new object(); $role->name = $name; $role->shortname = $shortname; $role->description = $description; //find free sortorder number $role->sortorder = count_records('role'); while (get_record('role', 'sortorder', $role->sortorder)) { $role->sortorder += 1; } if (!($context = get_context_instance(CONTEXT_SYSTEM))) { return false; } if ($id = insert_record('role', $role)) { if ($legacy) { assign_capability($legacy, CAP_ALLOW, $id, $context->id); } /// By default, users with role:manage at site level /// should be able to assign users to this new role, and override this new role's capabilities // find all admin roles if ($adminroles = get_roles_with_capability('moodle/role:manage', CAP_ALLOW, $context)) { // foreach admin role foreach ($adminroles as $arole) { // write allow_assign and allow_overrid allow_assign($arole->id, $id); allow_override($arole->id, $id); } } return $id; } else { return false; } }
/** * @package mod * @subpackage adobeconnect * @author Akinsaya Delamarre (adelamarre@remote-learner.net) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_adobeconnect_install() { global $DB; // The commented out code is waiting for a fix for MDL-25709 $result = true; $timenow = time(); $sysctx = get_context_instance(CONTEXT_SYSTEM); $mrole = new stdClass(); $levels = array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE); $param = array('shortname' => 'coursecreator'); $coursecreatorrid = $DB->get_record('role', $param); $param = array('shortname' => 'editingteacher'); $editingteacherrid = $DB->get_record('role', $param); $param = array('shortname' => 'teacher'); $teacherrid = $DB->get_record('role', $param); /// Fully setup the Adobe Connect Presenter role. $param = array('shortname' => 'adobeconnectpresenter'); if (!($mrole = $DB->get_record('role', $param))) { if ($rid = create_role(get_string('adobeconnectpresenter', 'adobeconnect'), 'adobeconnectpresenter', get_string('adobeconnectpresenterdescription', 'adobeconnect'), 'adobeconnectpresenter')) { $mrole->id = $rid; $result = assign_capability('mod/adobeconnect:meetingpresenter', CAP_ALLOW, $mrole->id, $sysctx->id); set_role_contextlevels($mrole->id, $levels); } else { $result = false; } } $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($coursecreatorrid->id, $mrole->id); } $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($editingteacherrid->id, $mrole->id); } $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($teacherrid->id, $mrole->id); } /// Fully setup the Adobe Connect Participant role. $param = array('shortname' => 'adobeconnectparticipant'); if (!($mrole = $DB->get_record('role', $param))) { if ($rid = create_role(get_string('adobeconnectparticipant', 'adobeconnect'), 'adobeconnectparticipant', get_string('adobeconnectparticipantdescription', 'adobeconnect'), 'adobeconnectparticipant')) { $mrole->id = $rid; $result = assign_capability('mod/adobeconnect:meetingparticipant', CAP_ALLOW, $mrole->id, $sysctx->id); set_role_contextlevels($mrole->id, $levels); } else { $result = false; } } $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($coursecreatorrid->id, $mrole->id); } $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($editingteacherrid->id, $mrole->id); } $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($teacherrid->id, $mrole->id); } /// Fully setup the Adobe Connect Host role. $param = array('shortname' => 'adobeconnecthost'); if (!($mrole = $DB->get_record('role', $param))) { if ($rid = create_role(get_string('adobeconnecthost', 'adobeconnect'), 'adobeconnecthost', get_string('adobeconnecthostdescription', 'adobeconnect'), 'adobeconnecthost')) { $mrole->id = $rid; $result = assign_capability('mod/adobeconnect:meetinghost', CAP_ALLOW, $mrole->id, $sysctx->id); set_role_contextlevels($mrole->id, $levels); } else { $result = false; } } $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($coursecreatorrid->id, $mrole->id); } $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($editingteacherrid->id, $mrole->id); } $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { $result = allow_assign($teacherrid->id, $mrole->id); } return $result; }
if ($grant = data_submitted()) { foreach ($grant as $grole => $val) { if ($grole == 'dummy') { continue; } $string = explode('_', $grole); $temp[$string[1]][$string[2]] = 1; // if set, means can access } // if current assignment is in data_submitted, ignore, else, write deny into db foreach ($roles as $srole) { foreach ($roles as $trole) { if (isset($temp[$srole->id][$trole->id])) { // if set, need to write to db if (!($record = get_record('role_allow_assign', 'roleid', $srole->id, 'allowassign', $trole->id))) { allow_assign($srole->id, $trole->id); } } else { //if set, means can access, attempt to remove it from db delete_records('role_allow_assign', 'roleid', $srole->id, 'allowassign', $trole->id); } } } // updated allowassigns sitewide... mark_context_dirty($sitecontext->path); } /// displaying form here admin_externalpage_print_header(); $currenttab = 'allowassign'; require_once 'managetabs.php'; $table->tablealign = 'center';
/** * When called resets all custom roles as per definition set down in /local/roles.php * * Note that this uses the non-core role.custom field to isolate roles to remove. * * Utilise the $path parameter to allow for localisation (i.e. different roles defintion than core). * * Sort order is reset based on the order listed in the defintion. * * WARNING: as long as you retain the same shortname existing user role assigments will * be retained. if you change the shortname they will be lost. * * KNOWN ISSUE: we rely on shortname being unique, but this is not enforced by the db. * this is more a problem with moodle. * * @param text $path * */ function tao_reset_custom_roles($path = 'local') { global $CFG; if (!get_site()) { // not finished installing, skip return true; } // get latest role definition from roles file $rolespath = $CFG->dirroot . '/' . $path . '/roles.php'; if (!file_exists($rolespath)) { debugging("Local caps reassignment called with invalid path {$path}"); return false; } require_once $rolespath; if (!isset($customroles)) { return true; // nothing to do. } $undeletableroles = array(); $undeletableroles[$CFG->notloggedinroleid] = 1; $undeletableroles[$CFG->guestroleid] = 1; $undeletableroles[$CFG->defaultuserroleid] = 1; $undeletableroles[$CFG->defaultcourseroleid] = 1; // If there is only one admin role, add that to $undeletableroles too. $adminroles = get_admin_roles(); if (count($adminroles) == 1) { $undeletableroles[reset($adminroles)->id] = 1; } // get recordset of existing custom roles $sql = "SELECT id, name, shortname, description, sortorder, custom\n FROM {$CFG->prefix}role\n WHERE custom IS NOT NULL"; $roles = get_records_sql($sql); // remove custom roles that are not in the latest definition foreach ($roles as $role) { // check whether this role is in the latest definition if (array_key_exists($role->shortname, $customroles)) { continue; } // extra safety: check undeletable roles if (isset($undeletableroles[$role->id])) { continue; } delete_role($role->id); } // hack to avoid sortorder unique constraint execute_sql("UPDATE {$CFG->prefix}role SET sortorder = (sortorder+1000) WHERE custom IS NOT NULL"); // set sortorder to current highest value $sortorder = get_field_sql("SELECT " . sql_max('sortorder') . " FROM {$CFG->prefix}role WHERE custom IS NULL"); // now loop through the new settings foreach ($customroles as $shortname => $role) { $sortorder++; // get the roleid $roleid = get_field('role', 'id', 'shortname', $shortname); // if exists then make updates if (!empty($roleid)) { // only update fields that have been set if (isset($role['name'])) { set_field('role', 'name', $role['name'], 'shortname', $shortname); } if (isset($role['description'])) { set_field('role', 'description', $role['description'], 'shortname', $shortname); } // reset sortorder set_field('role', 'sortorder', $sortorder, 'shortname', $shortname); // else create record } else { $newrole = new stdclass(); $newrole->name = $role['name']; $newrole->shortname = $shortname; $newrole->description = $role['description']; $newrole->sortorder = $sortorder; $newrole->custom = 1; $roleid = insert_record('role', $newrole); } // remove any previously set legacy roles $legacyroles = get_legacy_roles(); foreach ($legacyroles as $ltype => $lcap) { unassign_capability($lcap, $roleid); } // reset legacy role if (isset($role['legacy'])) { $legacycap = $legacyroles[$role['legacy']]; $context = get_context_instance(CONTEXT_SYSTEM); assign_capability($legacycap, CAP_ALLOW, $roleid, $context->id); } // update the context settings set_role_contextlevels($roleid, $role['context']); // e.g. array(CONTEXT_SYSTEM, CONTEXT_COURSECAT) // set allow assigns if (is_array($role['canassign'])) { // delete existing delete_records('role_allow_assign', 'allowassign', $roleid); foreach ($role['canassign'] as $canassign) { $canassignid = get_field('role', 'id', 'shortname', $canassign); allow_assign($canassignid, $roleid); } } } // reset custom capabilities to keep up with changes return tao_reset_capabilities(); }
function elluminate_install() { $result = true; $timenow = time(); $sysctx = get_context_instance(CONTEXT_SYSTEM); $adminrid = get_field('role', 'id', 'shortname', 'admin'); $coursecreatorrid = get_field('role', 'id', 'shortname', 'coursecreator'); $editingteacherrid = get_field('role', 'id', 'shortname', 'editingteacher'); $teacherrid = get_field('role', 'id', 'shortname', 'teacher'); /// Fully setup the Elluminate Moderator role. if ($result && !($mrole = get_record('role', 'shortname', 'elluminatemoderator'))) { if ($rid = create_role(get_string('elluminatemoderator', 'elluminate'), 'elluminatemoderator', get_string('elluminatemoderatordescription', 'elluminate'))) { $mrole = get_record('role', 'id', $rid); $result = $result && assign_capability('mod/elluminate:moderatemeeting', CAP_ALLOW, $mrole->id, $sysctx->id); } else { $result = false; } } if (!count_records('role_allow_assign', 'allowassign', $mrole->id)) { $result = $result && allow_assign($adminrid, $mrole->id); $result = $result && allow_assign($coursecreatorrid, $mrole->id); $result = $result && allow_assign($editingteacherrid, $mrole->id); $result = $result && allow_assign($teacherrid, $mrole->id); } /// Fully setup the Elluminate Participant role. if ($result && !($prole = get_record('role', 'shortname', 'elluminateparticipant'))) { if ($rid = create_role(get_string('elluminateparticipant', 'elluminate'), 'elluminateparticipant', get_string('elluminateparticipantdescription', 'elluminate'))) { $prole = get_record('role', 'id', $rid); $result = $result && assign_capability('mod/elluminate:joinmeeting', CAP_ALLOW, $prole->id, $sysctx->id); } else { $result = false; } } if (!count_records('role_allow_assign', 'allowassign', $prole->id)) { $result = $result && allow_assign($adminrid, $prole->id); $result = $result && allow_assign($coursecreatorrid, $prole->id); $result = $result && allow_assign($editingteacherrid, $prole->id); $result = $result && allow_assign($teacherrid, $prole->id); } return $result; }
/** * @package mod * @subpackage adobeconnect * @author Akinsaya Delamarre (adelamarre@remote-learner.net) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_adobeconnect_install() { global $DB; $result = true; $sysctx = context_system::instance(); $levels = array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE); $param = array('shortname' => 'coursecreator'); $coursecreator = $DB->get_records('role', $param, 'id ASC', 'id', 0, 1); if (empty($coursecreator)) { $param = array('archetype' => 'coursecreator'); $coursecreator = $DB->get_records('role', $param, 'id ASC', 'id', 0, 1); } $coursecreatorrid = array_shift($coursecreator); $param = array('shortname' => 'editingteacher'); $editingteacher = $DB->get_records('role', $param, 'id ASC', 'id', 0, 1); if (empty($editingteacher)) { $param = array('archetype' => 'editingteacher'); $editingteacher = $DB->get_records('role', $param, 'id ASC', 'id', 0, 1); } $editingteacherrid = array_shift($editingteacher); $param = array('shortname' => 'teacher'); $teacher = $DB->get_records('role', $param, 'id ASC', 'id', 0, 1); if (empty($teacher)) { $param = array('archetype' => 'teacher'); $teacher = $DB->get_records('role', $param, 'id ASC', 'id', 0, 1); } $teacherrid = array_shift($teacher); // Fully setup the Adobe Connect Presenter role. $param = array('shortname' => 'adobeconnectpresenter'); if (!($mrole = $DB->get_record('role', $param))) { if ($rid = create_role(get_string('adobeconnectpresenter', 'adobeconnect'), 'adobeconnectpresenter', get_string('adobeconnectpresenterdescription', 'adobeconnect'), 'adobeconnectpresenter')) { $mrole = new stdClass(); $mrole->id = $rid; $result = $result && assign_capability('mod/adobeconnect:meetingpresenter', CAP_ALLOW, $mrole->id, $sysctx->id); set_role_contextlevels($mrole->id, $levels); } else { $result = false; } } if (isset($coursecreatorrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($coursecreatorrid->id, $mrole->id); } } if (isset($editingteacherrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($editingteacherrid->id, $mrole->id); } } if (isset($teacherrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($teacherrid->id, $mrole->id); } } // Fully setup the Adobe Connect Participant role. $param = array('shortname' => 'adobeconnectparticipant'); if ($result && !($mrole = $DB->get_record('role', $param))) { if ($rid = create_role(get_string('adobeconnectparticipant', 'adobeconnect'), 'adobeconnectparticipant', get_string('adobeconnectparticipantdescription', 'adobeconnect'), 'adobeconnectparticipant')) { $mrole = new stdClass(); $mrole->id = $rid; $result = $result && assign_capability('mod/adobeconnect:meetingparticipant', CAP_ALLOW, $mrole->id, $sysctx->id); set_role_contextlevels($mrole->id, $levels); } else { $result = false; } } if (isset($coursecreatorrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($coursecreatorrid->id, $mrole->id); } } if (isset($editingteacherrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($editingteacherrid->id, $mrole->id); } } if (isset($teacherrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($teacherrid->id, $mrole->id); } } // Fully setup the Adobe Connect Host role. $param = array('shortname' => 'adobeconnecthost'); if ($result && !($mrole = $DB->get_record('role', $param))) { if ($rid = create_role(get_string('adobeconnecthost', 'adobeconnect'), 'adobeconnecthost', get_string('adobeconnecthostdescription', 'adobeconnect'), 'adobeconnecthost')) { $mrole = new stdClass(); $mrole->id = $rid; $result = $result && assign_capability('mod/adobeconnect:meetinghost', CAP_ALLOW, $mrole->id, $sysctx->id); set_role_contextlevels($mrole->id, $levels); } else { $result = false; } } if (isset($coursecreatorrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($coursecreatorrid->id, $mrole->id); } } if (isset($editingteacherrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($editingteacherrid->id, $mrole->id); } } if (isset($teacherrid->id)) { $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id); if (!$DB->get_record('role_allow_assign', $param)) { allow_assign($teacherrid->id, $mrole->id); } } return $result; }
function xmldb_main_install() { global $CFG, $DB, $SITE; /// make sure system context exists $syscontext = get_system_context(false); if ($syscontext->id != 1) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected system context id created!'); } // create site course $newsite = new object(); $newsite->fullname = ""; $newsite->shortname = ""; $newsite->summary = NULL; $newsite->newsitems = 3; $newsite->numsections = 0; $newsite->category = 0; $newsite->format = 'site'; // Only for this course $newsite->teacher = get_string("defaultcourseteacher"); $newsite->teachers = get_string("defaultcourseteachers"); $newsite->student = get_string("defaultcoursestudent"); $newsite->students = get_string("defaultcoursestudents"); $newsite->timemodified = time(); $DB->insert_record('course', $newsite); $SITE = get_site(); if ($SITE->id != 1) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected site course id created!'); } /// make sure site course context exists get_context_instance(CONTEXT_COURSE, $SITE->id); /// create default course category $cat = get_course_category(); $defaults = array('rolesactive' => '0', 'auth' => 'email', 'auth_pop3mailbox' => 'INBOX', 'enrol' => 'manual', 'enrol_plugins_enabled' => 'manual', 'style' => 'default', 'template' => 'default', 'theme' => 'standardwhite', 'filter_multilang_converted' => 1, 'siteidentifier' => random_string(32) . get_host_from_url($CFG->wwwroot), 'backup_version' => 2008111700, 'backup_release' => '2.0 dev', 'blocks_version' => 2007081300, 'mnet_dispatcher_mode' => 'off', 'sessiontimeout' => 7200, 'stringfilters' => '', 'filterall' => 0, 'texteditors' => 'tinymce,textarea'); foreach ($defaults as $key => $value) { set_config($key, $value); } /// bootstrap mnet $mnethost = new object(); $mnethost->wwwroot = $CFG->wwwroot; $mnethost->name = ''; $mnethost->name = ''; $mnethost->public_key = ''; if (empty($_SERVER['SERVER_ADDR'])) { // SERVER_ADDR is only returned by Apache-like webservers preg_match("@^(?:http[s]?://)?([A-Z0-9\\-\\.]+).*@i", $CFG->wwwroot, $matches); $my_hostname = $matches[1]; $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH! if ($my_ip == $my_hostname) { $mnethost->ip_address = 'UNKNOWN'; } else { $mnethost->ip_address = $my_ip; } } else { $mnethost->ip_address = $_SERVER['SERVER_ADDR']; } $mnetid = $DB->insert_record('mnet_host', $mnethost); set_config('mnet_localhost_id', $mnetid); // Initial insert of mnet applications info $mnet_app = new object(); $mnet_app->name = 'moodle'; $mnet_app->display_name = 'Moodle'; $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php'; $mnet_app->sso_land_url = '/auth/mnet/land.php'; $mnet_app->sso_jump_url = '/auth/mnet/land.php'; $DB->insert_record('mnet_application', $mnet_app); $mnet_app = new object(); $mnet_app->name = 'mahara'; $mnet_app->display_name = 'Mahara'; $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php'; $mnet_app->sso_land_url = '/auth/xmlrpc/land.php'; $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php'; $DB->insert_record('mnet_application', $mnet_app); /// insert log entries - replaces statements section in install.xml update_log_display_entry('user', 'view', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('course', 'user report', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('course', 'view', 'course', 'fullname'); update_log_display_entry('course', 'update', 'course', 'fullname'); update_log_display_entry('course', 'enrol', 'course', 'fullname'); update_log_display_entry('course', 'unenrol', 'course', 'fullname'); update_log_display_entry('course', 'report log', 'course', 'fullname'); update_log_display_entry('course', 'report live', 'course', 'fullname'); update_log_display_entry('course', 'report outline', 'course', 'fullname'); update_log_display_entry('course', 'report participation', 'course', 'fullname'); update_log_display_entry('course', 'report stats', 'course', 'fullname'); update_log_display_entry('message', 'write', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('message', 'read', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('message', 'add contact', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('message', 'remove contact', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('message', 'block contact', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('message', 'unblock contact', 'user', 'CONCAT(firstname,\' \',lastname)'); update_log_display_entry('group', 'view', 'groups', 'name'); /// Create guest record $guest = new object(); $guest->auth = 'manual'; $guest->username = '******'; $guest->password = hash_internal_user_password('guest'); $guest->firstname = get_string('guestuser'); $guest->lastname = ' '; $guest->email = 'root@localhost'; $guest->description = get_string('guestuserinfo'); $guest->mnethostid = $CFG->mnet_localhost_id; $guest->confirmed = 1; $guest->lang = $CFG->lang; $guest->timemodified = time(); $guest->id = $DB->insert_record('user', $guest); /// Now create admin user $admin = new object(); $admin->auth = 'manual'; $admin->firstname = get_string('admin'); $admin->lastname = get_string('user'); $admin->username = '******'; $admin->password = '******'; $admin->email = ''; $admin->confirmed = 1; $admin->mnethostid = $CFG->mnet_localhost_id; $admin->lang = $CFG->lang; $admin->maildisplay = 1; $admin->timemodified = time(); $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr(); // installation hijacking prevention $admin->id = $DB->insert_record('user', $admin); /// Install the roles system. $adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin'); $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator'); $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher'); $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'moodle/legacy:teacher'); $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'moodle/legacy:student'); $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'moodle/legacy:guest'); $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'moodle/legacy:user'); /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id); update_capabilities('moodle'); /// assign default roles role_assign($guestrole, $guest->id, 0, $syscontext->id); role_assign($adminrole, $admin->id, 0, $syscontext->id); /// Default allow assign/override/switch. $defaultallows = array($coursecreatorrole => $noneditteacherrole, $coursecreatorrole => $editteacherrole, $coursecreatorrole => $studentrole, $coursecreatorrole => $guestrole, $editteacherrole => $noneditteacherrole, $editteacherrole => $studentrole, $editteacherrole => $guestrole); foreach ($defaultallows as $fromroleid => $toroleid) { allow_assign($fromroleid, $toroleid); allow_override($fromroleid, $toroleid); // There is a rant about this in MDL-15841. allow_switch($fromroleid, $toroleid); } allow_switch($noneditteacherrole, $studentrole); /// Set up the context levels where you can assign each role. set_role_contextlevels($adminrole, get_default_contextlevels('admin')); set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator')); set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher')); set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher')); set_role_contextlevels($studentrole, get_default_contextlevels('student')); set_role_contextlevels($guestrole, get_default_contextlevels('guest')); set_role_contextlevels($userrole, get_default_contextlevels('user')); }
/** * Execute post-install custom actions for the module * This function was added in 1.9 * * @return boolean true if success, false on error */ function adobeconnect_install() { $result = true; $timenow = time(); $sysctx = get_context_instance(CONTEXT_SYSTEM); // $adminrid = get_field('role', 'id', 'shortname', 'admin'); $coursecreatorrid = get_field('role', 'id', 'shortname', 'coursecreator'); $editingteacherrid = get_field('role', 'id', 'shortname', 'editingteacher'); $teacherrid = get_field('role', 'id', 'shortname', 'teacher'); /// Fully setup the Adobe Connect Presenter role. if ($result && !($mrole = get_record('role', 'shortname', 'adobeconnectpresenter'))) { if ($rid = create_role(get_string('adobeconnectpresenter', 'adobeconnect'), 'adobeconnectpresenter', get_string('adobeconnectpresenterdescription', 'adobeconnect'))) { $mrole = get_record('role', 'id', $rid); $result = $result && assign_capability('mod/adobeconnect:meetingpresenter', CAP_ALLOW, $mrole->id, $sysctx->id); } else { $result = false; } } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $coursecreatorrid)) { $result = $result && allow_assign($coursecreatorrid, $mrole->id); } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $editingteacherrid)) { $result = $result && allow_assign($editingteacherrid, $mrole->id); } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $teacherrid)) { $result = $result && allow_assign($teacherrid, $mrole->id); } /// Fully setup the Adobe Connect Participant role. if ($result && !($mrole = get_record('role', 'shortname', 'adobeconnectparticipant'))) { if ($rid = create_role(get_string('adobeconnectparticipant', 'adobeconnect'), 'adobeconnectparticipant', get_string('adobeconnectparticipantdescription', 'adobeconnect'))) { $mrole = get_record('role', 'id', $rid); $result = $result && assign_capability('mod/adobeconnect:meetingparticipant', CAP_ALLOW, $mrole->id, $sysctx->id); } else { $result = false; } } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $coursecreatorrid)) { $result = $result && allow_assign($coursecreatorrid, $mrole->id); } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $editingteacherrid)) { $result = $result && allow_assign($editingteacherrid, $mrole->id); } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $teacherrid)) { $result = $result && allow_assign($teacherrid, $mrole->id); } /// Fully setup the Adobe Connect Host role. if ($result && !($mrole = get_record('role', 'shortname', 'adobeconnecthost'))) { if ($rid = create_role(get_string('adobeconnecthost', 'adobeconnect'), 'adobeconnecthost', get_string('adobeconnecthostdescription', 'adobeconnect'))) { $mrole = get_record('role', 'id', $rid); $result = $result && assign_capability('mod/adobeconnect:meetinghost', CAP_ALLOW, $mrole->id, $sysctx->id); } else { $result = false; } } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $coursecreatorrid)) { $result = $result && allow_assign($coursecreatorrid, $mrole->id); } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $editingteacherrid)) { $result = $result && allow_assign($editingteacherrid, $mrole->id); } if (!get_field('role_allow_assign', 'id', 'allowassign', $mrole->id, 'roleid', $teacherrid)) { $result = $result && allow_assign($teacherrid, $mrole->id); } return $result; }
/** * function that creates a role * @param name - role name * @param shortname - role short name * @param description - role description * @param legacy - optional legacy capability * @return id or false */ function create_role($name, $shortname, $description, $legacy = '') { global $CFG; // check for duplicate role name if ($role = get_record('role', 'name', $name)) { error('there is already a role with this name!'); } if ($role = get_record('role', 'shortname', $shortname)) { error('there is already a role with this shortname!'); } // Get the system context. if (!($context = get_context_instance(CONTEXT_SYSTEM))) { return false; } // Insert the role record. $role = new object(); $role->name = $name; $role->shortname = $shortname; $role->description = $description; //find free sortorder number if (!($role->sortorder = get_field_sql('SELECT MAX(sortorder) + 1 FROM ' . $CFG->prefix . 'role'))) { $role->sortorder = 1; } $id = insert_record('role', $role); if (!$id) { return false; } if ($legacy) { assign_capability($legacy, CAP_ALLOW, $id, $context->id); } // By default, users with role:manage at site level should be able to assign // users to this new role, and override this new role's capabilities. if ($adminroles = get_admin_roles()) { foreach ($adminroles as $arole) { allow_assign($arole->id, $id); allow_override($arole->id, $id); } } return $id; }
function xmldb_core_install() { global $CFG, $DB, $SITE; // switch to new default theme set_config('theme', 'standard'); $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes $systemcontext = context_system::instance(); // add coursetype and icon fields to course table $table = new xmldb_table('course'); $field = new xmldb_field('coursetype'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '4', null, null, null, null, null); $dbman->add_field($table, $field); } $field = new xmldb_field('icon'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, null, null); $dbman->add_field($table, $field); } // rename the moodle 'manager' fullname to "Site Manager" to make it // distinct from the "Staff Manager" if ($managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager', 'name' => get_string('manager', 'role')))) { $todb = new stdClass(); $todb->id = $managerroleid; $todb->name = get_string('sitemanager', 'local_core'); $DB->update_record('role', $todb); } // Create roles. $manager = $DB->get_record('role', array('shortname' => 'manager')); $managerrole = $manager->id; $staffmanagerrole = create_role('', 'staffmanager', '', 'staffmanager'); $assessorrole = create_role('', 'assessor', '', 'assessor'); $regionalmanagerrole = create_role('', 'regionalmanager', ''); $regionaltrainerrole = create_role('', 'regionaltrainer', ''); $defaultallowassigns = array( array($managerrole, $staffmanagerrole), array($managerrole, $assessorrole), array($managerrole, $regionalmanagerrole), array($managerrole, $regionaltrainerrole) ); foreach ($defaultallowassigns as $allow) { list($fromroleid, $toroleid) = $allow; allow_assign($fromroleid, $toroleid); } $defaultallowoverrides = array( array($managerrole, $staffmanagerrole), array($managerrole, $assessorrole), array($managerrole, $regionalmanagerrole), array($managerrole, $regionaltrainerrole) ); foreach ($defaultallowoverrides as $allow) { list($fromroleid, $toroleid) = $allow; allow_override($fromroleid, $toroleid); // There is a rant about this in MDL-15841. } $defaultallowswitch = array( array($managerrole, $staffmanagerrole), ); foreach ($defaultallowswitch as $allow) { list($fromroleid, $toroleid) = $allow; allow_switch($fromroleid, $toroleid); } set_role_contextlevels($staffmanagerrole, get_default_contextlevels('staffmanager')); assign_capability('moodle/user:viewdetails', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true); assign_capability('moodle/user:viewuseractivitiesreport', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true); assign_capability('moodle/cohort:view', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true); assign_capability('moodle/comment:view', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true); assign_capability('moodle/comment:delete', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true); assign_capability('moodle/comment:post', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true); $systemcontext->mark_dirty(); set_role_contextlevels($assessorrole, get_default_contextlevels('teacher')); $role_to_modify = array( 'editingteacher' => 'editingtrainer', 'teacher' => 'trainer', 'student' => 'learner' ); $DB->update_record('role', array('id' => $assessorrole, 'archetype' => 'assessor')); assign_capability('moodle/user:editownprofile', CAP_ALLOW, $assessorrole, $systemcontext->id, true); assign_capability('moodle/user:editownprofile', CAP_ALLOW, $regionalmanagerrole, $systemcontext->id, true); assign_capability('moodle/user:editownprofile', CAP_ALLOW, $regionaltrainerrole, $systemcontext->id, true); foreach ($role_to_modify as $old => $new) { if ($old_role = $DB->get_record('role', array('shortname' => $old))) { $new_role = new stdClass(); $new_role->id = $old_role->id; $new_role->name = ''; $new_role->description = ''; $DB->update_record('role', $new_role); } } // Set up frontpage. set_config('frontpage', ''); set_config('frontpageloggedin', ''); require_once($CFG->dirroot . '/lib/completionlib.php'); if(!completion_info::is_enabled_for_site()){ set_config('coreinstallation', 1); set_config('enablecompletion', 1); set_config('enablecompletion', 1, 'moodlecourse'); set_config('completionstartonenrol', 1, 'moodlecourse'); } // Add completionstartonenrol column to course table. $table = new xmldb_table('course'); // Define field completionstartonenrol to be added to course. $field = new xmldb_field('completionstartonenrol', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0'); // Conditionally launch add field completionstartonenrol. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Add RPL column to course_completions table $table = new xmldb_table('course_completions'); // Define field rpl to be added to course_completions $field = new xmldb_field('rpl', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'reaggregate'); // Conditionally launch add field rpl if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field rplgrade to be added to course_completions $field = new xmldb_field('rplgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'rpl'); // Conditionally launch add field rpl if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Add RPL column to course_completion_crit_compl table $table = new xmldb_table('course_completion_crit_compl'); // Define field rpl to be added to course_completion_crit_compl $field = new xmldb_field('rpl', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'unenroled'); // Conditionally launch add field rpl if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define fields status and renewalstatus to be added to course_completions. $table = new xmldb_table('course_completions'); $field = new xmldb_field('status', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); // Conditionally launch add field status. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('renewalstatus', XMLDB_TYPE_INTEGER, '2', null, null, null, '0'); // Conditionally launch add field renewalstatus. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } rebuild_course_cache($SITE->id, true); // readd specific course completion changes for anyone // upgrading from moodle 2.2.2+ require_once($CFG->dirroot . '/local/core/db/utils.php'); local_readd_course_completion_changes(); // remove any references to "complete on unenrolment" critiera type // these could exist in an upgrade from moodle 2.2 but the criteria $DB->delete_records('course_completion_criteria', array('criteriatype' => 3)); //disable autoupdate notifications from Moodle set_config('disableupdatenotifications', '1'); set_config('disableupdateautodeploy', '1'); set_config('updateautodeploy', false); set_config('updateautocheck', false); set_config('updatenotifybuilds', false); // Disable editing execpaths by default for security. set_config('preventexecpath', '1'); // Then provide default values to prevent them appearing on the upgradesettings page. set_config('geoipfile', $CFG->dataroot . 'geoip/GeoLiteCity.dat'); set_config('location', '', 'enrol_flatfile'); set_config('filter_tex_pathlatex', '/usr/bin/latex'); set_config('filter_tex_pathdvips', '/usr/bin/dvips'); set_config('filter_tex_pathconvert', '/usr/bin/convert'); set_config('pathtodu', ''); set_config('pathtoclam', ''); set_config('aspellpath', ''); set_config('pathtodot', ''); set_config('quarantinedir', ''); set_config('backup_auto_destination', '', 'backup'); // Adding some upgrade code from lib/db/upgrade.php to // avoid conflicts every time we upgrade moodle. // This can be removed once we reach the verion of Moodle that // includes this functionality. E.g. 2.5 for badges, 2.6? for // course completion. // Add openbadges tables. // Define table 'badge' to be created $table = new xmldb_table('badge'); // Adding fields to table 'badge' $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name'); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'description'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timecreated'); $table->add_field('usercreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'timemodified'); $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'usercreated'); $table->add_field('issuername', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'usermodified'); $table->add_field('issuerurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'issuername'); $table->add_field('issuercontact', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'issuerurl'); $table->add_field('expiredate', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'issuercontact'); $table->add_field('expireperiod', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'expiredate'); $table->add_field('type', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'expireperiod'); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'type'); $table->add_field('message', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'courseid'); $table->add_field('messagesubject', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'message'); $table->add_field('attachment', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'messagesubject'); $table->add_field('notification', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'attachment'); $table->add_field('status', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'notification'); $table->add_field('nextcron', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'status'); // Adding keys to table 'badge' $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); $table->add_key('fk_usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); $table->add_key('fk_usercreated', XMLDB_KEY_FOREIGN, array('usercreated'), 'user', array('id')); // Adding indexes to table 'badge' $table->add_index('type', XMLDB_INDEX_NOTUNIQUE, array('type')); // Set the comment for the table 'badge'. $table->setComment('Defines badge'); // Conditionally launch create table for 'badge' if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table 'badge_criteria' to be created $table = new xmldb_table('badge_criteria'); // Adding fields to table 'badge_criteria' $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('criteriatype', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'badgeid'); $table->add_field('method', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'criteriatype'); // Adding keys to table 'badge_criteria' $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); // Adding indexes to table 'badge_criteria' $table->add_index('criteriatype', XMLDB_INDEX_NOTUNIQUE, array('criteriatype')); $table->add_index('badgecriteriatype', XMLDB_INDEX_UNIQUE, array('badgeid', 'criteriatype')); // Set the comment for the table 'badge_criteria'. $table->setComment('Defines criteria for issuing badges'); // Conditionally launch create table for 'badge_criteria' if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table 'badge_criteria_param' to be created $table = new xmldb_table('badge_criteria_param'); // Adding fields to table 'badge_criteria_param' $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('critid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'critid'); $table->add_field('value', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'name'); // Adding keys to table 'badge_criteria_param' $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_critid', XMLDB_KEY_FOREIGN, array('critid'), 'badge_criteria', array('id')); // Set the comment for the table 'badge_criteria_param'. $table->setComment('Defines parameters for badges criteria'); // Conditionally launch create table for 'badge_criteria_param' if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table 'badge_issued' to be created $table = new xmldb_table('badge_issued'); // Adding fields to table 'badge_issued' $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'badgeid'); $table->add_field('uniquehash', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'userid'); $table->add_field('dateissued', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'uniquehash'); $table->add_field('dateexpire', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'dateissued'); $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'dateexpire'); $table->add_field('issuernotified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'visible'); // Adding keys to table 'badge_issued' $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); // Adding indexes to table 'badge_issued' $table->add_index('badgeuser', XMLDB_INDEX_UNIQUE, array('badgeid', 'userid')); // Set the comment for the table 'badge_issued'. $table->setComment('Defines issued badges'); // Conditionally launch create table for 'badge_issued' if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table 'badge_criteria_met' to be created $table = new xmldb_table('badge_criteria_met'); // Adding fields to table 'badge_criteria_met' $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('issuedid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'id'); $table->add_field('critid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuedid'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'critid'); $table->add_field('datemet', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'userid'); // Adding keys to table 'badge_criteria_met' $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_critid', XMLDB_KEY_FOREIGN, array('critid'), 'badge_criteria', array('id')); $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $table->add_key('fk_issuedid', XMLDB_KEY_FOREIGN, array('issuedid'), 'badge_issued', array('id')); // Set the comment for the table 'badge_criteria_met'. $table->setComment('Defines criteria that were met for an issued badge'); // Conditionally launch create table for 'badge_criteria_met' if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table 'badge_manual_award' to be created $table = new xmldb_table('badge_manual_award'); // Adding fields to table 'badge_manual_award' $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('recipientid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'badgeid'); $table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'recipientid'); $table->add_field('issuerrole', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuerid'); $table->add_field('datemet', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuerrole'); // Adding keys to table 'badge_manual_award' $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); $table->add_key('fk_recipientid', XMLDB_KEY_FOREIGN, array('recipientid'), 'user', array('id')); $table->add_key('fk_issuerid', XMLDB_KEY_FOREIGN, array('issuerid'), 'user', array('id')); $table->add_key('fk_issuerrole', XMLDB_KEY_FOREIGN, array('issuerrole'), 'role', array('id')); // Set the comment for the table 'badge_manual_award'. $table->setComment('Track manual award criteria for badges'); // Conditionally launch create table for 'badge_manual_award' if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table 'badge_backpack' to be created $table = new xmldb_table('badge_backpack'); // Adding fields to table 'badge_backpack' $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('email', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'userid'); $table->add_field('backpackurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'email'); $table->add_field('backpackuid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackurl'); $table->add_field('backpackgid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackuid'); $table->add_field('autosync', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'backpackgid'); $table->add_field('password', XMLDB_TYPE_CHAR, '50', null, null, null, null, 'autosync'); // Adding keys to table 'badge_backpack' $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); // Set the comment for the table 'badge_backpack'. $table->setComment('Defines settings for connecting external backpack'); // Conditionally launch create table for 'badge_backpack' if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Create a new 'badge_external' table first. // Define table 'badge_external' to be created. $table = new xmldb_table('badge_external'); // Adding fields to table 'badge_external'. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('backpackid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('collectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackid'); // Adding keys to table 'badge_external'. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('fk_backpackid', XMLDB_KEY_FOREIGN, array('backpackid'), 'badge_backpack', array('id')); // Set the comment for the table 'badge_external'. $table->setComment('Setting for external badges display'); // Conditionally launch create table for 'badge_external'. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define field backpackgid to be dropped from 'badge_backpack'. $table = new xmldb_table('badge_backpack'); $field = new xmldb_field('backpackgid'); if ($dbman->field_exists($table, $field)) { // Perform user data migration. $usercollections = $DB->get_records('badge_backpack'); foreach ($usercollections as $usercollection) { $collection = new stdClass(); $collection->backpackid = $usercollection->id; $collection->collectionid = $usercollection->backpackgid; $DB->insert_record('badge_external', $collection); } // Launch drop field backpackgid. $dbman->drop_field($table, $field); } // Create missing badgeid foreign key on badge_manual_award. $table = new xmldb_table('badge_manual_award'); $key = new xmldb_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('id'), 'badge', array('id')); $dbman->drop_key($table, $key); $key->set_attributes(XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); $dbman->add_key($table, $key); // Drop unused badge image field. $table = new xmldb_table('badge'); $field = new xmldb_field('image', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'description'); // Conditionally launch drop field eventtype. if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field completionprogressonview to be added to course. $table = new xmldb_table('course'); $field = new xmldb_field('completionprogressonview', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 0, 'enablecompletion'); // Conditionally launch add field completionprogressonview. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('audiencevisible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 2); // Conditionally launch add field audiencevisible to course table. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field invalidatecache to be added to course_completions. $table = new xmldb_table('course_completions'); $field = new xmldb_field('invalidatecache', XMLDB_TYPE_INTEGER, '1', null, null, null, '0'); // Conditionally launch add field invalidatecache. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Backporting MDL-41914 to add new webservice core_user_add_user_device. $table = new xmldb_table('user_devices'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('appid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, 'userid'); $table->add_field('name', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'appid'); $table->add_field('model', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'name'); $table->add_field('platform', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'model'); $table->add_field('version', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'platform'); $table->add_field('pushid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'version'); $table->add_field('uuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'pushid'); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'uuid'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'timecreated'); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('pushid-userid', XMLDB_KEY_UNIQUE, array('pushid', 'userid')); $table->add_key('pushid-platform', XMLDB_KEY_UNIQUE, array('pushid', 'platform')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Add timecompleted for module completion. $table = new xmldb_table('course_modules_completion'); $field = new xmldb_field('timecompleted', XMLDB_TYPE_INTEGER, '10'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } return true; }
protected function set_allow($fromroleid, $targetroleid) { allow_assign($fromroleid, $targetroleid); }
require_once '../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_login(); $systemcontext = get_context_instance(CONTEXT_SYSTEM); require_capability('moodle/role:manage', $systemcontext); /// Get all roles $roles = get_all_roles(); role_fix_names($roles, $systemcontext, ROLENAME_ORIGINAL); /// Process form submission if (optional_param('submit', false, PARAM_BOOL) && data_submitted() && confirm_sesskey()) { /// Delete all records, then add back the ones that should be allowed. delete_records('role_allow_assign'); foreach ($roles as $fromroleid => $notused) { foreach ($roles as $targetroleid => $alsonotused) { if (optional_param('s_' . $fromroleid . '_' . $targetroleid, false, PARAM_BOOL)) { allow_assign($fromroleid, $targetroleid); } } } /// Updated allowassigns sitewide, so force a premissions refresh, and redirect. mark_context_dirty($systemcontext->path); add_to_log(SITEID, 'role', 'edit allow assign', 'admin/roles/allowassign.php', '', '', $USER->id); redirect($CFG->wwwroot . '/' . $CFG->admin . '/roles/allowassign.php'); } /// Load the current settings $allowed = array(); foreach ($roles as $role) { // Make an array $role->id => false. This is probalby too clever for its own good.1 $allowed[$role->id] = array_combine(array_keys($roles), array_fill(0, count($roles), false)); } $raas = get_recordset('role_allow_assign');
/** * Main post-install tasks to be executed after the BD schema is available * * This function is automatically executed after Moodle core DB has been * created at initial install. It's in charge of perform the initial tasks * not covered by the {@link install.xml} file, like create initial users, * roles, templates, moving stuff from other plugins... * * Note that the function is only invoked once, at install time, so if new tasks * are needed in the future, they will need to be added both here (for new sites) * and in the corresponding {@link upgrade.php} file (for existing sites). * * All plugins within Moodle (modules, blocks, reports...) support the existence of * their own install.php file, using the "Frankenstyle" component name as * defined at {@link http://docs.moodle.org/dev/Frankenstyle}, for example: * - {@link xmldb_page_install()}. (modules don't require the plugintype ("mod_") to be used. * - {@link xmldb_enrol_meta_install()}. * - {@link xmldb_workshopform_accumulative_install()}. * - .... * * Finally, note that it's also supported to have one uninstall.php file that is * executed also once, each time one plugin is uninstalled (before the DB schema is * deleted). Those uninstall files will contain one function, using the "Frankenstyle" * naming conventions, like {@link xmldb_enrol_meta_uninstall()} or {@link xmldb_workshop_uninstall()}. */ function xmldb_main_install() { global $CFG, $DB, $SITE, $OUTPUT; // Make sure system context exists $syscontext = context_system::instance(0, MUST_EXIST, false); if ($syscontext->id != SYSCONTEXTID) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected new system context id!'); } // Create site course if ($DB->record_exists('course', array())) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Can not create frontpage course, courses already exist.'); } $newsite = new stdClass(); $newsite->fullname = ''; $newsite->shortname = ''; $newsite->summary = NULL; $newsite->newsitems = 3; $newsite->numsections = 1; $newsite->category = 0; $newsite->format = 'site'; // Only for this course $newsite->timecreated = time(); $newsite->timemodified = $newsite->timecreated; if (defined('SITEID')) { $newsite->id = SITEID; $DB->import_record('course', $newsite); $DB->get_manager()->reset_sequence('course'); } else { $newsite->id = $DB->insert_record('course', $newsite); define('SITEID', $newsite->id); } $SITE = get_site(); if ($newsite->id != $SITE->id) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected new site course id!'); } // Make sure site course context exists context_course::instance($SITE->id); // Update the global frontpage cache $SITE = $DB->get_record('course', array('id' => $newsite->id), '*', MUST_EXIST); // Create default course category if ($DB->record_exists('course_categories', array())) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Can not create default course category, categories already exist.'); } $cat = new stdClass(); $cat->name = get_string('miscellaneous'); $cat->depth = 1; $cat->sortorder = MAX_COURSES_IN_CATEGORY; $cat->timemodified = time(); $catid = $DB->insert_record('course_categories', $cat); $DB->set_field('course_categories', 'path', '/' . $catid, array('id' => $catid)); // Make sure category context exists context_coursecat::instance($catid); $defaults = array('rolesactive' => '0', 'auth' => 'email', 'auth_pop3mailbox' => 'INBOX', 'enrol_plugins_enabled' => 'manual,guest,self,cohort', 'theme' => theme_config::DEFAULT_THEME, 'filter_multilang_converted' => 1, 'siteidentifier' => random_string(32) . get_host_from_url($CFG->wwwroot), 'backup_version' => 2008111700, 'backup_release' => '2.0 dev', 'mnet_dispatcher_mode' => 'off', 'sessiontimeout' => 7200, 'stringfilters' => '', 'filterall' => 0, 'texteditors' => 'tinymce,textarea'); foreach ($defaults as $key => $value) { set_config($key, $value); } // Bootstrap mnet $mnethost = new stdClass(); $mnethost->wwwroot = $CFG->wwwroot; $mnethost->name = ''; $mnethost->name = ''; $mnethost->public_key = ''; if (empty($_SERVER['SERVER_ADDR'])) { // SERVER_ADDR is only returned by Apache-like webservers preg_match("@^(?:http[s]?://)?([A-Z0-9\\-\\.]+).*@i", $CFG->wwwroot, $matches); $my_hostname = $matches[1]; $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH! if ($my_ip == $my_hostname) { $mnethost->ip_address = 'UNKNOWN'; } else { $mnethost->ip_address = $my_ip; } } else { $mnethost->ip_address = $_SERVER['SERVER_ADDR']; } $mnetid = $DB->insert_record('mnet_host', $mnethost); set_config('mnet_localhost_id', $mnetid); // Initial insert of mnet applications info $mnet_app = new stdClass(); $mnet_app->name = 'moodle'; $mnet_app->display_name = 'Moodle'; $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php'; $mnet_app->sso_land_url = '/auth/mnet/land.php'; $mnet_app->sso_jump_url = '/auth/mnet/jump.php'; $moodleapplicationid = $DB->insert_record('mnet_application', $mnet_app); $mnet_app = new stdClass(); $mnet_app->name = 'mahara'; $mnet_app->display_name = 'Mahara'; $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php'; $mnet_app->sso_land_url = '/auth/xmlrpc/land.php'; $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php'; $DB->insert_record('mnet_application', $mnet_app); // Set up the probably-to-be-removed-soon 'All hosts' record $mnetallhosts = new stdClass(); $mnetallhosts->wwwroot = ''; $mnetallhosts->ip_address = ''; $mnetallhosts->public_key = ''; $mnetallhosts->public_key_expires = 0; $mnetallhosts->last_connect_time = 0; $mnetallhosts->last_log_id = 0; $mnetallhosts->deleted = 0; $mnetallhosts->name = 'All Hosts'; $mnetallhosts->applicationid = $moodleapplicationid; $mnetallhosts->id = $DB->insert_record('mnet_host', $mnetallhosts, true); set_config('mnet_all_hosts_id', $mnetallhosts->id); // Create guest record - do not assign any role, guest user gets the default guest role automatically on the fly if ($DB->record_exists('user', array())) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Can not create default users, users already exist.'); } $guest = new stdClass(); $guest->auth = 'manual'; $guest->username = '******'; $guest->password = hash_internal_user_password('guest'); $guest->firstname = get_string('guestuser'); $guest->lastname = ' '; $guest->email = 'root@localhost'; $guest->description = get_string('guestuserinfo'); $guest->mnethostid = $CFG->mnet_localhost_id; $guest->confirmed = 1; $guest->lang = $CFG->lang; $guest->timemodified = time(); $guest->id = $DB->insert_record('user', $guest); if ($guest->id != 1) { echo $OUTPUT->notification('Unexpected id generated for the Guest account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem'); } // Store guest id set_config('siteguest', $guest->id); // Make sure user context exists context_user::instance($guest->id); // Now create admin user $admin = new stdClass(); $admin->auth = 'manual'; $admin->firstname = get_string('admin'); $admin->lastname = get_string('user'); $admin->username = '******'; $admin->password = '******'; $admin->email = ''; $admin->confirmed = 1; $admin->mnethostid = $CFG->mnet_localhost_id; $admin->lang = $CFG->lang; $admin->maildisplay = 1; $admin->timemodified = time(); $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr(); // installation hijacking prevention $admin->id = $DB->insert_record('user', $admin); if ($admin->id != 2) { echo $OUTPUT->notification('Unexpected id generated for the Admin account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem'); } if ($admin->id != $guest->id + 1) { echo $OUTPUT->notification('Nonconsecutive id generated for the Admin account. Your database configuration or clustering setup may not be fully supported.', 'notifyproblem'); } // Store list of admins set_config('siteadmins', $admin->id); // Make sure user context exists context_user::instance($admin->id); // Install the roles system. $managerrole = create_role(get_string('manager', 'role'), 'manager', get_string('managerdescription', 'role'), 'manager'); $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'coursecreator'); $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'editingteacher'); $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'teacher'); $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'student'); $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'guest'); $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'user'); $frontpagerole = create_role(get_string('frontpageuser', 'role'), 'frontpage', get_string('frontpageuserdescription', 'role'), 'frontpage'); // Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles update_capabilities('moodle'); // Default allow assign $defaultallowassigns = array(array($managerrole, $managerrole), array($managerrole, $coursecreatorrole), array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole)); foreach ($defaultallowassigns as $allow) { list($fromroleid, $toroleid) = $allow; allow_assign($fromroleid, $toroleid); } // Default allow override $defaultallowoverrides = array(array($managerrole, $managerrole), array($managerrole, $coursecreatorrole), array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($managerrole, $guestrole), array($managerrole, $userrole), array($managerrole, $frontpagerole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole), array($editteacherrole, $guestrole)); foreach ($defaultallowoverrides as $allow) { list($fromroleid, $toroleid) = $allow; allow_override($fromroleid, $toroleid); // There is a rant about this in MDL-15841. } // Default allow switch. $defaultallowswitch = array(array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($managerrole, $guestrole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole), array($editteacherrole, $guestrole), array($noneditteacherrole, $studentrole), array($noneditteacherrole, $guestrole)); foreach ($defaultallowswitch as $allow) { list($fromroleid, $toroleid) = $allow; allow_switch($fromroleid, $toroleid); } // Set up the context levels where you can assign each role. set_role_contextlevels($managerrole, get_default_contextlevels('manager')); set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator')); set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher')); set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher')); set_role_contextlevels($studentrole, get_default_contextlevels('student')); set_role_contextlevels($guestrole, get_default_contextlevels('guest')); set_role_contextlevels($userrole, get_default_contextlevels('user')); // Init theme and JS revisions set_config('themerev', time()); set_config('jsrev', time()); // Install licenses require_once $CFG->libdir . '/licenselib.php'; license_manager::install_licenses(); // Init profile pages defaults if ($DB->record_exists('my_pages', array())) { throw new moodle_exception('generalexceptionmessage', 'error', '', 'Can not create default profile pages, records already exist.'); } $mypage = new stdClass(); $mypage->userid = NULL; $mypage->name = '__default'; $mypage->private = 0; $mypage->sortorder = 0; $DB->insert_record('my_pages', $mypage); $mypage->private = 1; $DB->insert_record('my_pages', $mypage); }
/** * Database upgrade code. * * @version $Id: upgrade.php,v 1.6 2009-06-05 20:12:38 jfilip Exp $ * @author Justin Filip <*****@*****.**> * @author Remote Learner - http://www.remote-learner.net/ */ function xmldb_elluminate_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; if ($oldversion < 2006062102) { /// This should not be necessary but it's included just in case. $result = install_from_xmldb_file($CFG->dirroot . '/mod/elluminate/db/install.xml'); } if ($result && $oldversion < 2009090801) { $meetings = get_records('elluminate'); $table = new XMLDBTable('elluminate'); if (table_exists($table)) { $status = drop_table($table, true, false); } $table = new XMLDBTable('elluminate_recordings'); if (table_exists($table)) { $status = drop_table($table, true, false); } $table = new XMLDBTable('elluminate_session'); if (table_exists($table)) { $status = drop_table($table, true, false); } $table = new XMLDBTable('elluminate_users'); if (table_exists($table)) { $status = drop_table($table, true, false); } $table = new XMLDBTable('elluminate_preloads'); if (table_exists($table)) { $status = drop_table($table, true, false); } install_from_xmldb_file($CFG->dirroot . '/mod/elluminate/db/upgrade.xml'); /// Modify all of the existing meetings, if any. if ($result && !empty($meetings)) { $timenow = time(); foreach ($meetings as $meeting) { /// Update the meeting by storing values from the ELM server in the local DB. if (!($elmmeeting = elluminate_get_meeting_full_response($meeting->meetingid))) { continue; } //$mparams = elluminate_get_meeting_parameters($meeting->meetingid); $sparams = elluminate_get_server_parameters($meeting->meetingid); $umeeting = new stdClass(); //$umeeting->id = $meeting->id; $umeeting->meetingid = $meeting->meetingid; $umeeting->meetinginit = 2; $umeeting->course = $meeting->course; $umeeting->creator = $elmmeeting->creatorId; $umeeting->groupmode = '0'; $umeeting->groupid = '0'; $umeeting->sessionname = addslashes($meeting->name); $umeeting->timestart = substr($elmmeeting->startTime, 0, -3); $umeeting->timeend = substr($elmmeeting->endTime, 0, -3); $umeeting->nonchairlist = $elmmeeting->nonChairList; $umeeting->chairlist = $elmmeeting->chairList; $umeeting->recordingmode = $elmmeeting->recordingModeType; $umeeting->name = $meeting->name; $umeeting->description = addslashes($meeting->description); $umeeting->boundarytime = $elmmeeting->boundaryTime; $umeeting->boundarytimedisplay = 1; $umeeting->seats = $meeting->seats; $umeeting->private = $meeting->private; $umeeting->grade = $meeting->grade; $umeeting->timemodified = $meeting->timemodified; insert_record('elluminate', $umeeting); $newmeeting = get_record('elluminate', 'meetingid', $meeting->meetingid); $attendancerecords = get_records('elluminate_attendance', 'elluminateid', $meeting->id); if (!empty($attendancerecords)) { foreach ($attendancerecords as $attendee) { $attendee->ellumianteid = $newmeeting->id; update_record('elluminate_attendance', $attendee); } } $recordings = elluminate_list_recordings($meeting->meetingid); if ($result && !empty($recordings)) { $timenow = time(); foreach ($recordings as $recording) { $urecording = new stdClass(); $urecording->meetingid = $recording->meetingid; $urecording->recordingid = $recording->recordingid; $urecording->description = $recording->roomname; $urecording->visible = '1'; $urecording->groupvisible = '0'; $urecording->created = $recording->created; insert_record('elluminate_recordings', $urecording); } } } } $timenow = time(); $sysctx = get_context_instance(CONTEXT_SYSTEM); $adminrid = get_field('role', 'id', 'shortname', 'admin'); $coursecreatorrid = get_field('role', 'id', 'shortname', 'coursecreator'); $editingteacherrid = get_field('role', 'id', 'shortname', 'editingteacher'); $teacherrid = get_field('role', 'id', 'shortname', 'teacher'); /// Fully setup the Elluminate Moderator role. if ($result && !($mrole = get_record('role', 'shortname', 'elluminatemoderator'))) { if ($rid = create_role(get_string('elluminatemoderator', 'elluminatelive'), 'elluminatemoderator', get_string('elluminatemoderatordescription', 'elluminatelive'))) { $mrole = get_record('role', 'id', $rid); $result = $result && assign_capability('mod/elluminatelive:moderatemeeting', CAP_ALLOW, $mrole->id, $sysctx->id); } else { $result = false; } } if (!count_records('role_allow_assign', 'allowassign', $mrole->id)) { $result = $result && allow_assign($adminrid, $mrole->id); $result = $result && allow_assign($coursecreatorrid, $mrole->id); $result = $result && allow_assign($editingteacherrid, $mrole->id); $result = $result && allow_assign($teacherrid, $mrole->id); } /// Fully setup the Elluminate Participant role. if ($result && !($prole = get_record('role', 'shortname', 'elluminateparticipant'))) { if ($rid = create_role(get_string('elluminateparticipant', 'elluminatelive'), 'elluminateparticipant', get_string('elluminateparticipantdescription', 'elluminatelive'))) { $prole = get_record('role', 'id', $rid); $result = $result && assign_capability('mod/elluminatelive:joinmeeting', CAP_ALLOW, $prole->id, $sysctx->id); } else { $result = false; } } if (!count_records('role_allow_assign', 'allowassign', $prole->id)) { $result = $result && allow_assign($adminrid, $prole->id); $result = $result && allow_assign($coursecreatorrid, $prole->id); $result = $result && allow_assign($editingteacherrid, $prole->id); $result = $result && allow_assign($teacherrid, $prole->id); } } if ($result && $oldversion == 2010021600) { $table = new XMLDBTable('elluminate'); $field = new XMLDBField('sessiontype'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, false, false, '0', 'creator'); $result = $result && add_field($table, $field); $field = new XMLDBField('groupingid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, false, false, '0', 'sessiontype'); $result = $result && add_field($table, $field); $meetings = get_records('elluminate'); foreach ($meetings as $meeting) { $meeting->groupingid = 0; if ($meeting->private == true) { $meeting->sessiontype = 1; } if ($meeting->groupmode > 0) { $meeting->sessiontype = 2; } update_record('elluminate', $meeting); } $field = new XMLDBField('private'); drop_field($table, $field); $recordings_table = new XMLDBTable('elluminate_recordings'); $size_field = new XMLDBField('recordingsize'); $size_field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NULL, false, false, false, '0', 'description'); $result = $result && add_field($recordings_table, $size_field); $recordings = get_records('elluminate_recordings'); foreach ($recordings as $recording) { $full_recordings = elluminate_list_recordings($recording->meetingid); foreach ($full_recordings as $full_recording) { if ($full_recording->recordingid == $recording->recordingid) { $recording->recordingsize = $full_recording->size; update_record('elluminate_recordings', $recording); } } } } return $result; }