function xmldb_customlabel_upgrade($oldversion = 0) { global $CFG, $THEME, $DB; $result = true; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($result && $oldversion < 2012062401) { // Define field fallbacktype to be added to customlabel. $table = new xmldb_table('customlabel'); $field = new xmldb_field('fallbacktype'); $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, 'labelclass'); // Launch add field parent. $result = $result || $dbman->add_field($table, $field); // customlabel savepoint reached. upgrade_mod_savepoint($result, 2012062401, 'customlabel'); } if ($result && $oldversion < 2013041802) { // Regenerates all contents to match template changes. $sql = "\n SELECT DISTINCT\n c.id,\n c.shortname,\n c.fullname,\n c.idnumber,\n c.summary,\n c.category,\n c.summaryformat\n FROM\n {course} c,\n {course_modules} cm,\n {modules} m\n WHERE\n c.id = cm.course AND\n cm.module = m.id AND\n m.name = 'customlabel'\n "; $courses = $DB->get_records_sql($sql); if ($courses) { echo '<pre>'; foreach ($courses as $c) { customlabel_course_preprocess_filepickers($c); customlabel_course_regenerate($c, 'all'); } echo '</pre>'; } upgrade_mod_savepoint($result, 2013041802, 'customlabel'); } return $result; }
function xmldb_hotquestion_upgrade($oldversion = 0) { global $CFG, $DB; $result = true; //===== 1.9.0 upgrade line ======// if ($result && $oldversion < 2007040100) { /// Define field course to be added to hotquestion $table = new XMLDBTable('hotquestion'); $field = new XMLDBField('course'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); /// Launch add field course $result = $result && $table->add_field($field); /// Define field intro to be added to hotquestion $field = new xmldb_field('intro'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'name'); /// Launch add field intro $result = $result && $table->add_field($field); /// Define field introformat to be added to hotquestion $field = new xmldb_field('introformat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'intro'); /// Launch add field introformat $result = $result && $table->add_field($field); } if ($result && $oldversion < 2007040101) { /// Define field timecreated to be added to hotquestion $table = new xmldb_table('hotquestion'); $field = new xmldb_field('timecreated'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'introformat'); /// Launch add field timecreated $result = $result && $table->add_field($field); $field = new xmldb_field('timemodified'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timecreated'); /// Launch add field timemodified $result = $result && $table->add_field($table, $field); /// Define index course (not unique) to be added to hotquestion $result = $result && $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); } if ($result && $oldversion < 2007040200) { /// Add some actions to get them properly displayed in the logs $rec = new stdClass(); $rec->module = 'hotquestion'; $rec->action = 'add'; $rec->mtable = 'hotquestion'; $rec->filed = 'name'; /// Insert the add action in log_display $result = $DB->insert_record('log_display', $rec); /// Now the update action $rec->action = 'update'; $result = $DB->insert_record('log_display', $rec); /// Now the view action $rec->action = 'view'; $result = $DB->insert_record('log_display', $rec); } //===== 2.0 upgrade start here ======// return $result; }
function xmldb_groupselect_upgrade($oldversion = 0) { global $CFG, $THEME, $DB; $result = true; $dbman = $DB->get_manager(); if ($result && $oldversion < 2009020600) { /// Define field signuptype to be added to groupselect $table = new xmldb_table('groupselect'); $field = new xmldb_field('signuptype'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, '0', 'intro'); $dbman->add_field($table, $field); /// Define field timecreated to be added to groupselect $table = new xmldb_table('groupselect'); $field = new xmldb_field('timecreated'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timedue'); $dbman->add_field($table, $field); } if ($result && $oldversion < 2009030500) { /// Define field targetgrouping to be added to groupselect $table = new xmldb_table('groupselect'); $field = new xmldb_field('targetgrouping'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); $dbman->add_field($table, $field); } if ($result && $oldversion < 2009061200) { $table = new xmldb_table('groupselect'); $field = new xmldb_field('individual_limits'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $dbman->add_field($table, $field); $table = new xmldb_table('groupselect_limits'); if ($result && !$dbman->table_exists($table)) { $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE); $table->add_field('groupselect', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->add_field('lim', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_index('groupselect', XMLDB_INDEX_NOTUNIQUE, array('groupselect')); $dbman->create_table($table); } } // Define field introformat to be added to groupselect if ($result && $oldversion < 2010101300) { $table = new xmldb_table('groupselect'); $field = new xmldb_field('introformat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $dbman->add_field($table, $field); } return $result; }
function xmldb_local_lae_install() { global $CFG, $DB; $dbman = $DB->get_manager(); // Migrate the old config setting, if present. if (!empty($CFG->forum_anonymous)) { set_config('forum_enableanonymousposts', $CFG->forum_anonymous); set_config('forum_anonymous', null); } // Extend forum tables. $table = new xmldb_table('forum'); $field = new xmldb_field('anonymous'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionposts'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('forum_posts'); $field = new xmldb_field('hiddenuserid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, 'mailnow'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Add anonymous user. if (empty($CFG->anonymous_userid)) { $anon_user = new stdClass(); $anon_user->username = '******'; // The password needs strings. $anon_user->password = hash_internal_user_password(str_shuffle($anon_user->username) . (string) mt_rand()); $anon_user->auth = 'nologin'; $anon_user->firstname = get_string('auser_firstname', 'local_lae'); $anon_user->lastname = get_string('auser_lastname', 'local_lae'); $anon_user->mnethostid = $CFG->mnet_localhost_id; $anon_user->email = get_string('auser_email', 'local_lae'); if ($result = $DB->insert_record('user', $anon_user)) { set_config('anonymous_userid', $result); context_user::instance($result); } else { print_error("Failed to create anonymous user"); return false; } } // Update course table to support display defaults $table = new xmldb_table('course'); $field = new xmldb_field('filedisplaydefault', XMLDB_TYPE_INTEGER, '2', null, null, null, null, null); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } return true; }
function xmldb_block_poll_upgrade($oldversion) { global $DB; $dbman = $DB->get_manager(); // Add a new column for anonymous polls. if ($oldversion < 2011041400) { $table = new xmldb_table('block_poll'); $field = new xmldb_field('anonymous'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'created'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } } return true; }
function xmldb_customlabel_upgrade($oldversion = 0) { global $CFG, $THEME, $DB; $result = true; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($result && $oldversion < 2012062401) { /// Define field fallbacktype to be added to customlabel $table = new xmldb_table('customlabel'); $field = new xmldb_field('fallbacktype'); $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, 'labelclass'); /// Launch add field parent $result = $result || $dbman->add_field($table, $field); /// customlabel savepoint reached upgrade_mod_savepoint($result, 2012062401, 'customlabel'); } return $result; }
function xmldb_conceptmap_upgrade($oldversion = 0) { if ($oldversion < 20151231) { // Add new fields to certificate table. $table = new xmldb_table('concept-map'); $field = new xmldb_field('showcode'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'savecert'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Add new fields to certificate_issues table. $table = new xmldb_table('certificate_issues'); $field = new xmldb_field('code'); $field->set_attributes(XMLDB_TYPE_CHAR, '50', null, null, null, null, 'certificateid'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Certificate savepoint reached. upgrade_mod_savepoint(true, 2012091800, 'certificate'); } }
/** * Upgrades for engagement * * @package mod_engagement * @copyright 2012 NetSpot Pty Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_engagement_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); if ($oldversion < 2012061900) { if (!$dbman->table_exists('engagement_cache')) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/mod/engagement/db/install.xml', 'engagement_cache'); } upgrade_mod_savepoint(true, 2012061900, 'engagement'); } if ($oldversion < 2012080700) { $table = new xmldb_table('engagement_cache'); $field = new xmldb_field('rawdata'); $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field, 'settings'); } upgrade_mod_savepoint(true, 2012080700, 'engagement'); } return true; }
function xmldb_groupreg_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes if ($oldversion < 2011100201) { $table = new xmldb_table('groupreg'); $field = new xmldb_field('groupmembers'); $field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '4', 'assigned'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } } if ($oldversion < 2011112601) { // Adding DB field: boolean (int-1) "finalized", telling whether the students have already been put in their groups. $table = new xmldb_table('groupreg'); $field = new xmldb_field('finalized'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembers'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } } return true; }
/** * Mindmap plugin upgrade code * * @package mod * @subpackage mindmap * @author ekpenso.com * @copyright 2011 Tõnis Tartes <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_mindmap_upgrade($oldversion = 0) { global $CFG, $THEME, $DB; $dbman = $DB->get_manager(); /// loads ddl manager and xmldb classes $result = true; if ($oldversion < 2012032300) { upgrade_mod_savepoint(true, 2012032300, 'mindmap'); } if ($oldversion < 2012061300) { $table = new xmldb_table('mindmap'); $field = new xmldb_field('editable', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'userid'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2012061300, 'mindmap'); } if ($oldversion < 2012070400) { upgrade_mod_savepoint(true, 2012070400, 'mindmap'); } //Locking functionality if ($oldversion < 2013030100) { $table = new xmldb_table('mindmap'); $field = new xmldb_field('locking'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'timemodified'); $dbman->add_field($table, $field); $table = new xmldb_table('mindmap'); $field = new xmldb_field('locked'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'locking'); $dbman->add_field($table, $field); $table = new xmldb_table('mindmap'); $field = new xmldb_field('lockedbyuser'); $field->set_attributes(XMLDB_TYPE_INTEGER, '12', null, XMLDB_NOTNULL, null, '0', 'locked'); $dbman->add_field($table, $field); upgrade_mod_savepoint(true, 2013030100, 'mindmap'); } return $result; }
function xmldb_block_quickmail_upgrade($oldversion) { global $DB; $result = true; $dbman = $DB->get_manager(); // 1.9 to 2.0 upgrade if ($oldversion < 2011021812) { // Changing type of field attachment on table block_quickmail_log to text $table = new xmldb_table('block_quickmail_log'); $field = new xmldb_field('attachment', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'message'); // Launch change of type for field attachment $dbman->change_field_type($table, $field); // Rename field timesent on table block_quickmail_log to time $table = new xmldb_table('block_quickmail_log'); $field = new xmldb_field('timesent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'format'); // Conditionally launch rename field timesent if ($dbman->field_exists($table, $field)) { $dbman->rename_field($table, $field, 'time'); } // Define table block_quickmail_signatures to be created $table = new xmldb_table('block_quickmail_signatures'); // Adding fields to table block_quickmail_signatures $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('title', XMLDB_TYPE_CHAR, '125', null, null, null, null); $table->add_field('signature', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); $table->add_field('default_flag', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); // Adding keys to table block_quickmail_signatures $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for block_quickmail_signatures if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table block_quickmail_drafts to be created $table = new xmldb_table('block_quickmail_drafts'); // Adding fields to table block_quickmail_drafts $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('mailto', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); $table->add_field('subject', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('message', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); $table->add_field('attachment', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('format', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); // Adding keys to table block_quickmail_drafts $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for block_quickmail_drafts if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Define table block_quickmail_config to be created $table = new xmldb_table('block_quickmail_config'); // Adding fields to table block_quickmail_config $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('coursesid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_CHAR, '125', null, null, null, null); // Adding keys to table block_quickmail_config $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for block_quickmail_config if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // quickmail savepoint reached upgrade_block_savepoint($result, 2011021812, 'quickmail'); } if ($oldversion < 2012021014) { $table = new xmldb_table('block_quickmail_alternate'); $field = new xmldb_field('id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null); $table->addField($field); $field = new xmldb_field('courseid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, 'id'); $table->addField($field); $field = new xmldb_field('address'); $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, false, null, 'courseid'); $table->addField($field); $field = new xmldb_field('valid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', 'address'); $table->addField($field); $key = new xmldb_key('PRIMARY'); $key->set_attributes(XMLDB_KEY_PRIMARY, array('id')); $table->addKey($key); if (!$dbman->table_exists($table)) { $dbman->create_table($table); } foreach (array('log', 'drafts') as $table) { // Define field alternateid to be added to block_quickmail_log $table = new xmldb_table('block_quickmail_' . $table); $field = new xmldb_field('alternateid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'userid'); // Conditionally launch add field alternateid if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } } // quickmail savepoint reached upgrade_block_savepoint($result, 2012021014, 'quickmail'); } if ($oldversion < 2012061112) { // Restructure database references to the new filearea locations foreach (array('log', 'drafts') as $type) { $params = array('component' => 'block_quickmail_' . $type, 'filearea' => 'attachment'); $attachments = $DB->get_records('files', $params); foreach ($attachments as $attachment) { $attachment->filearea = 'attachment_' . $type; $attachment->component = 'block_quickmail'; $result = $result && $DB->update_record('files', $attachment); } } upgrade_block_savepoint($result, 2012061112, 'quickmail'); } if ($oldversion < 2012061112) { migrate_quickmail_20(); } if ($oldversion < 2014042914) { // Define field status to be dropped from block_quickmail_log. $table = new xmldb_table('block_quickmail_log'); $field = new xmldb_field('status'); // Conditionally launch drop field status. if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field status to be added to block_quickmail_log. $table = new xmldb_table('block_quickmail_log'); $field = new xmldb_field('failuserids', XMLDB_TYPE_TEXT, null, null, null, null, null, 'time'); $field2 = new xmldb_field('additional_emails', XMLDB_TYPE_TEXT, null, null, null, null, null, 'failuserids'); // Conditionally launch add field status. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } if (!$dbman->field_exists($table, $field2)) { $dbman->add_field($table, $field2); } // Define field additional_emails to be added to block_quickmail_drafts. $table = new xmldb_table('block_quickmail_drafts'); $field = new xmldb_field('additional_emails', XMLDB_TYPE_TEXT, null, null, null, null, null, 'time'); // Conditionally launch add field additional_emails. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Quickmail savepoint reached. upgrade_block_savepoint(true, 2014042914, 'quickmail'); } return $result; }
function xmldb_scorm_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); $result = true; //===== 1.9.0 upgrade line ======// // Adding missing 'whatgrade' field to table scorm if ($result && $oldversion < 2008073000) { $table = new xmldb_table('scorm'); $field = new xmldb_field('whatgrade'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grademethod'); /// Launch add field whatgrade if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint($result, 2008073000, 'scorm'); } if ($result && $oldversion < 2008082500) { /// Define field scormtype to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('scormtype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, 'local', 'name'); /// Launch add field scormtype $dbman->add_field($table, $field); /// scorm savepoint reached upgrade_mod_savepoint($result, 2008082500, 'scorm'); } if ($result && $oldversion < 2008090300) { /// Define field sha1hash to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('sha1hash', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'updatefreq'); /// Launch add field sha1hash $dbman->add_field($table, $field); /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090300, 'scorm'); } if ($result && $oldversion < 2008090301) { /// Define field revision to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'md5hash'); /// Launch add field revision $dbman->add_field($table, $field); /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090301, 'scorm'); } if ($result && $oldversion < 2008090302) { $sql = "UPDATE {scorm}\n SET scormtype = 'external'\n WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?"; $DB->execute($sql, array('http://%imsmanifest.xml', 'https://%imsmanifest.xml', 'www.%imsmanifest.xml')); $sql = "UPDATE {scorm}\n SET scormtype = 'localsync'\n WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?\n OR reference LIKE ? OR reference LIKE ? OR reference LIKE ?"; $DB->execute($sql, array('http://%.zip', 'https://%.zip', 'www.%.zip', 'http://%.pif', 'https://%.pif', 'www.%.pif')); $sql = "UPDATE {scorm} SET scormtype = 'imsrepository' WHERE reference LIKE ?"; $DB->execute($sql, array('#%')); /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090302, 'scorm'); } if ($result && $oldversion < 2008090303) { //remove obsoleted config settings unset_config('scorm_advancedsettings'); unset_config('scorm_windowsettings'); /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090303, 'scorm'); } if ($result && $oldversion < 2008090304) { ///////////////////////////////////// /// new file storage upgrade code /// ///////////////////////////////////// function scorm_migrate_content_files($context, $base, $path) { global $CFG, $OUTPUT; $fullpathname = $base . $path; $fs = get_file_storage(); $filearea = 'scorm_content'; $items = new DirectoryIterator($fullpathname); foreach ($items as $item) { if ($item->isDot()) { unset($item); // release file handle continue; } if ($item->isLink()) { // do not follow symlinks - they were never supported in moddata, sorry unset($item); // release file handle continue; } if ($item->isFile()) { if (!$item->isReadable()) { echo $OUTPUT->notification(" File not readable, skipping: " . $fullpathname . $item->getFilename()); unset($item); // release file handle continue; } $filepath = clean_param($path, PARAM_PATH); $filename = clean_param($item->getFilename(), PARAM_FILE); $oldpathname = $fullpathname . $item->getFilename(); if ($filename === '') { continue; unset($item); // release file handle } if (!$fs->file_exists($context->id, $filearea, '0', $filepath, $filename)) { $file_record = array('contextid' => $context->id, 'filearea' => $filearea, 'itemid' => 0, 'filepath' => $filepath, 'filename' => $filename, 'timecreated' => $item->getCTime(), 'timemodified' => $item->getMTime()); unset($item); // release file handle if ($fs->create_file_from_pathname($file_record, $oldpathname)) { @unlink($oldpathname); } } else { unset($item); // release file handle } } else { //migrate recursively all subdirectories $oldpathname = $fullpathname . $item->getFilename() . '/'; $subpath = $path . $item->getFilename() . '/'; unset($item); // release file handle scorm_migrate_content_files($context, $base, $subpath); @rmdir($oldpathname); // deletes dir if empty } } unset($items); //release file handles } $fs = get_file_storage(); $sqlfrom = "FROM {scorm} s\n JOIN {modules} m ON m.name = 'scorm'\n JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = s.id)"; $count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}"); if ($rs = $DB->get_recordset_sql("SELECT s.id, s.scormtype, s.reference, s.course, cm.id AS cmid {$sqlfrom} ORDER BY s.course, s.id")) { $pbar = new progress_bar('migratescormfiles', 500, true); $i = 0; foreach ($rs as $scorm) { $i++; upgrade_set_timeout(180); // set up timeout, may also abort execution $pbar->update($i, $count, "Migrating scorm files - {$i}/{$count}."); $context = get_context_instance(CONTEXT_MODULE, $scorm->cmid); $coursecontext = get_context_instance(CONTEXT_COURSE, $scorm->course); // first copy local packages if found - do not delete in case they are shared ;-) if ($scorm->scormtype === 'local' and preg_match('/.*(\\.zip|\\.pif)$/i', $scorm->reference)) { $packagefile = '/' . clean_param($scorm->reference, PARAM_PATH); $pathnamehash = sha1($coursecontext->id . 'course_content0' . $packagefile); if ($file = $fs->get_file_by_hash($pathnamehash)) { $file_record = array('scontextid' => $context->id, 'filearea' => 'scorm_pacakge', 'itemid' => 0, 'filepath' => '/'); $packagefile = $fs->create_file_from_storedfile($file_record, $file); $scorm->reference = $packagefile->get_filename(); } else { $scorm->reference = ''; } $DB->update_record('scorm', $scorm); } // now migrate the extracted package $basepath = "{$CFG->dataroot}/{$scorm->course}/{$CFG->moddata}/scorm/{$scorm->id}"; if (!is_dir($basepath)) { //no files? continue; } scorm_migrate_content_files($context, $basepath, '/'); // remove dirs if empty @rmdir("{$CFG->dataroot}/{$scorm->course}/{$CFG->moddata}/scorm/{$scorm->id}/"); @rmdir("{$CFG->dataroot}/{$scorm->course}/{$CFG->moddata}/scorm/"); @rmdir("{$CFG->dataroot}/{$scorm->course}/{$CFG->moddata}/"); } $rs->close(); } /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090304, 'scorm'); } if ($result && $oldversion < 2008090305) { /// Define new fields forcecompleted, forcenewattempt, displayattemptstatus, and displaycoursestructure to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'maxattempt'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'forcecompleted'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'forcenewattempt'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'lastattemptlock'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'displayattemptstatus'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090305, 'scorm'); } // remove redundant config values if ($result && $oldversion < 2008090306) { /* * comment this out as it is handled by the update mark 2008090310 below * left for historical documentation as some early adopters may have done * this already. $redundant_config = array( 'scorm_allowapidebug', 'scorm_allowtypeexternal', 'scorm_allowtypeimsrepository', 'scorm_allowtypelocalsync', 'scorm_apidebugmask', 'scorm_frameheight', 'scorm_framewidth', 'scorm_maxattempts', 'scorm_updatetime'); foreach ($redundant_config as $rcfg) { if (isset($CFG->$rcfg)) { unset_config($rcfg); } } */ /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090306, 'scorm'); } // remove redundant config values if ($result && $oldversion < 2008090307) { /* * comment this out as it is handled by the update mark 2008090310 below * left for historical documentation as some early adopters may have done * this already. $redundant_config = array( 'scorm_allowapidebug', 'scorm_allowtypeexternal', 'scorm_allowtypeimsrepository', 'scorm_allowtypelocalsync', 'scorm_apidebugmask', 'scorm_frameheight', 'scorm_framewidth', 'scorm_maxattempts', 'scorm_updatetime', 'scorm_resizable', 'scorm_scrollbars', 'scorm_directories', 'scorm_location', 'scorm_menubar', 'scorm_toolbar', 'scorm_status', 'scorm_grademethod', 'scorm_maxgrade', 'scorm_whatgrade', 'scorm_popup', 'scorm_skipview', 'scorm_hidebrowse', 'scorm_hidetoc', 'scorm_hidenav', 'scorm_auto', 'scorm_updatefreq' ); foreach ($redundant_config as $rcfg) { if (isset($CFG->$rcfg)) { unset_config($rcfg); } } */ /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090307, 'scorm'); } if ($result && $oldversion < 2008090308) { $table = new xmldb_table('scorm'); $field = new xmldb_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'height'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeopen'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090308, 'scorm'); } if ($result && $oldversion < 2008090310) { // take above blocks that delete config and move the values in to config_plugins $redundant_config = array('scorm_allowapidebug', 'scorm_allowtypeexternal', 'scorm_allowtypeimsrepository', 'scorm_allowtypelocalsync', 'scorm_apidebugmask', 'scorm_frameheight', 'scorm_framewidth', 'scorm_maxattempts', 'scorm_updatetime', 'scorm_resizable', 'scorm_scrollbars', 'scorm_directories', 'scorm_location', 'scorm_menubar', 'scorm_toolbar', 'scorm_status', 'scorm_grademethod', 'scorm_maxgrade', 'scorm_whatgrade', 'scorm_popup', 'scorm_skipview', 'scorm_hidebrowse', 'scorm_hidetoc', 'scorm_hidenav', 'scorm_auto', 'scorm_updatefreq', 'scorm_displayattemptstatus', 'scorm_displaycoursestructure', 'scorm_forcecompleted', 'scorm_forcenewattempt', 'scorm_lastattemptlock'); foreach ($redundant_config as $rcfg) { if (isset($CFG->{$rcfg})) { $shortname = substr($rcfg, 6); $result = $result && set_config($shortname, $CFG->{$rcfg}, 'scorm'); $result = $result && unset_config($rcfg); } } /// scorm savepoint reached upgrade_mod_savepoint($result, 2008090310, 'scorm'); } if ($result && $oldversion < 2009042000) { /// Rename field summary on table scorm to intro $table = new xmldb_table('scorm'); $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'reference'); /// Launch rename field summary $dbman->rename_field($table, $field, 'intro'); /// scorm savepoint reached upgrade_mod_savepoint($result, 2009042000, 'scorm'); } if ($result && $oldversion < 2009042001) { /// Define field introformat to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Launch add field introformat $dbman->add_field($table, $field); /// scorm savepoint reached upgrade_mod_savepoint($result, 2009042001, 'scorm'); } return $result; }
function xmldb_block_email_list_upgrade($oldversion = 0) { global $CFG, $THEME, $DB; $dbman = $DB->get_manager(); /// loads ddl manager and xmldb classes $result = true; // If is set upgrade_blocks_savepoint function $existfunction = false; if (!function_exists('upgrade_blocks_savepoint')) { $existfunction = true; } /// And upgrade begins here. For each one, you'll need one /// block of code similar to the next one. Please, delete /// this comment lines once this file start handling proper /// upgrade code. if ($result && $oldversion < 2007062205) { $fields = array('mod/email:viewmail', 'mod/email:addmail', 'mod/email:reply', 'mod/email:replyall', 'mod/email:forward', 'mod/email:addsubfolder', 'mod/email:updatesubfolder', 'mod/email:removesubfolder'); /// Remove no more used fields $table = new xmldb_table('capabilities'); foreach ($fields as $name) { $field = new xmldb_field($name); $result = $result && $dbman->drop_field($table, $field); } // Active cron block of email_list if ($result) { if ($email_list = $DB->get_record('block', array('name' => 'email_list'))) { $email_list->cron = 1; update_record('block', $email_list); } } if ($existfunction) { /// Block savepoint reached upgrade_blocks_savepoint($result, 2007062205, 'email_list'); } } // force $result = true; if ($result && $oldversion < 2007072003) { // Add marriedfolder2courses flag on email_preferences $table = new xmldb_table('email_preference'); $field = new xmldb_field('marriedfolders2courses'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $result = $result && $dbman->add_field($table, $field); // Add course ID on email_folder $table = new xmldb_table('email_folder'); $field = new xmldb_field('course'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $result = $result && $dbman->add_field($table, $field); // Add index $key = new xmldb_key('course'); $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'course', array('id')); $result = $result && $dbman->add_key($table, $key); if ($existfunction) { /// Block savepoint reached upgrade_blocks_savepoint($result, 2007072003, 'email_list'); } } if ($result && $oldversion < 2008061400) { // Add reply and forwarded info field on email_mail. $table = new xmldb_table('email_send'); $field = new xmldb_field('answered'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL); $result = $result && $dbman->add_field($table, $field); if ($existfunction) { /// Block savepoint reached upgrade_blocks_savepoint($result, 2008061400, 'email_list'); } } // Solve old problems if ($result && $oldversion < 2008061600) { $table = new xmldb_table('email_preference'); $field = new xmldb_field('marriedfolders2courses'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $result = $result && $dbman->add_field($table, $field); } $table = new xmldb_table('email_folder'); $field = new xmldb_field('course'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $result = $result && $dbman->add_field($table, $field); // Add index $key = new xmldb_key('course'); $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'course', array('id')); $result = $result && $dbman->add_key($table, $key); } if ($existfunction) { /// Block savepoint reached upgrade_blocks_savepoint($result, 2008061600, 'email_list'); } } // Add new index if ($result and $oldversion < 2008081602) { // Add combine key on foldermail $table = new xmldb_table('email_foldermail'); $index = new xmldb_index('folderid-mailid'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('folderid', 'mailid')); if (!$dbman->index_exists($table, $index)) { /// Launch add index $result = $result && $dbman->add_index($table, $index); } if ($existfunction) { /// Block savepoint reached upgrade_blocks_savepoint($result, 2008081602, 'email_list'); } } // Upgrading to Moodle 2.0 if ($result and $oldversion < 2009040200) { // Portable SQL staments to Oracle, MySQL and PostgreSQL NOT APPLYCABLE to MSSQL if ($CFG->dbname != 'mssql') { // Moodle 1.9 or prior if ($CFG->version < '2009011541') { // Filter $result = $DB->execute_sql("ALTER TABLE {email_filter} RENAME TO {block_email_list_filter}"); // Folder $result = $DB->execute_sql("ALTER TABLE {email_folder} RENAME TO {block_email_list_folder}") && $result; // Foldermail $result = $DB->execute_sql("ALTER TABLE {email_foldermail} RENAME TO {block_email_list_foldermail}") && $result; // Mail $result = $DB->execute_sql("ALTER TABLE {email_mail} RENAME TO {block_email_list_mail}") && $result; // Preference $result = $DB->execute_sql("ALTER TABLE {email_preference} RENAME TO {block_email_list_preference}") && $result; // Send $result = $DB->execute_sql("ALTER TABLE {email_send} RENAME TO {block_email_list_send}") && $result; // Subfolder $result = $DB->execute_sql("ALTER TABLE {email_subfolder} RENAME TO {block_email_list_subfolder}") && $result; } else { // Filter $DB->execute("ALTER TABLE {email_filter} RENAME TO {block_email_list_filter}"); // Folder $DB->execute("ALTER TABLE {email_folder} RENAME TO {block_email_list_folder}"); // Foldermail $DB->execute("ALTER TABLE {email_foldermail} RENAME TO {block_email_list_foldermail}"); // Mail $DB->execute("ALTER TABLE {email_mail} RENAME TO {block_email_list_mail}"); // Preference $DB->execute("ALTER TABLE {email_preference} RENAME TO {block_email_list_preference}"); // Send $DB->execute("ALTER TABLE {email_send} RENAME TO {block_email_list_send}"); // Subfolder $DB->execute("ALTER TABLE {email_subfolder} RENAME TO {block_email_list_subfolder}"); } } // Change module name to Standard eMail name. if ($logs = $DB->get_records('log_display', array('module' => 'email'))) { foreach ($logs as $log) { $DB->set_field('log_display', array('module' => 'block_email_list'), array('id' => $log->id)); } } // Only compatible with 1.9 or prior versions if ($existfunction) { /// Block savepoint reached upgrade_blocks_savepoint($result, 2009040200, 'block_email_list'); } } // Add field respondedid into block_email_list_mail table because, if one mail has replied, know this parent. if ($result and $oldversion < 2010021400) { $table = new xmldb_table('block_email_list_mail'); $field = new xmldb_field('respondedid'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $result = $result && $dbman->add_field($table, $field); } // Only compatible with 1.9 or prior versions if ($existfunction) { /// Block savepoint reached upgrade_blocks_savepoint($result, 2010021400, 'block_email_list'); } } return $result; }
/** * This file keeps track of upgrades to * the referentiel module * * Sometimes, changes between versions involve * alterations to database structures and other * major things that may break installations. * * The upgrade function in this file will attempt * to perform all the necessary actions to upgrade * your older installation to the current version. * * If there's something it cannot do itself, it * will tell you what you need to do. * * The commands in here will all be database-neutral, * using the methods of database_manager class * * Please do not forget to use upgrade_set_timeout() * before any action that may take longer time to finish. * * @package mod-forum * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @copyright 2011 onwards Jean Fruitet(jfruitet) {@link http://www.univ-nantes.fr} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_referentiel_upgrade($oldversion) { global $CFG, $DB, $OUTPUT; $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes // VERSION Moodle 2.x /// Add intro to table referentiel description $table = new xmldb_table('referentiel'); /// Adding fields $field = new xmldb_field('intro'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'config_impression'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel}", null); foreach ($rs as $res) { if (!empty($res->description_instance)) { $res->intro = $res->description_instance; } $DB->update_record('referentiel', $res); } $rs->close(); } /// Adding fields $field = new xmldb_field('introformat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'intro'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// And upgrade begins here. //===== 1.9.0 upgrade line ======// if ($oldversion < 2008052700) { /// Define field evaluation to be added to referentiel_certificat $table = new xmldb_table('referentiel_certificat'); $field = new xmldb_field('evaluation'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'valide'); /// Launch add field evaluation if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2008052700, 'referentiel'); } if ($oldversion < 2008052800) { /// Define field logo_etablissement to be added to referentiel_etablissement $table = new xmldb_table('referentiel_etablissement'); $field = new xmldb_field('logo_etablissement'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'adresse_etablissement'); /// Launch add field referentiel_etablissement if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Add some values to referentiel_etablissement $rec = new stdClass(); $rec->num_etablissement = 'INCONNU'; $rec->nom_etablissement = 'A COMPLETER'; $rec->adresse_etablissement = 'A COMPLETER'; $rec->logo_etablissement = ' '; /// Insert the add action in log_display $DB->insert_record('referentiel_etablissement', $rec, false, false); upgrade_mod_savepoint(true, 2008052800, 'referentiel'); } if ($oldversion < 2008062300) { // VERSION 1.2 /// Define new field liste_codes_competence to be added to referentiel_referentiel $table1 = new xmldb_table('referentiel_referentiel'); $field1 = new xmldb_field('liste_codes_competence'); $field1->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'nb_domaines'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table1, $field1)) { $dbman->add_field($table1, $field1); } /// Define new field liste_empreintes_competence to be added to referentiel_referentiel $field2 = new xmldb_field('liste_empreintes_competence'); $field2->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'liste_codes_competence'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table1, $field2)) { $dbman->add_field($table1, $field2); } /// Define new field logo_referentiel to be added to referentiel_referentiel $field3 = new xmldb_field('logo_referentiel'); $field3->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'local'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table1, $field3)) { $dbman->add_field($table1, $field3); } /// Define new field empreinte_item to be added to referentiel_item_competence $table2 = new xmldb_table('referentiel_item_competence'); $field4 = new xmldb_field('empreinte_item'); $field4->set_attributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'poids_item'); /// change fiel type field etiquette_url in referentiel_document if (!$dbman->field_exists($table2, $field4)) { $dbman->add_field($table2, $field4); } upgrade_mod_savepoint(true, 2008062300, 'referentiel'); } if ($oldversion < 2009042900) { // VERSION 3.0 /// Define new field config to be added to referentiel $table = new xmldb_table('referentiel'); $field = new xmldb_field('config'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;', 'visible'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Redefinir type field liste_codes_competence de referentiel_referentiel $table = new xmldb_table('referentiel_referentiel'); $field = new xmldb_field('liste_codes_competence'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'nb_domaines'); /// Change field type if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } /// Refinir type field liste_empreintes_competence referentiel_referentiel $field = new xmldb_field('liste_empreintes_competence'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'liste_codes_competence'); /// Change field type if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } /// Refinir type field competences_activite de referentiel_activite $table = new xmldb_table('referentiel_activite'); $field = new xmldb_field('competences_activite'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'description_activite'); /// Change field type if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } /// Refinir type field competences_certificat de referentiel_certificat $table = new xmldb_table('referentiel_certificat'); $field = new xmldb_field('competences_certificat'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'commentaire_certificat'); /// Change field type if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } // NOUVEAUX CHAMPS /// Define new fields to be added to referentiel_referentiel $table = new xmldb_table('referentiel_referentiel'); $field = new xmldb_field('mail_auteur_referentiel'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'code_referentiel'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('cle_referentiel'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'mail_auteur_referentiel'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('pass_referentiel'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'cle_referentiel'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Nouvelles tables /// Define table referentiel_task to be created $table = new xmldb_table('referentiel_task'); /// Adding fields to table referentiel_task $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('type_task', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('description_task', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'type_task'); $table->add_field('competences_task', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'description_task'); $table->add_field('criteres_evaluation', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'competences_task'); $table->add_field('ref_instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'criteres_evaluation'); $table->add_field('ref_referentiel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_instance'); $table->add_field('ref_course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_referentiel'); $table->add_field('auteurid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_course'); $table->add_field('date_creation', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'auteurid'); $table->add_field('date_modif', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'date_creation'); $table->add_field('date_debut', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'date_modif'); $table->add_field('date_fin', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'date_debut'); /// Adding keys to table referentiel_task $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding index to table referentiel_notification_queue $table->add_index('user', XMLDB_INDEX_NOTUNIQUE, array('userid')); /// Launch create table for referentiel_task if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } /// Define table referentiel_consigne to be created $table = new xmldb_table('referentiel_consigne'); /// Adding fields to table referentiel_consigne $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('type_consigne', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('description_consigne', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'type_consigne'); $table->add_field('url_consigne', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'description_consigne'); $table->add_field('ref_task', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'url_consigne'); /// Adding keys to table referentiel_consigne $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Launch create table for referentiel_consigne if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } /// Define table referentiel_a_user_task to be created $table = new xmldb_table('referentiel_a_user_task'); /// Adding fields to table referentiel_a_user_task $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('ref_user', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('ref_task', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_user'); /// Adding keys to table referentiel_a_user_task $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Launch create table for referentiel_a_user_task if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } // AJOUT CHAMP a table referentiel_activite $table = new xmldb_table('referentiel_activite'); $field = new xmldb_field('ref_task'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'approved'); /// Launch add field ref_task if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('referentiel_a_user_task'); $field = new xmldb_field('date_selection'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_task'); /// Launch add field ref_task if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('referentiel_a_user_task'); $field = new xmldb_field('ref_activite'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'date_selection'); /// Launch add field ref_task if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2009042900, 'referentiel'); } if ($oldversion < 2009083100) { // VERSION 3.2.5 /// Changing type of field seuil_certificat on table referentiel_referentiel to float $table = new xmldb_table('referentiel_referentiel'); $field = new xmldb_field('seuil_certificat'); $field->set_attributes(XMLDB_TYPE_FLOAT, null, null, XMLDB_NOTNULL, null, '0', 'url_referentiel'); /// Launch change of type for field seuil_certificat if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } /// Changing type of field poids_item on table referentiel_item_competence to float $table = new xmldb_table('referentiel_item_competence'); $field = new xmldb_field('poids_item'); $field->set_attributes(XMLDB_TYPE_FLOAT, null, null, XMLDB_NOTNULL, null, '0', 'type_item'); /// Launch if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } upgrade_mod_savepoint(true, 2009083100, 'referentiel'); } if ($oldversion < 2009110100) { // VERSION 4.0.1 // Nouveau champ liste_poids_competence dans referentiel_referentiel /// Define new field liste_poids_competence to be added to referentiel_referentiel $table = new xmldb_table('referentiel_referentiel'); $field = new xmldb_field('liste_poids_competence'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'liste_empreintes_competence'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Nouveau champ date_modif_student dans referentiel_activite /// Define new field liste_poids_competence to be added to referentiel_referentiel $table = new xmldb_table('referentiel_activite'); $field = new xmldb_field('date_modif_student'); $field->set_attributes(XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'date_creation'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2009110100, 'referentiel'); } if ($oldversion < 2009112800) { // VERSION 4.1.2 // Nouveau champ competences_activite dans referentiel_certificat /// Define new field competences_activite to be added to referentiel_certificat $table = new xmldb_table('referentiel_certificat'); $field = new xmldb_field('competences_activite'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'competences_certificat'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2009112800, 'referentiel'); } if ($oldversion < 2009122009) { // VERSION 4.2.0 // Nouveau champ cible_document dans referentiel_document /// Define new field cible_document to be added to referentiel_document $table1 = new xmldb_table('referentiel_document'); $field1 = new xmldb_field('cible_document'); $field1->set_attributes(XMLDB_TYPE_INTEGER, 4, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'ref_activite'); /// Launch add field if (!$dbman->field_exists($table1, $field1)) { $dbman->add_field($table1, $field1); } // Nouveau champ etiquette_document dans referentiel_document /// Define new field etiquette to be added to referentiel_document $field2 = new xmldb_field('etiquette_document'); $field2->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'cible_document'); /// Launch add field if (!$dbman->field_exists($table1, $field2)) { $dbman->add_field($table1, $field2); } $table2 = new xmldb_table('referentiel_consigne'); $field3 = new xmldb_field('cible_consigne'); $field3->set_attributes(XMLDB_TYPE_INTEGER, 4, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'ref_task'); if (!$dbman->field_exists($table2, $field3)) { $dbman->add_field($table2, $field3); } $field4 = new xmldb_field('etiquette_consigne'); $field4->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'cible_consigne'); /// Launch add field if (!$dbman->field_exists($table2, $field4)) { $dbman->add_field($table2, $field4); } upgrade_mod_savepoint(true, 2009122009, 'referentiel'); } if ($oldversion < 2010010500) { // VERSION 4.2.1 /// Define new default for field config for referentiel table $table = new xmldb_table('referentiel'); $field2 = new xmldb_field('config_impression'); $field2->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'refcert:1;instcert:0;numetu:1;nometu:1;etabetu:0;ddnetu:0;lieuetu:0;adretu:0;detail:1;pourcent:0;compdec:0;compval:1;nomreferent:0;jurycert:1;comcert:0;', 'config'); /// Launch add field referentiel if (!$dbman->field_exists($table, $field2)) { $dbman->add_field($table, $field2); } upgrade_mod_savepoint(true, 2010010500, 'referentiel'); } if ($oldversion < 2010011000) { // VERSION 4.2.3 /// Define new fields for referentiel_task table $table = new xmldb_table('referentiel_task'); $field = new xmldb_field('cle_souscription'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'date_fin'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field2 = new xmldb_field('souscription_libre'); $field2->set_attributes(XMLDB_TYPE_INTEGER, 4, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'cle_souscription'); /// Launch add field referentiel if (!$dbman->field_exists($table, $field2)) { $dbman->add_field($table, $field2); } upgrade_mod_savepoint(true, 2010010500, 'referentiel'); } if ($oldversion < 2010021200) { // VERSION 4.4.4 /// Define table referentiel_notification_queue to be created $table = new xmldb_table('referentiel_notification_queue'); /// Adding fields to table referentiel_notification_queue $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('activiteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'activiteid'); $table->add_field('activiteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid'); $table->add_field('type', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified'); /// Adding keys to table referentiel_notification_queue $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('activiteid', XMLDB_KEY_FOREIGN, array('activiteid'), 'referentiel_activite', array('id')); /// Adding index to table referentiel_notification_queue $table->add_index('user', XMLDB_INDEX_NOTUNIQUE, array('userid')); /// Create table for referentiel_notification_queue if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } /// Define new fields for referentiel_activite table $table = new xmldb_table('referentiel_activite'); $field = new xmldb_field('mailed'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_task'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('mailnow'); $field->set_attributes(XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'mailed'); /// Launch add field referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define new fields for referentiel_task table $table = new xmldb_table('referentiel_task'); $field = new xmldb_field('mailed'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'souscription_libre'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('mailnow'); $field->set_attributes(XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'mailed'); /// Launch add field referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define new fields for referentiel_certificat table $table = new xmldb_table('referentiel_certificat'); $field = new xmldb_field('mailed'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'evaluation'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('mailnow'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'mailed'); /// Launch add field referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2010021200, 'referentiel'); } if ($oldversion < 2010022800) { // VERSION 5.1.0 /// Define table referentiel_activite_modules to be created $table = new xmldb_table('referentiel_activite_modules'); /// Adding fields to table referentiel_activite_modules $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('type', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('moduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'type'); $table->add_field('ref_instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'moduleid'); $table->add_field('ref_referentiel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_instance'); $table->add_field('ref_course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_referentiel'); /// Launch add field referentiel $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_course'); $table->add_field('activiteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid'); /// Adding keys to table referentiel_activite_modules $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Launch create table for referentiel_activite_modules if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } upgrade_mod_savepoint(true, 2010022800, 'referentiel'); } if ($oldversion < 2010031600) { // VERSION 5.2.0 /// Define new fields for referentiel_task table $table = new xmldb_table('referentiel_task'); $field = new xmldb_field('tache_masquee'); $field->set_attributes(XMLDB_TYPE_INTEGER, 4, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'souscription_libre'); /// Launch add field referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2010031600, 'referentiel'); } if ($oldversion < 2010032500) { // VERSION 5.2.1 /// Define table referentiel_accompagnement to be created $table = new xmldb_table('referentiel_accompagnement'); /// Adding fields to table referentiel_accompagnement $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('accompagnement', XMLDB_TYPE_CHAR, '3', null, XMLDB_NOTNULL, null, 'REF', 'id'); $table->add_field('ref_instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'accompagnement'); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ref_instance'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'courseid'); $table->add_field('teacherid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid'); /// Adding keys to table referentiel_accompagnement $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Launch create table for referentiel_accompagnement if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } upgrade_mod_savepoint(true, 2010032500, 'referentiel'); } if ($oldversion < 2010033110) { // VERSION 5.2.3 /// Drop table referentiel_notification_queue /// because table name don't respect XML facet specification /// Define table referentiel_notification to be created $table = new xmldb_table('referentiel_notification'); /// Adding fields to table referentiel_notification $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('activiteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'activiteid'); $table->add_field('type', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified'); /// Adding keys to table referentiel_notification $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('activiteid', XMLDB_KEY_FOREIGN, array('activiteid'), 'referentiel_activite', array('id')); /// Adding index to table referentiel_notification $table->add_index('user', XMLDB_INDEX_NOTUNIQUE, array('userid')); /// Launch create table for referentiel_notification if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } $tableold = new xmldb_table('referentiel_notification_queue'); /// Silenty drop any previous referentiel_notification_queue table if (table_exists($tableold)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel_notification_queue}", null); foreach ($rs as $res) { $DB->insert_record('referentiel_notification', $res, false, false); } $rs->close(); $status = $dbman->drop_table($tableold, true, true); } upgrade_mod_savepoint(true, 2010033110, 'referentiel'); } if ($oldversion < 2010060900) { // VERSION 5.3.3 /// Define table referentiel_certificat to be updated $table = new xmldb_table('referentiel_certificat'); /// Adding fields to table referentiel_certificat $field = new xmldb_field('synthese_certificat'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'mailnow'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2010060900, 'referentiel'); } if ($oldversion < 2010101800) { // VERSION 5.4.3 /// Define table referentiel_certificat to be updated $table = new xmldb_table('referentiel_referentiel'); /// Adding fields to table referentiel_referentiel $field = new xmldb_field('config'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;', 'logo_referentiel'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Adding fields to table referentiel_referentiel $field2 = new xmldb_field('config_impression'); $field2->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'refcert:1;instcert:0;numetu:1;nometu:1;etabetu:0;ddnetu:0;lieuetu:0;adretu:0;detail:1;pourcent:0;compdec:0;compval:1;nomreferent:0;jurycert:1;comcert:0;', 'config'); /// Launch add field referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field2); } upgrade_mod_savepoint(true, 2010101800, 'referentiel'); } if ($oldversion < 2010111100) { // VERSION 5.4.4 /// Add new field to table referentiel_activite_modules $table = new xmldb_table('referentiel_activite_modules'); /// Adding fields $field = new xmldb_field('ref_activite'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'activiteid'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2010111100, 'referentiel'); } if ($oldversion < 2011022012) { // VERSION 5.5.1 /// mise à jour $table = new xmldb_table('referentiel'); /// Silenty update if ($dbman->table_exists($table)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "graph:0;"; $DB->update_record('referentiel', $res); } $rs->close(); } $table2 = new xmldb_table('referentiel_referentiel'); /// Silently update if ($dbman->table_exists($table2)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel_referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "graph:0;"; $DB->update_record('referentiel_referentiel', $res); } $rs->close(); } upgrade_mod_savepoint(true, 2011022012, 'referentiel'); } if ($oldversion < 2011031100) { // VERSION 5.5.5 /// Define table referentiel_pedagogie to be created $table = new xmldb_table('referentiel_pedagogie'); /// Adding fields to table chat_messages_current $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('promotion', XMLDB_TYPE_CHAR, '4', null, null, null, null); $table->add_field('num_groupe', XMLDB_TYPE_CHAR, '20', null, null, null, null); $table->add_field('date_cloture', XMLDB_TYPE_CHAR, '20', null, null, null, null); $table->add_field('formation', XMLDB_TYPE_CHAR, '40', null, null, null, null); $table->add_field('pedagogie', XMLDB_TYPE_CHAR, '40', null, null, null, null); $table->add_field('composante', XMLDB_TYPE_CHAR, '40', null, null, null, null); $table->add_field('commentaire', XMLDB_TYPE_CHAR, '40', null, null, null, null); /// Adding keys to table $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// create table if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table referentiel_a_user_pedagogie to be created $table = new xmldb_table('referentiel_a_user_pedagogie'); /// Adding fields $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('refrefid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('refpedago', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// create table if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } upgrade_mod_savepoint(true, 2011031100, 'referentiel'); } if ($oldversion < 2011042204) { /* /// Adding index to table referentiel_notification_queue $index = new xmldb_index('user'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('userid')); if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } */ // Supprimer une source d'erreur lors de la creation d'un certificat /// Define index uniqueuser (unique) to be dropped from referentiel_certificat $table = new xmldb_table('referentiel_certificat'); $index = new xmldb_index('uniqueuser'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('userid')); /// Launch drop index uniqueuser if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // recreer index non unique /// Define index indexuser (not unique) to be added to referentiel_certificat $table = new xmldb_table('referentiel_certificat'); $index = new xmldb_index('indexuser'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('userid')); /// Launch drop index uniqueuser if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } upgrade_mod_savepoint(true, 2011042204, 'referentiel'); } if ($oldversion < 2011042205) { // VERSION 5.6.01 /// Define index userpedagoref (unique) to be added to referentiel_a_user_pedagogie $table = new xmldb_table('referentiel_a_user_pedagogie'); $index = new xmldb_index('userpedagoref'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('userid', 'refrefid', 'refpedago')); /// Launch drop index uniqueuser if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } upgrade_mod_savepoint(true, 2011042205, 'referentiel'); } if ($oldversion < 2011042213) { // VERSION 5.6.02 // Define table referentiel_course_users $table = new xmldb_table('referentiel_course_users'); /// Adding fields to table $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('tab_users', XMLDB_TYPE_BINARY, 'big', null, null, null, null); $table->add_field('tab_initiales', XMLDB_TYPE_BINARY, 'big', null, null, null, null); $table->add_field('tab_pedagos', XMLDB_TYPE_BINARY, 'big', null, null, null, null); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('refrefid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table $table->add_index('refcourse', XMLDB_INDEX_UNIQUE, array('courseid', 'refrefid')); /// create table for if (!$dbman->table_exists($table)) { $dbman->create_table($table); } upgrade_mod_savepoint(true, 2011042213, 'referentiel'); } if ($oldversion < 2011082500) { // VERSION Moodle 1.9 - 5.6.03 et Moodle 2 - 1.0.6 // Update type_activite field $table = new xmldb_table('referentiel_activite'); $field = new xmldb_field('type_activite'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); /// Launch change of type for field type_activite //if ($dbman->field_exists($table,$field)) { $dbman->change_field_type($table, $field); //} // Update type_task field $table1 = new xmldb_table('referentiel_task'); $field1 = new xmldb_field('type_task'); $field1->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); /// Launch change of type for field type_task if ($dbman->field_exists($table1, $field1)) { $dbman->change_field_type($table1, $field1); } upgrade_mod_savepoint(true, 2011082500, 'referentiel'); } if ($oldversion < 2011082610) { // VERSION Moodle 1.9 - 5.6.04 et Moodle 2 - 1.0.8 /// Modify field default config table referentiel $table = new xmldb_table('referentiel'); $field = new xmldb_field('config'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;light:0;', 'visible'); /// Launch change of type for field type_activite $dbman->change_field_default($table, $field); /// Modify field default config table referentiel_referentiel $table1 = new xmldb_table('referentiel_referentiel'); $field1 = new xmldb_field('config'); $field1->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;light:0;', 'logo_referentiel'); /// Launch change of type for field type_activite $dbman->change_field_default($table1, $field1); /// mise à jour des champs existants $table2 = new xmldb_table('referentiel'); /// Silenty update if ($dbman->table_exists($table2)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "light:0;"; $DB->update_record('referentiel', $res); } $rs->close(); } $table3 = new xmldb_table('referentiel_referentiel'); /// Silently update if ($dbman->table_exists($table3)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel_referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "light:0;"; $DB->update_record('referentiel_referentiel', $res); } $rs->close(); } upgrade_mod_savepoint(true, 2011082610, 'referentiel'); } if ($oldversion < 2011090710) { // VERSION Moodle 1.9 - 5.6.08 et Moodle 2 - 1.0.9 // Define table referentiel_activite $table = new xmldb_table('referentiel_activite'); /// Adding index to table referentiel_activite $index1 = new xmldb_index('indexuser'); $index1->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('userid')); if (!$dbman->index_exists($table, $index1)) { $dbman->add_index($table, $index1); } /// Adding index to table referentiel_activite $index2 = new xmldb_index('indexinstance'); $index2->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_instance')); if (!$dbman->index_exists($table, $index2)) { $dbman->add_index($table, $index2); } upgrade_mod_savepoint(true, 2011090710, 'referentiel'); } if ($oldversion < 2011090712) { // VERSION Moodle 1.9 - 5.6.09 et Moodle 2 - 1.0.7 /// Define index userid (not unique) to be added to referentiel_task $table = new xmldb_table('referentiel_task'); $index = new xmldb_index('indexinstance'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_instance')); /// Launch add index if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Define index activite (not unique) to be added to referentiel_document $table1 = new xmldb_table('referentiel_document'); $index1 = new xmldb_index('indexactivite'); $index1->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_activite')); /// Launch add index if (!$dbman->index_exists($table1, $index1)) { $dbman->add_index($table1, $index1); } /// Define index instanceid (not unique) to be added to referentiel_consigne $table2 = new xmldb_table('referentiel_consigne'); $index2 = new xmldb_index('indextask'); $index2->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_task')); /// Launch add index if (!$dbman->index_exists($table2, $index2)) { $dbman->add_index($table2, $index2); } upgrade_mod_savepoint(true, 2011090712, 'referentiel'); } if ($oldversion < 2011092710) { // VERSION Moodle 1.9 - 5.6.09 et Moodle 2 - 1.1.4 /// Define new field maxbytes $table = new xmldb_table('referentiel'); $field = new xmldb_field('maxbytes'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1073741824', 'config_impression'); /// Launch add field evaluation if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Silently update if ($dbman->table_exists($table)) { $maxbytes = 1073741824; $sql = "SELECT id, course FROM {referentiel}"; if ($rs = $DB->get_records_sql($sql, NULL)) { foreach ($rs as $res) { $course = $DB->get_record('course', array("id" => "{$res->course}")); $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes); $DB->set_field("referentiel", "maxbytes", "{$maxbytes}", array("id" => "{$res->id}")); } } } /// Define index referenteil (not unique) to be added to referentiel_activite $table1 = new xmldb_table('referentiel_activite'); $index1 = new xmldb_index('indexreferentiel'); $index1->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_referentiel')); /// Launch add index if (!$dbman->index_exists($table1, $index1)) { $dbman->add_index($table1, $index1); } /// Define index referentiel (not unique) to be added to referentiel_certificat $table2 = new xmldb_table('referentiel_certificat'); $index2 = new xmldb_index('indexreferentiel'); $index2->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_referentiel')); /// Launch add index if (!$dbman->index_exists($table2, $index2)) { $dbman->add_index($table2, $index2); } upgrade_mod_savepoint(true, 2011092710, 'referentiel'); } if ($oldversion < 2011101611) { // VERSION Moodle 1.9 - '5.7.04 - 2011/10/16' Moodle 2 - '1.1.8 - 2011/10/16'; /// Define index userpedagoref (unique) to be added to referentiel_a_user_pedagogie $table = new xmldb_table('referentiel_etudiant'); $index = new xmldb_index('usernum'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('userid')); /// Launch drop index uniqueuser if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Change type field logo_etablissement $table = new xmldb_table('referentiel_etablissement'); $field = new xmldb_field('logo_etablissement'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NULL, null, null, 'adresse_etablissement'); /// Launch change of type for field type_task if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } upgrade_mod_savepoint(true, 2011101611, 'referentiel'); } if ($oldversion < 2011112615) { // VERSION Moodle 1.9 N°6.1.01 VERSION Moodle 2 - '1.2.01 - 2011/12/01'; /// Define table referentiel_repartition $table = new xmldb_table('referentiel_repartition'); /// Adding fields $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('ref_instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('ref_occurrence', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('teacherid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('code_item', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); /// Adding keys to table $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// create table if (!$dbman->table_exists($table)) { $dbman->create_table($table, true, true); } /// Indexes $index = new xmldb_index('indexinstance'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_instance')); /// Add index if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Indexes $index = new xmldb_index('indexoccurrence'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('ref_occurrence')); /// Add index if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } upgrade_mod_savepoint(true, 2011112615, 'referentiel'); } if ($oldversion < 2012032813) { // VERSION Moodle 2.1 2.1.06 - 2012/03/28; /// Add field table referentiel_domaine $table = new xmldb_table('referentiel_domaine'); $field = new xmldb_field('type_domaine'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0', 'nb_competences'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('seuil_domaine'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0.0', 'type_domaine'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Add field table referentiel_competence $table = new xmldb_table('referentiel_competence'); $field = new xmldb_field('type_competence'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0', 'nb_item_competences'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('seuil_competence'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0.0', 'type_competence'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Modify field default config table referentiel $table = new xmldb_table('referentiel_item_competence'); /// Redefinir type field $field = new xmldb_field('type_item'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0', 'ref_competence'); /// Launch change of default for field if ($dbman->field_exists($table, $field)) { if ($items = $DB->get_recordset_sql("SELECT id, type_item FROM {referentiel_item_competence} ORDER BY id, type_item ", null)) { foreach ($items as $item) { if ($item->type_item != '') { $DB->set_field('referentiel_item_competence', 'type_item', '1', array('id' => $item->id)); } else { $DB->set_field('referentiel_item_competence', 'type_item', '0', array('id' => $item->id)); } } } // $dbman->change_field_default($table, $field, true, true); $dbman->change_field_type($table, $field); } /// Define table referentiel_protocol $table = new xmldb_table('referentiel_protocol'); /// Adding fields to table referentiel_protocol $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('ref_occurrence', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('seuil_referentiel', XMLDB_TYPE_FLOAT, null, null, XMLDB_NOTNULL, null, null); $table->add_field('l_domaines_oblig', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('l_seuils_domaines', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('l_competences_oblig', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('l_seuils_competences', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('l_items_oblig', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('commentaire', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('actif', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table $table->add_index('indexoccurrence', XMLDB_INDEX_UNIQUE, array('ref_occurrence')); /// create table for if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// initialiser les tables $table2 = new xmldb_table('referentiel_referentiel'); /// Silently update if ($dbman->table_exists($table) && $dbman->table_exists($table2)) { if ($occurrences = $DB->get_recordset_sql("SELECT id, seuil_certificat, liste_codes_competence FROM {referentiel_referentiel} ORDER BY id", null)) { foreach ($occurrences as $occurrence) { if (!empty($occurrence) && !empty($occurrence->id)) { // mettre a jour le protocole $protocole = new stdClass(); $protocole->ref_occurrence = $occurrence->id; $protocole->seuil_referentiel = $occurrence->seuil_certificat; // initialiser les items obligatoires à 0 $liste_items_obligatoires = ''; if (!empty($occurrence->liste_codes_competence)) { $t_codes_items = explode("/", $occurrence->liste_codes_competence); while (list($key, $code) = each($t_codes_items)) { //echo "$key => code\n"; if (!empty($code)) { $liste_items_obligatoires .= $code . ':0/'; } } } $protocole->l_items_oblig = $liste_items_obligatoires; // competences $liste_competences_obligatoires = ''; $liste_competences_seuils = ''; // domaines $liste_domaines_obligatoires = ''; $liste_domaines_seuils = ''; if ($domaines = $DB->get_recordset_sql("SELECT id, num_domaine, code_domaine FROM {referentiel_domaine} WHERE ref_referentiel=:id ORDER BY num_domaine ", array("id" => $occurrence->id))) { foreach ($domaines as $domaine) { $liste_comp_oblig = ''; $liste_comp_seuil = ''; if ($codes_competence = $DB->get_recordset_sql("SELECT code_competence, num_competence FROM {referentiel_competence} WHERE ref_domaine=:id ORDER BY num_competence ", array("id" => $domaine->id))) { foreach ($codes_competence as $codec) { $liste_comp_oblig .= $codec->code_competence . ':0/'; $liste_comp_seuil .= $codec->code_competence . ':0.0/'; } $codes_competence->close(); } $liste_competences_obligatoires .= $liste_comp_oblig; $liste_competences_seuils .= $liste_comp_seuil; if (!empty($domaine->code_domaine)) { $liste_domaines_obligatoires .= $domaine->code_domaine . ':0/'; $liste_domaines_seuils .= $domaine->code_domaine . ':0.0/'; } } $domaines->close(); } // initialiser les competences $protocole->l_competences_oblig = $liste_competences_obligatoires; $protocole->l_seuils_competences = $liste_competences_seuils; // initialiser les domaines $protocole->l_domaines_oblig = $liste_domaines_obligatoires; $protocole->l_seuils_domaines = $liste_domaines_seuils; $protocole->commentaire = ''; $protocole->timemodified = time(); $protocole->actif = 0; // par defaut protocole inactive // creer la ligne if (!$DB->get_record('referentiel_protocol', array('ref_occurrence' => $protocole->ref_occurrence))) { $protocole->id = $DB->insert_record('referentiel_protocol', $protocole); } } } $occurrences->close(); } } upgrade_mod_savepoint(true, 2012032813, 'referentiel'); } /* ############################################################## */ if ($oldversion < 2012051700) { // moodle 2 version 07 du 02/04/2012 /// Verifier si un index peut être ajoute aux tables domaine, competence, referentiel // ADD fields minimas $table = new xmldb_table('referentiel_domaine'); $field = new xmldb_field('seuil_domaine'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0.0', 'type_domaine'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('minima_domaine'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0', 'seuil_domaine'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // renommer les lignes qui posent problème if ($dbman->table_exists($table)) { $sql = "SELECT DISTINCT t_domaine2.id as id, t_domaine2.code_domaine as code_domaine, {referentiel_referentiel}.id as refrefid\n FROM {referentiel_referentiel},\n {referentiel_domaine} AS t_domaine1, {referentiel_domaine} AS t_domaine2\n WHERE {referentiel_referentiel}.id=t_domaine1.ref_referentiel\n AND {referentiel_referentiel}.id=t_domaine2.ref_referentiel\n AND t_domaine1.id<t_domaine2.id\n AND t_domaine1.code_domaine=t_domaine2.code_domaine\n ORDER BY t_domaine2.id "; if ($rs = $DB->get_records_sql($sql, NULL)) { foreach ($rs as $res) { $DB->set_field("referentiel_domaine", "code_domaine", $res->code_domaine . "-" . $res->id, array("id" => "{$res->id}")); // Mettre a jour la table referentiel_protocol $sql = "SELECT id, code_domaine, type_domaine, num_domaine FROM {referentiel_domaine} WHERE ref_referentiel=:refrefid ORDER BY num_domaine "; $domaines = $DB->get_records_sql($sql, array("refrefid" => $res->refrefid)); if ($domaines) { $l_domaines_oblig = ''; $l_seuils_domaines = ''; foreach ($domaines as $domaine) { if ($domaine) { $l_domaines_oblig .= $domaine->code_domaine . ":" . $domaine->type_domaine . "/"; $l_seuils_domaines .= $domaine->code_domaine . ":" . $domaine->seuil_domaine . "/"; } } $DB->set_field("referentiel_protocol", "l_domaines_oblig", $l_domaines_oblig, array("ref_occurrence" => $res->refrefid)); $DB->set_field("referentiel_protocol", "l_seuils_domaines", $l_seuils_domaines, array("ref_occurrence" => $res->refrefid)); } } } } // maintenant creer les indexes /// Indexes $index = new xmldb_index('codedomaineunique'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('code_domaine', 'ref_referentiel')); /// Launch add index if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Add field table referentiel_competence $table = new xmldb_table('referentiel_competence'); $field = new xmldb_field('seuil_competence'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0.0', 'type_competence'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('minima_competence'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, '0', 'seuil_competence'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // renommer les lignes qui posent problème if ($dbman->table_exists($table)) { $sql = "SELECT DISTINCT t_competence2.id as id, t_competence2.code_competence as code_competence, t_competence2.ref_domaine as ref_domaine, t_domaine.ref_referentiel as refrefid\n FROM {referentiel_referentiel},\n {referentiel_domaine} AS t_domaine,\n {referentiel_competence} AS t_competence1,\n {referentiel_competence} AS t_competence2\n WHERE {referentiel_referentiel}.id=t_domaine.ref_referentiel\n AND t_domaine.id=t_competence1.ref_domaine\n AND t_domaine.id=t_competence2.ref_domaine\n AND t_competence1.id<t_competence2.id\n AND t_competence1.code_competence=t_competence2.code_competence\n ORDER BY t_competence2.id "; if ($rs = $DB->get_records_sql($sql, NULL)) { foreach ($rs as $res) { $DB->set_field("referentiel_competence", "code_competence", $res->code_competence . "-" . $res->id, array("id" => "{$res->id}")); // Mettre a jour la table referentiel_protocol $sql = "SELECT id, code_competence, type_competence, num_competence FROM {referentiel_competence} WHERE ref_domaine=:ref_domaine ORDER BY ref_domaine, num_competence "; $competences = $DB->get_records_sql($sql, array("ref_domaine" => $res->ref_domaine)); if ($competences) { $l_competences_oblig = ''; $l_seuils_competences = ''; foreach ($competences as $competence) { if ($competence) { $l_competences_oblig .= $competence->code_competence . ":" . $competence > type_competence . "/"; $l_seuils_competences .= $competence->code_competence . ":" . $competence->seuil_competence . "/"; } } $DB->set_field("referentiel_protocol", "l_competences_oblig", $l_competences_oblig, array("ref_occurrence" => $res->refrefid)); $DB->set_field("referentiel_protocol", "l_seuils_competences", $l_seuils_competences, array("ref_occurrence" => $res->refrefid)); } } } } // maintenant creer les indexes /// Indexes $index = new xmldb_index('codecompetenceunique'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('code_competence', 'ref_domaine')); /// Launch add index if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Table Item $table = new xmldb_table('referentiel_item_competence'); // renommer les lignes qui posent problème if ($dbman->table_exists($table)) { $sql = "SELECT DISTINCT t_item2.id as id, t_item2.code_item as code_item, {$CFG->prefix}referentiel_referentiel.id as refrefid\n FROM {referentiel_referentiel},\n {referentiel_item_competence} AS t_item1,\n {referentiel_item_competence} AS t_item2\n WHERE {referentiel_referentiel}.id=t_item1.ref_referentiel\n AND {referentiel_referentiel}.id=t_item2.ref_referentiel\n AND t_item1.id<t_item2.id\n AND t_item1.code_item=t_item2.code_item\n ORDER BY t_item2.id "; if ($rs = $DB->get_records_sql($sql, NULL)) { foreach ($rs as $res) { $DB->set_field("referentiel_item_competence", "code_item", $res->code_item . "-" . $res->id, array("id" => "{$res->id}")); // Mettre a jour la table referentiel_referentiel et refrentiel_protocol $sql = "SELECT id, code_item, type_item, ref_competence, num_item FROM {referentiel_item_competence} WHERE ref_referentiel=:refrefid ORDER BY ref_competence, num_item "; $items = $DB->get_records_sql($sql, array("refrefid" => $res->refrefid)); if ($items) { $l_codes = ''; $l_items_oblig = ''; foreach ($items as $item) { if ($item) { $l_codes .= $item->code_item . "/"; $l_items_oblig .= $item->code_item . ":" . $item->type_item . "/"; } } $DB->set_field("referentiel_referentiel", "liste_codes_competence", $l_codes, array("id" => $res->refrefid)); $DB->set_field("referentiel_protocol", "l_items_oblig", $l_items_oblig, array("ref_occurrence" => $res->refrefid)); } } } } // maintenant creer les indexes /// Indexes $index = new xmldb_index('codeitemunique'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('code_item', 'ref_competence')); /// Launch add index if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } ///// NOUVEAUX CHAMPS minima /// Add field table referentiel_referentiel $table = new xmldb_table('referentiel_referentiel'); $field = new xmldb_field('minima_certificat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '1', 'seuil_certificat'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Add field table referentiel_protocol $table = new xmldb_table('referentiel_protocol'); $field = new xmldb_field('minima_referentiel'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '1', 'seuil_referentiel'); /// Launch add field if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Add field $maj1 = false; $field1 = new xmldb_field('l_minimas_domaines'); $field1->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'l_seuils_domaines'); /// Launch add field if (!$dbman->field_exists($table, $field1)) { $dbman->add_field($table, $field1); $maj1 = true; } $maj2 = false; $field2 = new xmldb_field('l_minimas_competences'); $field2->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'l_seuils_competences'); /// Launch add field if (!$dbman->field_exists($table, $field2)) { $dbman->add_field($table, $field2); $maj2 = true; } if ($maj1 && $maj2) { /// initialiser les tables $table2 = new xmldb_table('referentiel_referentiel'); /// Silently update if ($dbman->table_exists($table) && $dbman->table_exists($table2)) { $sql = "SELECT id FROM {referentiel_referentiel} ORDER BY id"; if ($occurrences = $DB->get_records_sql($sql, NULL)) { foreach ($occurrences as $occurrence) { if (!empty($occurrence) && !empty($occurrence->id)) { // initialiser les minimas $liste_minimas_domaines = ''; $liste_minimas_competences = ''; $domaines = $DB->get_records_sql("SELECT id, code_domaine, num_domaine FROM {referentiel_domaine} WHERE ref_referentiel=:refrefid ORDER BY num_domaine ", array("refrefid" => $occurrence->id)); if (!empty($domaines)) { foreach ($domaines as $domaine) { $liste_comp_minimas = ''; $codes_competence = $DB->get_records_sql("SELECT id, code_competence, num_competence FROM {referentiel_competence} WHERE ref_domaine=:ref_domaine ORDER BY num_competence ", array("ref_domaine" => $domaine->id)); if (!empty($codes_competence)) { foreach ($codes_competence as $codec) { $liste_comp_minimas .= $codec->code_competence . ':0/'; } } $liste_minimas_competences .= $liste_comp_minimas; if (!empty($domaine->code_domaine)) { $liste_minimas_domaines .= $domaine->code_domaine . ':0/'; } } } // creer la ligne $DB->set_field('referentiel_protocol', 'l_minimas_domaines', $liste_minimas_domaines, array("ref_occurrence" => $occurrence->id)); $DB->set_field('referentiel_protocol', 'l_minimas_competences', $liste_minimas_competences, array("ref_occurrence" => $occurrence->id)); } } } } } upgrade_mod_savepoint(true, 2012051700, 'referentiel'); } if ($oldversion < 2012060200) { /// Define new fields label_xxx to be added to referentiel_referentiel $table = new xmldb_table('referentiel_referentiel'); $field = new xmldb_field('label_domaine'); $field->set_attributes(XMLDB_TYPE_CHAR, '80', null, null, null, null, 'config_impression'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('label_competence'); $field->set_attributes(XMLDB_TYPE_CHAR, '80', null, null, null, null, 'label_domaine'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('label_item'); $field->set_attributes(XMLDB_TYPE_CHAR, '80', null, null, null, null, 'label_competence'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2012060200, 'referentiel'); } if ($oldversion < 2012071300) { /// Modify referentiel_etudiant $table = new xmldb_table('referentiel_etudiant'); if ($dbman->table_exists($table)) { // $sql = "UPDATE {referentiel_etudiant} SET `num_etudiant`='l_inconnu'\n WHERE (`num_etudiant`=? OR `num_etudiant`=? OR `num_etudiant`=? OR `num_etudiant`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); $sql = "UPDATE {referentiel_etudiant} SET `ddn_etudiant`='l_inconnu'\n WHERE (`ddn_etudiant`=? OR `ddn_etudiant`=? OR `ddn_etudiant`=? OR `ddn_etudiant`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); $sql = "UPDATE {referentiel_etudiant} SET `lieu_naissance`='l_inconnu'\n WHERE (`lieu_naissance`=? OR `lieu_naissance`=? OR `lieu_naissance`=? OR `lieu_naissance`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); $sql = "UPDATE {referentiel_etudiant} SET `departement_naissance`='l_inconnu'\n WHERE (`departement_naissance`=? OR `departement_naissance`=? OR `departement_naissance`=? OR `departement_naissance`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); $sql = "UPDATE {referentiel_etudiant} SET `adresse_etudiant`='l_inconnu'\n WHERE (`adresse_etudiant`=? OR `adresse_etudiant`=? OR `adresse_etudiant`=? OR `adresse_etudiant`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); } /// Modify referentiel_etablissement $table = new xmldb_table('referentiel_etablissement'); if ($dbman->table_exists($table)) { // $sql = "UPDATE {referentiel_etablissement} SET `num_etablissement`='l_inconnu'\n WHERE (`num_etablissement`=? OR `num_etablissement`=? OR `num_etablissement`=? OR `num_etablissement`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); $sql = "UPDATE {referentiel_etablissement} SET `nom_etablissement`='l_inconnu'\n WHERE (`nom_etablissement`=? OR `nom_etablissement`=? OR `nom_etablissement`=? OR `nom_etablissement`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); $sql = "UPDATE {referentiel_etablissement} SET `adresse_etablissement`='l_inconnu'\n WHERE (`adresse_etablissement`=? OR `adresse_etablissement`=? OR `adresse_etablissement`=? OR `adresse_etablissement`=?) "; $DB->execute($sql, array('INCONNU', 'UNKNOWN', 'НЕВІДОМЕ', 'DESCONOCIDO')); } upgrade_mod_savepoint(true, 2012071300, 'referentiel'); } if ($oldversion < 2012060200) { /// Define new fields label_xxx to be added to referentiel_referentiel $table = new xmldb_table('referentiel_referentiel'); $field = new xmldb_field('label_domaine'); $field->set_attributes(XMLDB_TYPE_CHAR, '80', null, null, null, null, 'config_impression'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('label_competence'); $field->set_attributes(XMLDB_TYPE_CHAR, '80', null, null, null, null, 'label_domaine'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('label_item'); $field->set_attributes(XMLDB_TYPE_CHAR, '80', null, null, null, null, 'label_competence'); /// Launch add field referentiel_referentiel if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2012060200, 'referentiel'); } if ($oldversion < 2012101000) { /// Modify referentiel_referentiel $table = new xmldb_table('referentiel_certificat'); if ($dbman->table_exists($table)) { // set each valide field to 0 $sql = "UPDATE {referentiel_certificat} SET `valide`=0 "; $DB->execute($sql, array()); } upgrade_mod_savepoint(true, 2012101000, 'referentiel'); } if ($oldversion < 2013020200) { /// Modify referentiel_document /// <FIELD NAME="timestamp" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="etiquette_consigne" /> $table = new xmldb_table('referentiel_document'); $field = new xmldb_field('timestamp'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'etiquette_document'); /// Launch add field referentiel_document if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('referentiel_consigne'); $field = new xmldb_field('timestamp'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'etiquette_consigne'); /// Launch add field referentiel_document if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2013020200, 'referentiel'); } if ($oldversion < 2013021700) { /// Modify referentiel_etudiant ///<FIELD NAME="num_etudiant" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="id" NEXT="ddn_etudiant"/> $table = new xmldb_table('referentiel_etudiant'); $field = new xmldb_field('num_etudiant'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); /// Launch change of default for field // $dbman->change_field_default($table, $field, true, true); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2013021700, 'referentiel'); } if ($oldversion < 2013062700) { /// Create new table referentiel_scale $table = new xmldb_table('referentiel_scale'); if (!$dbman->table_exists($table)) { /// Adding fields to table referentiel_task $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('scale', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('threshold', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('maxscale', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); $table->add_field('icons', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('labels', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Launch create table $dbman->create_table($table, true, true); } /// Create new table referentiel_a_scale_occurrence $table = new xmldb_table('referentiel_a_scale_ref'); if (!$dbman->table_exists($table)) { /// Adding fields $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('refscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('refrefid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Launch create table $dbman->create_table($table, true, true); } /// Create new table referentiel_activite_scale $table = new xmldb_table('referentiel_activite_scale'); if (!$dbman->table_exists($table)) { /// Adding fields $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('refscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('activiteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('competences_bareme', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding index to table referentiel_notification_queue $table->add_index('indscale', XMLDB_INDEX_NOTUNIQUE, array('refscaleid')); $table->add_index('indactivite', XMLDB_INDEX_NOTUNIQUE, array('activiteid')); /// Launch create table $dbman->create_table($table, true, true); } upgrade_mod_savepoint(true, 2013062700, 'referentiel'); } if ($oldversion < 2013100400) { // VERSION Moodle 2.4 /// Modify field default config table referentiel $table = new xmldb_table('referentiel'); $field = new xmldb_field('config'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;light:0;hierarchy:0;', 'visible'); /// Launch change of type for field type_activite $dbman->change_field_default($table, $field); /// Modify field default config table referentiel_referentiel $table1 = new xmldb_table('referentiel_referentiel'); $field1 = new xmldb_field('config'); $field1->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;light:0;hierarchy:0;', 'logo_referentiel'); /// Launch change of type for field type_activite $dbman->change_field_default($table1, $field1); /// mise a jour des champs existants $table2 = new xmldb_table('referentiel'); /// Silenty update if ($dbman->table_exists($table2)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "hierarchy:0;"; $DB->update_record('referentiel', $res); } $rs->close(); } $table3 = new xmldb_table('referentiel_referentiel'); /// Silently update if ($dbman->table_exists($table3)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel_referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "hierarchy:0;"; $DB->update_record('referentiel_referentiel', $res); } $rs->close(); } upgrade_mod_savepoint(true, 2013100400, 'referentiel'); } if ($oldversion < 2013112400) { // VERSION Moodle 2.5 /// Modify field default config table referentiel $table = new xmldb_table('referentiel'); $field = new xmldb_field('config'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;light:0;hierarchy:0;cfcertif:0;certif:1;', 'visible'); /// Launch change of type for field type_activite $dbman->change_field_default($table, $field); /// Modify field default config table referentiel_referentiel $table1 = new xmldb_table('referentiel_referentiel'); $field1 = new xmldb_field('config'); $field1->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'scol:0;creref:0;selref:0;impcert:0;graph:0;light:0;hierarchy:0;cfcertif:0;certif:1;', 'logo_referentiel'); /// Launch change of type for field type_activite $dbman->change_field_default($table1, $field1); /// mise a jour des champs existants $table2 = new xmldb_table('referentiel'); /// Silenty update if ($dbman->table_exists($table2)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "cfcertif:0;certif:1;"; $DB->update_record('referentiel', $res); } $rs->close(); } $table3 = new xmldb_table('referentiel_referentiel'); /// Silently update if ($dbman->table_exists($table3)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel_referentiel}", null); foreach ($rs as $res) { $res->config = $res->config . "cfcertif:0;certif:1;"; $DB->update_record('referentiel_referentiel', $res); } $rs->close(); } upgrade_mod_savepoint(true, 2013112400, 'referentiel'); } if ($oldversion < 2014022802) { // VERSION Moodle 2.5 that uses block referentiel /// Modify errorneous field config table referentiel $table = new xmldb_table('referentiel'); if ($dbman->table_exists($table)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel}", null); foreach ($rs as $res) { if (strpos($res->config, 'hierachy') !== false) { $res->config = str_replace('hierachy', 'hierarchy', $res->config); $DB->update_record('referentiel', $res); } } $rs->close(); } /// Modify errorneous field config table referentiel_referentiel $table = new xmldb_table('referentiel_referentiel'); if ($dbman->table_exists($table)) { $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel_referentiel}", null); foreach ($rs as $res) { if (strpos($res->config, 'hierachy') !== false) { $res->config = str_replace('hierachy', 'hierarchy', $res->config); $DB->update_record('referentiel_referentiel', $res); } } $rs->close(); } upgrade_mod_savepoint(true, 2014022802, 'referentiel'); } return true; }
function xmldb_facetoface_upgrade($oldversion = 0) { global $CFG, $USER, $DB; $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. require_once $CFG->dirroot . '/mod/facetoface/lib.php'; $result = true; if ($result && $oldversion < 2008050500) { $table = new xmldb_table('facetoface'); $field = new xmldb_field('thirdpartywaitlist'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'thirdparty'); $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2008061000) { $table = new xmldb_table('facetoface_submissions'); $field = new xmldb_field('notificationtype'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified'); $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2008080100) { echo $OUTPUT->notification(get_string('upgradeprocessinggrades', 'facetoface'), 'notifysuccess'); require_once $CFG->dirroot . '/mod/facetoface/lib.php'; $transaction = $DB->start_delegated_transaction(); $DB->debug = false; // Too much debug output. // Migrate the grades to the gradebook. $sql = "SELECT f.id, f.name, f.course, s.grade, s.timegraded, s.userid,\n cm.idnumber as cmidnumber\n FROM {facetoface_submissions} s\n JOIN {facetoface} f ON s.facetoface = f.id\n JOIN {course_modules} cm ON cm.instance = f.id\n JOIN {modules} m ON m.id = cm.module\n WHERE m.name='facetoface'"; if ($rs = $DB->get_recordset_sql($sql)) { foreach ($rs as $facetoface) { $grade = new stdclass(); $grade->userid = $facetoface->userid; $grade->rawgrade = $facetoface->grade; $grade->rawgrademin = 0; $grade->rawgrademax = 100; $grade->timecreated = $facetoface->timegraded; $grade->timemodified = $facetoface->timegraded; $result = $result && GRADE_UPDATE_OK == facetoface_grade_item_update($facetoface, $grade); } $rs->close(); } $DB->debug = true; // Remove the grade and timegraded fields from facetoface_submissions. if ($result) { $table = new xmldb_table('facetoface_submissions'); $field1 = new xmldb_field('grade'); $field2 = new xmldb_field('timegraded'); $result = $result && $dbman->drop_field($table, $field1, false, true); $result = $result && $dbman->drop_field($table, $field2, false, true); } $transaction->allow_commit(); } if ($result && $oldversion < 2008090800) { // Define field timemodified to be added to facetoface_submissions. $table = new xmldb_table('facetoface_submissions'); $field = new xmldb_field('timecancelled'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'timemodified'); // Launch add field. $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2009111300) { // New fields necessary for the training calendar. $table = new xmldb_table('facetoface'); $field1 = new xmldb_field('shortname'); $field1->set_attributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, 'timemodified'); $result = $result && $dbman->add_field($table, $field1); $field2 = new xmldb_field('description'); $field2->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'shortname'); $result = $result && $dbman->add_field($table, $field2); $field3 = new xmldb_field('showoncalendar'); $field3->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'description'); $result = $result && $dbman->add_field($table, $field3); } if ($result && $oldversion < 2009111600) { $table1 = new xmldb_table('facetoface_session_field'); $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table1->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table1->add_field('type', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table1->add_field('possiblevalues', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); $table1->add_field('required', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table1->add_field('defaultvalue', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table1->add_field('isfilter', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table1->add_field('showinsummary', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $result = $result && $dbman->create_table($table1); $table2 = new xmldb_table('facetoface_session_data'); $table2->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table2->add_field('fieldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table2->add_field('sessionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table2->add_field('data', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $result = $result && $dbman->create_table($table2); } if ($result && $oldversion < 2009111900) { // Remove unused field. $table = new xmldb_table('facetoface_sessions'); $field = new xmldb_field('closed'); $result = $result && $dbman->drop_field($table, $field); } // Migration of old Location, Venue and Room fields. if ($result && $oldversion < 2009112300) { // Create three new custom fields. $newfield1 = new stdClass(); $newfield1->name = 'Location'; $newfield1->shortname = 'location'; $newfield1->type = 0; // Free text. $newfield1->required = 1; if (!($locationfieldid = $DB->insert_record('facetoface_session_field', $newfield1))) { $result = false; } $newfield2 = new stdClass(); $newfield2->name = 'Venue'; $newfield2->shortname = 'venue'; $newfield2->type = 0; // Free text. $newfield2->required = 1; if (!($venuefieldid = $DB->insert_record('facetoface_session_field', $newfield2))) { $result = false; } $newfield3 = new stdClass(); $newfield3->name = 'Room'; $newfield3->shortname = 'room'; $newfield3->type = 0; // Free text. $newfield3->required = 1; $newfield3->showinsummary = 0; if (!($roomfieldid = $DB->insert_record('facetoface_session_field', $newfield3))) { $result = false; } // Migrate data into the new fields. $olddebug = $DB->debug; $DB->debug = false; // Too much debug output. if ($rs = $DB->get_recordset('facetoface_sessions', array(), '', 'id, location, venue, room')) { foreach ($rs as $session) { $locationdata = new stdClass(); $locationdata->sessionid = $session->id; $locationdata->fieldid = $locationfieldid; $locationdata->data = $session->location; $result = $result && $DB->insert_record('facetoface_session_data', $locationdata); $venuedata = new stdClass(); $venuedata->sessionid = $session->id; $venuedata->fieldid = $venuefieldid; $venuedata->data = $session->venue; $result = $result && $DB->insert_record('facetoface_session_data', $venuedata); $roomdata = new stdClass(); $roomdata->sessionid = $session->id; $roomdata->fieldid = $roomfieldid; $roomdata->data = $session->room; $result = $result && $DB->insert_record('facetoface_session_data', $roomdata); } $rs->close(); } $DB->debug = $olddebug; // Drop the old fields. $table = new xmldb_table('facetoface_sessions'); $oldfield1 = new xmldb_field('location'); $result = $result && $dbman->drop_field($table, $oldfield1); $oldfield2 = new xmldb_field('venue'); $result = $result && $dbman->drop_field($table, $oldfield2); $oldfield3 = new xmldb_field('room'); $result = $result && $dbman->drop_field($table, $oldfield3); } // Migration of old Location, Venue and Room placeholders in email templates. if ($result && $oldversion < 2009112400) { $transaction = $DB->start_delegated_transaction(); $olddebug = $DB->debug; $DB->debug = false; // Too much debug output. $templatedfields = array('confirmationsubject', 'confirmationinstrmngr', 'confirmationmessage', 'cancellationsubject', 'cancellationinstrmngr', 'cancellationmessage', 'remindersubject', 'reminderinstrmngr', 'remindermessage', 'waitlistedsubject', 'waitlistedmessage'); if ($rs = $DB->get_recordset('facetoface', array(), '', 'id, ' . implode(', ', $templatedfields))) { foreach ($rs as $activity) { $todb = new stdClass(); $todb->id = $activity->id; foreach ($templatedfields as $fieldname) { $s = $activity->{$fieldname}; $s = str_replace('[location]', '[session:location]', $s); $s = str_replace('[venue]', '[session:venue]', $s); $s = str_replace('[room]', '[session:room]', $s); $todb->{$fieldname} = $s; } $result = $result && $DB->update_record('facetoface', $todb); } $rs->close(); } $DB->debug = $olddebug; $transaction->allow_commit(); } if ($result && $oldversion < 2009120900) { // Create Calendar events for all existing Face-to-face sessions. try { $transaction = $DB->start_delegated_transaction(); if ($records = $DB->get_records('facetoface_sessions', '', '', '', 'id, facetoface')) { // Remove all exising site-wide events (there shouldn't be any). foreach ($records as $record) { if (!facetoface_remove_session_from_calendar($record, SITEID)) { $result = false; throw new Exception('Could not remove session from site calendar'); break; } } // Add new site-wide events. foreach ($records as $record) { $session = facetoface_get_session($record->id); $facetoface = $DB->get_record('facetoface', 'id', $record->facetoface); if (!facetoface_add_session_to_calendar($session, $facetoface, 'site')) { $result = false; throw new Exception('Could not add session to site calendar'); break; } } } $transaction->allow_commit(); } catch (Exception $e) { $transaction->rollback($e); } } if ($result && $oldversion < 2009122901) { // Create table facetoface_session_roles. $table = new xmldb_table('facetoface_session_roles'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('sessionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('sessionid', XMLDB_KEY_FOREIGN, array('sessionid'), 'facetoface_sessions', array('id')); $result = $result && $dbman->create_table($table); // Create table facetoface_signups. $table = new xmldb_table('facetoface_signups'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('sessionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('mailedreminder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('discountcode', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('notificationtype', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('sessionid', XMLDB_KEY_FOREIGN, array('sessionid'), 'facetoface_sessions', array('id')); $result = $result && $dbman->create_table($table); // Create table facetoface_signups_status. $table = new xmldb_table('facetoface_signups_status'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('signupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('statuscode', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('superceded', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('createdby', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, '0'); $table->add_field('note', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('signupid', XMLDB_KEY_FOREIGN, array('signupid'), 'facetoface_signups', array('id')); $result = $result && $dbman->create_table($table); // Migrate submissions to signups. $table = new xmldb_table('facetoface_submissions'); if ($dbman->table_exists($table)) { require_once $CFG->dirroot . '/mod/facetoface/lib.php'; $transaction = $DB->start_delegated_transaction(); // Get all submissions and loop through. $rs = $DB->get_recordset('facetoface_submissions'); foreach ($rs as $submission) { // Insert signup. $signup = new stdClass(); $signup->sessionid = $submission->sessionid; $signup->userid = $submission->userid; $signup->mailedreminder = $submission->mailedreminder; $signup->discountcode = $submission->discountcode; $signup->notificationtype = $submission->notificationtype; $id = $DB->insert_record('facetoface_signups', $signup); $signup->id = $id; // Check facetoface still exists (some of them are missing). // Also, we need the course id so we can load the grade. $facetoface = $DB->get_record('facetoface', 'id', $submission->facetoface); if (!$facetoface) { // If facetoface delete, ignore as it's of no use to us now. mtrace('Could not find facetoface instance ' . $submission->facetoface); continue; } // Get grade. $grade = facetoface_get_grade($submission->userid, $facetoface->course, $facetoface->id); // Create initial "booked" signup status. $status = new stdClass(); $status->signupid = $signup->id; $status->statuscode = MDL_F2F_STATUS_BOOKED; $status->superceded = $grade->grade > 0 || $submission->timecancelled ? 1 : 0; $status->createdby = $USER->id; $status->timecreated = $submission->timecreated; $status->mailed = 0; $DB->insert_record('facetoface_signups_status', $status); // Create attended signup status. if ($grade->grade > 0) { $status->statuscode = MDL_F2F_STATUS_FULLY_ATTENDED; $status->grade = $grade->grade; $status->timecreated = $grade->dategraded; $status->superceded = $submission->timecancelled ? 1 : 0; $DB->insert_record('facetoface_signups_status', $status); } // If cancelled, create status. if ($submission->timecancelled) { $status->statuscode = MDL_F2F_STATUS_USER_CANCELLED; $status->timecreated = $submission->timecancelled; $status->superceded = 0; $DB->insert_record('facetoface_signups_status', $status); } } $rs->close(); $transaction->allow_commit(); // Drop table facetoface_submissions. $table = new xmldb_table('facetoface_submissions'); $result = $result && $dbman->drop_table($table); } // New field necessary for overbooking. $table = new xmldb_table('facetoface_sessions'); $field1 = new xmldb_field('allowoverbook'); $field1->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'capacity'); $result = $result && $dbman->add_field($table, $field1); } if ($result && $oldversion < 2010012000) { // New field for storing recommendations/advice. $table = new xmldb_table('facetoface_signups_status'); $field1 = new xmldb_field('advice'); $field1->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null); $result = $result && $dbman->add_field($table, $field1); } if ($result && $oldversion < 2010012001) { // New field for storing manager approval requirement. $table = new xmldb_table('facetoface'); $field = new xmldb_field('approvalreqd'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'showoncalendar'); $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2010012700) { // New fields for storing request emails. $table = new xmldb_table('facetoface'); $field = new xmldb_field('requestsubject'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'reminderperiod'); $result = $result && $dbman->add_field($table, $field); $field = new xmldb_field('requestinstrmngr'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'requestsubject'); $result = $result && $dbman->add_field($table, $field); $field = new xmldb_field('requestmessage'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'requestinstrmngr'); $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2010051000) { // Create Calendar events for all existing Face-to-face sessions. $transaction = $DB->start_delegated_transaction(); if ($records = $DB->get_records('facetoface_sessions', '', '', '', 'id, facetoface')) { // Remove all exising site-wide events (there shouldn't be any). foreach ($records as $record) { facetoface_remove_session_from_calendar($record, SITEID); } // Add new site-wide events. foreach ($records as $record) { $session = facetoface_get_session($record->id); $facetoface = $DB->get_record('facetoface', 'id', $record->facetoface); facetoface_add_session_to_calendar($session, $facetoface, 'site'); } } $transaction->allow_commit(); // Add tables required for site notices. $table1 = new xmldb_table('facetoface_notice'); $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table1->add_field('text', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $result = $result && $dbman->create_table($table1); $table2 = new xmldb_table('facetoface_notice_data'); $table2->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table2->add_field('fieldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table2->add_field('noticeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table2->add_field('data', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table2->add_index('facetoface_notice_date_fieldid', XMLDB_INDEX_NOTUNIQUE, array('fieldid')); $result = $result && $dbman->create_table($table2); } if ($result && $oldversion < 2010100400) { // Remove unused mailed field. $table = new xmldb_table('facetoface_signups_status'); $field = new xmldb_field('mailed'); if ($dbman->field_exists($table, $field)) { $result = $result && $dbman->drop_field($table, $field, false, true); } } // 2.0 upgrade line. if ($oldversion < 2011120701) { // Update existing select fields to use new seperator. $badrows = $DB->get_records_sql("\n SELECT\n *\n FROM\n {facetoface_session_field}\n WHERE\n possiblevalues LIKE '%;%'\n AND possiblevalues NOT LIKE '%" . CUSTOMFIELD_DELIMITER . "%'\n AND type IN (" . CUSTOMFIELD_TYPE_SELECT . "," . CUSTOMFIELD_TYPE_MULTISELECT . ")\n "); if ($badrows) { $transaction = $DB->start_delegated_transaction(); foreach ($badrows as $bad) { $fixedrow = new stdClass(); $fixedrow->id = $bad->id; $fixedrow->possiblevalues = str_replace(';', CUSTOMFIELD_DELIMITER, $bad->possiblevalues); $DB->update_record('facetoface_session_field', $fixedrow); } $transaction->allow_commit(); } $baddatarows = $DB->get_records_sql("\n SELECT\n sd.id, sd.data\n FROM\n {facetoface_session_field} sf\n JOIN\n {facetoface_session_data} sd\n ON\n sd.fieldid=sf.id\n WHERE\n sd.data LIKE '%;%'\n AND sd.data NOT LIKE '%" . CUSTOMFIELD_DELIMITER . "%'\n AND sf.type = " . CUSTOMFIELD_TYPE_MULTISELECT); if ($baddatarows) { $transaction = $DB->start_delegated_transaction(); foreach ($baddatarows as $bad) { $fixedrow = new stdClass(); $fixedrow->id = $bad->id; $fixedrow->data = str_replace(';', CUSTOMFIELD_DELIMITER, $bad->data); $DB->update_record('facetoface_session_data', $fixedrow); } $transaction->allow_commit(); } upgrade_mod_savepoint(true, 2011120701, 'facetoface'); } if ($oldversion < 2011120702) { $table = new xmldb_table('facetoface_session_field'); $index = new xmldb_index('ind_session_field_unique'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('shortname')); if ($dbman->table_exists($table)) { // Do we need to check for duplicates? if (!$dbman->index_exists($table, $index)) { // Check for duplicate records and make them unique. $replacements = array(); $transaction = $DB->start_delegated_transaction(); $sql = 'SELECT l.id, l.shortname FROM {facetoface_session_field} l, ( SELECT MIN(id) AS id, shortname FROM {facetoface_session_field} GROUP BY shortname HAVING COUNT(*)>1 ) a WHERE l.id<>a.id AND l.shortname = a.shortname '; $rs = $DB->get_recordset_sql($sql, null); if ($rs !== false) { foreach ($rs as $item) { $data = (object) $item; // Randomize the value. $data->shortname = $DB->escape($data->shortname . '_' . $data->id); $DB->update_record('facetoface_session_field', $data); $replacements[] = array($item['id'], $item['shortname'], $data->shortname); } } $transaction->allow_commit(); facetoface_send_admin_upgrade_msg($replacements); // Apply the index. $dbman->add_index($table, $index); } } upgrade_mod_savepoint(true, 2011120702, 'facetoface'); } if ($oldversion < 2011120703) { $table = new xmldb_table('facetoface'); $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'name'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Add the introformat field. $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'intro'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('description'); if ($dbman->field_exists($table, $field)) { // Move all data from description to intro. $facetofaces = $DB->get_records('facetoface'); foreach ($facetofaces as $facetoface) { $facetoface->intro = $facetoface->description; $facetoface->introformat = FORMAT_HTML; $DB->update_record('facetoface', $facetoface); } // Remove the old description field. $dbman->drop_field($table, $field); } // Facetoface savepoint reached. upgrade_mod_savepoint(true, 2011120703, 'facetoface'); } if ($oldversion < 2013010400) { // Add a field for the user calendar entry checkbox. $table = new xmldb_table('facetoface'); $field = new xmldb_field('usercalentry'); $field->set_attributes(XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 1); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Update the existing showoncalendar field, change true to F2F_CAL_SITE. $sql = 'UPDATE {facetoface} SET showoncalendar = ? WHERE showoncalendar = ?'; $DB->execute($sql, array(F2F_CAL_SITE, F2F_CAL_COURSE)); $f2f = $DB->get_records('facetoface'); foreach ($f2f as $facetoface) { facetoface_update_instance($facetoface, false); } upgrade_mod_savepoint(true, 2013010400, 'facetoface'); } return $result; }
/** * Quiz module upgrade function. * @param string $oldversion the version we are upgrading from. */ function xmldb_quiz_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($oldversion < 2008062000) { // Define table quiz_report to be created $table = new xmldb_table('quiz_report'); // Adding fields to table quiz_report $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); // Adding keys to table quiz_report $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for quiz_report if (!$dbman->table_exists($table)) { $dbman->create_table($table); } upgrade_mod_savepoint(true, 2008062000, 'quiz'); } if ($oldversion < 2008062001) { $reporttoinsert = new stdClass(); $reporttoinsert->name = 'overview'; $reporttoinsert->displayorder = 10000; $DB->insert_record('quiz_report', $reporttoinsert); $reporttoinsert = new stdClass(); $reporttoinsert->name = 'responses'; $reporttoinsert->displayorder = 9000; $DB->insert_record('quiz_report', $reporttoinsert); $reporttoinsert = new stdClass(); $reporttoinsert->name = 'regrade'; $reporttoinsert->displayorder = 7000; $DB->insert_record('quiz_report', $reporttoinsert); $reporttoinsert = new stdClass(); $reporttoinsert->name = 'grading'; $reporttoinsert->displayorder = 6000; $DB->insert_record('quiz_report', $reporttoinsert); upgrade_mod_savepoint(true, 2008062001, 'quiz'); } if ($oldversion < 2008072402) { // Define field lastcron to be added to quiz_report $table = new xmldb_table('quiz_report'); $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'displayorder'); // Conditionally launch add field lastcron if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field cron to be added to quiz_report $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lastcron'); // Conditionally launch add field cron if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2008072402, 'quiz'); } if ($oldversion < 2008072900) { // Delete the regrade report - it is now part of the overview report. $DB->delete_records('quiz_report', array('name' => 'regrade')); // quiz savepoint reached upgrade_mod_savepoint(true, 2008072900, 'quiz'); } if ($oldversion < 2008081500) { // Define table quiz_question_versions to be dropped $table = new xmldb_table('quiz_question_versions'); // Launch drop table for quiz_question_versions $dbman->drop_table($table); // quiz savepoint reached upgrade_mod_savepoint(true, 2008081500, 'quiz'); } // Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar. if ($oldversion < 2008081501) { // First set all quiz.sumgrades to 0 if they are null. This should never // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL'); $table = new xmldb_table('quiz'); $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'questions'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081501, 'quiz'); } if ($oldversion < 2008081502) { $table = new xmldb_table('quiz'); $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'sumgrades'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081502, 'quiz'); } if ($oldversion < 2008081503) { // First set all quiz.sumgrades to 0 if they are null. This should never // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL'); $table = new xmldb_table('quiz_attempts'); $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'attempt'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081503, 'quiz'); } if ($oldversion < 2008081504) { $table = new xmldb_table('quiz_feedback'); $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'feedbacktext'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081504, 'quiz'); } if ($oldversion < 2008081505) { $table = new xmldb_table('quiz_feedback'); $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'mingrade'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081505, 'quiz'); } if ($oldversion < 2008081506) { $table = new xmldb_table('quiz_grades'); $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'userid'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081506, 'quiz'); } if ($oldversion < 2008081507) { $table = new xmldb_table('quiz_question_instances'); $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2008081507, 'quiz'); } // Move all of the quiz config settings from $CFG to the config_plugins table. if ($oldversion < 2008082200) { foreach (get_object_vars($CFG) as $name => $value) { if (strpos($name, 'quiz_') === 0) { $shortname = substr($name, 5); if ($shortname == 'fix_adaptive') { // Special case - remove old inconsistency. $shortname == 'fix_optionflags'; } set_config($shortname, $value, 'quiz'); unset_config($name); } } upgrade_mod_savepoint(true, 2008082200, 'quiz'); } // Now that the quiz is no longer responsible for creating all the question // bank tables, and some of the tables are now the responsibility of the // datasetdependent question type, which did not have a version.php file before, // we need to say that these tables are already installed, otherwise XMLDB // will try to create them again and give an error. if ($oldversion < 2008082600) { // Since MDL-16505 was fixed, and we eliminated the datasetdependent // question type, this is now a no-op. upgrade_mod_savepoint(true, 2008082600, 'quiz'); } if ($oldversion < 2008112101) { // Define field lastcron to be added to quiz_report $table = new xmldb_table('quiz_report'); $field = new xmldb_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'cron'); // Conditionally launch add field lastcron if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2008112101, 'quiz'); } if ($oldversion < 2009010700) { // Define field showuserpicture to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('showuserpicture', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'delay2'); // Conditionally launch add field showuserpicture if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2009010700, 'quiz'); } if ($oldversion < 2009030900) { // If there are no quiz settings set to advanced yet, the set up the default // advanced fields from Moodle 2.0. $quizconfig = get_config('quiz'); $arealreadyadvanced = false; foreach (array($quizconfig) as $name => $value) { if (strpos($name, 'fix_') === 0 && !empty($value)) { $arealreadyadvanced = true; break; } } if (!$arealreadyadvanced) { set_config('fix_penaltyscheme', 1, 'quiz'); set_config('fix_attemptonlast', 1, 'quiz'); set_config('fix_questiondecimalpoints', 1, 'quiz'); set_config('fix_password', 1, 'quiz'); set_config('fix_subnet', 1, 'quiz'); set_config('fix_delay1', 1, 'quiz'); set_config('fix_delay2', 1, 'quiz'); set_config('fix_popup', 1, 'quiz'); } // quiz savepoint reached upgrade_mod_savepoint(true, 2009030900, 'quiz'); } if ($oldversion < 2009031000) { // Add new questiondecimaldigits setting, separate form the overall decimaldigits one. $table = new xmldb_table('quiz'); $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '-2', 'decimalpoints'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2009031000, 'quiz'); } if ($oldversion < 2009031001) { // Convert quiz.timelimit from minutes to seconds. $DB->execute('UPDATE {quiz} SET timelimit = timelimit * 60'); $default = get_config('quiz', 'timelimit'); set_config('timelimit', 60 * $default, 'quiz'); // quiz savepoint reached upgrade_mod_savepoint(true, 2009031001, 'quiz'); } if ($oldversion < 2009042000) { // Define field introformat to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('quiz', array('introformat' => FORMAT_MOODLE), '', 'id, intro, introformat'); foreach ($rs as $q) { $q->intro = text_to_html($q->intro, false, false, true); $q->introformat = FORMAT_HTML; $DB->update_record('quiz', $q); upgrade_set_timeout(); } $rs->close(); } // quiz savepoint reached upgrade_mod_savepoint(true, 2009042000, 'quiz'); } if ($oldversion < 2010030501) { // Define table quiz_overrides to be created $table = new xmldb_table('quiz_overrides'); // Adding fields to table quiz_overrides $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('quiz', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timelimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('attempts', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, null, null, null); $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null); // Adding keys to table quiz_overrides $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('quiz', XMLDB_KEY_FOREIGN, array('quiz'), 'quiz', array('id')); $table->add_key('groupid', XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); // Conditionally launch create table for quiz_overrides if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // quiz savepoint reached upgrade_mod_savepoint(true, 2010030501, 'quiz'); } if ($oldversion < 2010051800) { // Define field showblocks to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showuserpicture'); // Conditionally launch add field showblocks if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2010051800, 'quiz'); } if ($oldversion < 2010080600) { // Define field feedbacktextformat to be added to quiz_feedback $table = new xmldb_table('quiz_feedback'); $field = new xmldb_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'feedbacktext'); // Conditionally launch add field feedbacktextformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // This column defaults to FORMAT_MOODLE, which is correct. // quiz savepoint reached upgrade_mod_savepoint(true, 2010080600, 'quiz'); } if ($oldversion < 2010102000) { // Define field showblocks to be added to quiz // Repeat this step, because the column was missing from install.xml for a time. $table = new xmldb_table('quiz'); $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showuserpicture'); // Conditionally launch add field showblocks if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2010102000, 'quiz'); } if ($oldversion < 2010122300) { // Fix quiz in the post table after upgrade from 1.9 $table = new xmldb_table('quiz'); $columns = $DB->get_columns('quiz'); // quiz.questiondecimalpoints should be int (4) not null default -2 if (array_key_exists('questiondecimalpoints', $columns) && $columns['questiondecimalpoints']->default_value != '-2') { $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, -2, 'decimalpoints'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } // quiz.sumgrades should be decimal(10, 5) not null default 0 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) { // First set all quiz.sumgrades to 0 if they are null. This should never // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL'); $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'questions'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } // quiz.grade should be decimal(10, 5) not null default 0 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) { $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'sumgrades'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_mod_savepoint(true, 2010122300, 'quiz'); } if ($oldversion < 2010122301) { // Fix quiz_attempts in the post table after upgrade from 1.9 $table = new xmldb_table('quiz_attempts'); $columns = $DB->get_columns('quiz_attempts'); // quiz_attempts.sumgrades should be decimal(10, 5) not null default 0 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) { // First set all quiz.sumgrades to 0 if they are null. This should never // happen however some users have encountered a null value there. $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL'); $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'attempt'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_mod_savepoint(true, 2010122301, 'quiz'); } if ($oldversion < 2010122302) { // Fix quiz_feedback in the post table after upgrade from 1.9 $table = new xmldb_table('quiz_feedback'); $columns = $DB->get_columns('quiz_feedback'); // quiz_feedback.mingrade should be decimal(10, 5) not null default 0 if (array_key_exists('mingrade', $columns) && empty($columns['mingrade']->not_null)) { $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'feedbacktextformat'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } // quiz_feedback.maxgrade should be decimal(10, 5) not null default 0 if (array_key_exists('maxgrade', $columns) && empty($columns['maxgrade']->not_null)) { // Fixed in earlier upgrade code $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'mingrade'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_mod_savepoint(true, 2010122302, 'quiz'); } if ($oldversion < 2010122303) { // Fix quiz_grades in the post table after upgrade from 1.9 $table = new xmldb_table('quiz_grades'); $columns = $DB->get_columns('quiz_grades'); // quiz_grades.grade should be decimal(10, 5) not null default 0 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) { $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'userid'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_mod_savepoint(true, 2010122303, 'quiz'); } if ($oldversion < 2010122304) { // Fix quiz_question_instances in the post table after upgrade from 1.9 $table = new xmldb_table('quiz_question_instances'); $columns = $DB->get_columns('quiz_question_instances'); // quiz_question_instances.grade should be decimal(12, 7) not null default 0 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) { $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_mod_savepoint(true, 2010122304, 'quiz'); } //===== 2.1.0 upgrade line ======// // Complete any old upgrade from 1.5 that was never finished. if ($oldversion < 2011051199) { $table = new xmldb_table('question_states'); if ($dbman->table_exists($table)) { $transaction = $DB->start_delegated_transaction(); $oldattempts = $DB->get_records_sql(' SELECT * FROM {quiz_attempts} quiza WHERE uniqueid IN ( SELECT DISTINCT qst.attempt FROM {question_states} qst LEFT JOIN {question_sessions} qsess ON qst.question = qsess.questionid AND qst.attempt = qsess.attemptid WHERE qsess.id IS NULL ) '); if ($oldattempts) { require_once($CFG->dirroot . '/mod/quiz/db/upgradelib.php'); $pbar = new progress_bar('q15upgrade'); $pbar->create(); $a = new stdClass(); $a->outof = count($oldattempts); $a->done = 0; $pbar->update($a->done, $a->outof, get_string('upgradingveryoldquizattempts', 'quiz', $a)); foreach ($oldattempts as $oldattempt) { quiz_upgrade_very_old_question_sessions($oldattempt); $a->done += 1; $pbar->update($a->done, $a->outof, get_string('upgradingveryoldquizattempts', 'quiz', $a)); } } $transaction->allow_commit(); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051199, 'quiz'); } // Add new preferredbehaviour column to the quiz table. if ($oldversion < 2011051200) { $table = new xmldb_table('quiz'); $field = new xmldb_field('preferredbehaviour'); $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, 'timeclose'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051200, 'quiz'); } // Populate preferredbehaviour column based on old optionflags column. if ($oldversion < 2011051201) { if ($dbman->field_exists('quiz', 'optionflags')) { $DB->set_field_select('quiz', 'preferredbehaviour', 'deferredfeedback', 'optionflags = 0'); $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptive', 'optionflags <> 0 AND penaltyscheme <> 0'); $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptivenopenalty', 'optionflags <> 0 AND penaltyscheme = 0'); set_config('preferredbehaviour', 'deferredfeedback', 'quiz'); set_config('fix_preferredbehaviour', 0, 'quiz'); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051201, 'quiz'); } // Add a not-NULL constraint to the preferredmodel field now that it is populated. if ($oldversion < 2011051202) { $table = new xmldb_table('quiz'); $field = new xmldb_field('preferredbehaviour'); $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'timeclose'); $dbman->change_field_notnull($table, $field); // quiz savepoint reached upgrade_mod_savepoint(true, 2011051202, 'quiz'); } // Drop the old optionflags field. if ($oldversion < 2011051203) { $table = new xmldb_table('quiz'); $field = new xmldb_field('optionflags'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } unset_config('optionflags', 'quiz'); unset_config('fix_optionflags', 'quiz'); // quiz savepoint reached upgrade_mod_savepoint(true, 2011051203, 'quiz'); } // Drop the old penaltyscheme field. if ($oldversion < 2011051204) { $table = new xmldb_table('quiz'); $field = new xmldb_field('penaltyscheme'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } unset_config('penaltyscheme', 'quiz'); unset_config('fix_penaltyscheme', 'quiz'); // quiz savepoint reached upgrade_mod_savepoint(true, 2011051204, 'quiz'); } if ($oldversion < 2011051205) { // Changing nullability of field sumgrades on table quiz_attempts to null $table = new xmldb_table('quiz_attempts'); $field = new xmldb_field('sumgrades'); $field->set_attributes(XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'attempt'); // Launch change of nullability for field sumgrades $dbman->change_field_notnull($table, $field); // Launch change of default for field sumgrades $dbman->change_field_default($table, $field); // quiz savepoint reached upgrade_mod_savepoint(true, 2011051205, 'quiz'); } if ($oldversion < 2011051207) { // Define field reviewattempt to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('reviewattempt'); $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'review'); // Launch add field reviewattempt if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051207, 'quiz'); } if ($oldversion < 2011051208) { // Define field reviewattempt to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('reviewcorrectness'); $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewattempt'); // Launch add field reviewattempt if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051208, 'quiz'); } if ($oldversion < 2011051209) { // Define field reviewattempt to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('reviewmarks'); $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewcorrectness'); // Launch add field reviewattempt if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051209, 'quiz'); } if ($oldversion < 2011051210) { // Define field reviewattempt to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('reviewspecificfeedback'); $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewmarks'); // Launch add field reviewattempt if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051210, 'quiz'); } if ($oldversion < 2011051211) { // Define field reviewattempt to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('reviewgeneralfeedback'); $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewspecificfeedback'); // Launch add field reviewattempt if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051211, 'quiz'); } if ($oldversion < 2011051212) { // Define field reviewattempt to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('reviewrightanswer'); $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewgeneralfeedback'); // Launch add field reviewattempt if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051212, 'quiz'); } if ($oldversion < 2011051213) { // Define field reviewattempt to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('reviewoverallfeedback'); $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewrightanswer'); // Launch add field reviewattempt if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051213, 'quiz'); } define('QUIZ_NEW_DURING', 0x10000); define('QUIZ_NEW_IMMEDIATELY_AFTER', 0x01000); define('QUIZ_NEW_LATER_WHILE_OPEN', 0x00100); define('QUIZ_NEW_AFTER_CLOSE', 0x00010); define('QUIZ_OLD_IMMEDIATELY', 0x3c003f); define('QUIZ_OLD_OPEN', 0x3c00fc0); define('QUIZ_OLD_CLOSED', 0x3c03f000); define('QUIZ_OLD_RESPONSES', 1*0x1041); // Show responses define('QUIZ_OLD_SCORES', 2*0x1041); // Show scores define('QUIZ_OLD_FEEDBACK', 4*0x1041); // Show question feedback define('QUIZ_OLD_ANSWERS', 8*0x1041); // Show correct answers define('QUIZ_OLD_SOLUTIONS', 16*0x1041); // Show solutions define('QUIZ_OLD_GENERALFEEDBACK', 32*0x1041); // Show question general feedback define('QUIZ_OLD_OVERALLFEEDBACK', 1*0x4440000); // Show quiz overall feedback // Copy the old review settings if ($oldversion < 2011051214) { if ($dbman->field_exists('quiz', 'review')) { $DB->execute(" UPDATE {quiz} SET reviewattempt = " . $DB->sql_bitor($DB->sql_bitor( QUIZ_NEW_DURING, 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES) . ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES) . ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES) . ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " "); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051214, 'quiz'); } if ($oldversion < 2011051215) { if ($dbman->field_exists('quiz', 'review')) { $DB->execute(" UPDATE {quiz} SET reviewcorrectness = " . $DB->sql_bitor($DB->sql_bitor( QUIZ_NEW_DURING, 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) . ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) . ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) . ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " "); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051215, 'quiz'); } if ($oldversion < 2011051216) { if ($dbman->field_exists('quiz', 'review')) { $DB->execute(" UPDATE {quiz} SET reviewmarks = " . $DB->sql_bitor($DB->sql_bitor( QUIZ_NEW_DURING, 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) . ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) . ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) . ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " "); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051216, 'quiz'); } if ($oldversion < 2011051217) { if ($dbman->field_exists('quiz', 'review')) { $DB->execute(" UPDATE {quiz} SET reviewspecificfeedback = " . $DB->sql_bitor($DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " "); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051217, 'quiz'); } if ($oldversion < 2011051218) { if ($dbman->field_exists('quiz', 'review')) { $DB->execute(" UPDATE {quiz} SET reviewgeneralfeedback = " . $DB->sql_bitor($DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " "); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051218, 'quiz'); } if ($oldversion < 2011051219) { if ($dbman->field_exists('quiz', 'review')) { $DB->execute(" UPDATE {quiz} SET reviewrightanswer = " . $DB->sql_bitor($DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) . ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) . ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS) . ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS) . ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " "); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051219, 'quiz'); } if ($oldversion < 2011051220) { if ($dbman->field_exists('quiz', 'review')) { $DB->execute(" UPDATE {quiz} SET reviewoverallfeedback = " . $DB->sql_bitor($DB->sql_bitor( 0, 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK) . ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " "); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051220, 'quiz'); } // And, do the same for the defaults if ($oldversion < 2011051221) { $quizrevew = get_config('quiz', 'review'); if (!empty($quizrevew)) { set_config('reviewattempt', QUIZ_NEW_DURING | ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES ? QUIZ_NEW_AFTER_CLOSE : 0), 'quiz'); set_config('reviewcorrectness', QUIZ_NEW_DURING | ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0), 'quiz'); set_config('reviewmarks', QUIZ_NEW_DURING | ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0), 'quiz'); set_config('reviewspecificfeedback', ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_DURING : 0) | ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), 'quiz'); set_config('reviewgeneralfeedback', ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_DURING : 0) | ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), 'quiz'); set_config('reviewrightanswer', ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_DURING : 0) | ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS ? QUIZ_NEW_AFTER_CLOSE : 0), 'quiz'); set_config('reviewoverallfeedback', 0 | ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), 'quiz'); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051221, 'quiz'); } // Finally drop the old column if ($oldversion < 2011051222) { // Define field review to be dropped from quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('review'); // Launch drop field review if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051222, 'quiz'); } if ($oldversion < 2011051223) { unset_config('review', 'quiz'); // quiz savepoint reached upgrade_mod_savepoint(true, 2011051223, 'quiz'); } if ($oldversion < 2011051225) { // Define table quiz_report to be renamed to quiz_reports $table = new xmldb_table('quiz_report'); // Launch rename table for quiz_reports if ($dbman->table_exists($table)) { $dbman->rename_table($table, 'quiz_reports'); } upgrade_mod_savepoint(true, 2011051225, 'quiz'); } if ($oldversion < 2011051226) { // Define index name (unique) to be added to quiz_reports $table = new xmldb_table('quiz_reports'); $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); // Conditionally launch add index name if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } upgrade_mod_savepoint(true, 2011051226, 'quiz'); } if ($oldversion < 2011051227) { // Changing nullability of field sumgrades on table quiz_attempts to null $table = new xmldb_table('quiz_attempts'); $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'attempt'); // Launch change of nullability for field sumgrades $dbman->change_field_notnull($table, $field); // quiz savepoint reached upgrade_mod_savepoint(true, 2011051227, 'quiz'); } if ($oldversion < 2011051228) { // Define field needsupgradetonewqe to be added to quiz_attempts $table = new xmldb_table('quiz_attempts'); $field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'preview'); // Launch add field needsupgradetonewqe if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $DB->set_field('quiz_attempts', 'needsupgradetonewqe', 1); // quiz savepoint reached upgrade_mod_savepoint(true, 2011051228, 'quiz'); } if ($oldversion < 2011051229) { $table = new xmldb_table('question_states'); if ($dbman->table_exists($table)) { // First delete all data from preview attempts. $DB->delete_records_select('question_states', "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); $DB->delete_records_select('question_sessions', "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); $DB->delete_records('quiz_attempts', array('preview' => 1)); // Now update all the old attempt data. $oldrcachesetting = $CFG->rcache; $CFG->rcache = false; require_once($CFG->dirroot . '/question/engine/upgrade/upgradelib.php'); $upgrader = new question_engine_attempt_upgrader(); $upgrader->convert_all_quiz_attempts(); $CFG->rcache = $oldrcachesetting; } // quiz savepoint reached upgrade_mod_savepoint(true, 2011051229, 'quiz'); } // Moodle v2.1.0 release upgrade line // Put any upgrade step following this if ($oldversion < 2011100600) { // Define field browsersecurity to be added to quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('browsersecurity', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, '[unknownvalue]', 'subnet'); // Conditionally launch add field browsersecurity if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011100600, 'quiz'); } if ($oldversion < 2011100601) { $DB->set_field('quiz', 'browsersecurity', '-', array('popup' => 0)); $DB->set_field('quiz', 'browsersecurity', 'securewindow', array('popup' => 1)); $DB->set_field('quiz', 'browsersecurity', 'safebrowser', array('popup' => 2)); upgrade_mod_savepoint(true, 2011100601, 'quiz'); } if ($oldversion < 2011100602) { // Changing the default of field browsersecurity on table quiz to drop it $table = new xmldb_table('quiz'); $field = new xmldb_field('browsersecurity', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'subnet'); // Launch change of default for field browsersecurity $dbman->change_field_default($table, $field); // quiz savepoint reached upgrade_mod_savepoint(true, 2011100602, 'quiz'); } if ($oldversion < 2011100603) { // Define field popup to be dropped from quiz $table = new xmldb_table('quiz'); $field = new xmldb_field('popup'); // Conditionally launch drop field popup if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // quiz savepoint reached upgrade_mod_savepoint(true, 2011100603, 'quiz'); } if ($oldversion < 2011100604) { switch (get_config('quiz', 'popup')) { case 1: set_config('browsersecurity', 'securewindow', 'quiz'); break; case 2: set_config('browsersecurity', 'safebrowser', 'quiz'); break; default: set_config('browsersecurity', '-', 'quiz'); } unset_config('quiz', 'popup'); set_config('browsersecurity_adv', get_config('quiz', 'popup_adv'), 'quiz'); unset_config('quiz', 'popup_adv'); upgrade_mod_savepoint(true, 2011100604, 'quiz'); } // Moodle v2.2.0 release upgrade line // Put any upgrade step following this return true; }
function xmldb_ouwiki_upgrade($oldversion = 0) { global $CFG, $DB; $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. if ($oldversion < 2008100600) { // Define field deletedat to be added to ouwiki_versions. $table = new xmldb_table('ouwiki_versions'); $field = new xmldb_field('deletedat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'changeprevsize'); // Launch add field deletedat (provided field does not already exist). if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2008100600, 'ouwiki'); } if ($oldversion < 2009120801) { // Launch create table for ouwiki_annotations - if it does not already exist (extra precaution). $table = new xmldb_table('ouwiki_annotations'); if (!$dbman->table_exists($table)) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/mod/ouwiki/db/install.xml', 'ouwiki_annotations'); } // Define field locked to be added to ouwiki_pages. $table = new xmldb_table('ouwiki_pages'); $field = new xmldb_field('locked'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 0, 'currentversionid'); // Launch add field locked - if it does not already exist (extra precaution). if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2009120801, 'ouwiki'); } if ($oldversion < 2010022300) { // Define field locked to be added to ouwiki_pages. $table = new xmldb_table('ouwiki'); $field = new xmldb_field('commenting'); $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, null, null, 'default', 'completionedits'); // Launch add field locked - if it does not already exist (extra precaution). if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2010022300, 'ouwiki'); } if ($oldversion < 2010122001) { // Drop the old comments table $table = new xmldb_table('ouwiki_comments'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } // Drop the old commenting field in ouwiki $table2 = new xmldb_table('ouwiki'); $field = new xmldb_field('commenting'); if ($dbman->field_exists($table2, $field)) { // We need to know about any wikis which are currently // using annotation or both systems before the upgrade // we need these before we drop the commenting field $rs = $DB->get_records_sql("SELECT DISTINCT w.id " . "FROM {ouwiki} w " . "WHERE w.commenting = 'annotations' OR w.commenting = 'both'"); $dbman->drop_field($table2, $field); } // Define field annotation to be added to ouwiki $field2 = new xmldb_field('annotation'); $field2->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'completionedits'); if (!$dbman->field_exists($table2, $field2)) { $dbman->add_field($table2, $field2); } // update the existing wikis to have annotation turned on // where they did before or had the BOTH commenting option if (!empty($rs)) { $ids = array_keys($rs); list($usql, $params) = $DB->get_in_or_equal($ids); $update_sql = 'UPDATE {ouwiki} SET annotation = 1 WHERE id ' . $usql; $DB->execute($update_sql, $params); } // retrieve new summary field $field3 = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'template'); // Launch rename field summary if ($dbman->field_exists($table2, $field3)) { $dbman->rename_field($table2, $field3, 'intro'); } // Define field introformat to be added to ouwiki $field4 = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'annotation'); // Launch add field introformat if (!$dbman->field_exists($table2, $field4)) { $dbman->add_field($table2, $field4); } // Define field introformat to be added to ouwiki $table3 = new xmldb_table('ouwiki_versions'); $field5 = new xmldb_field('xhtmlformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'deletedat'); // Launch add field introformat if (!$dbman->field_exists($table3, $field5)) { $dbman->add_field($table3, $field5); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { // introformat $rs = $DB->get_recordset('ouwiki', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $r) { $r->intro = text_to_html($r->intro, false, false, true); $r->introformat = FORMAT_HTML; $DB->update_record('ouwiki', $r); upgrade_set_timeout(); } $rs->close(); // xhtmlformat $rs = $DB->get_recordset('ouwiki_versions', array('xhtmlformat' => FORMAT_MOODLE), '', 'id,xhtml,xhtmlformat'); foreach ($rs as $r) { $r->xhtml = text_to_html($r->xhtml, false, false, true); $r->xhtmlformat = FORMAT_MOODLE; $DB->update_record('ouwiki_versions', $r); upgrade_set_timeout(); } $rs->close(); } upgrade_mod_savepoint(true, 2010122001, 'ouwiki'); } if ($oldversion < 2011031800) { upgrade_mod_savepoint(true, 2011031800, 'ouwiki'); } if ($oldversion < 2011060100) { // Define field enablewordcount to be added to ouwiki $table = new xmldb_table('ouwiki'); $field = new xmldb_field('enablewordcount', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'introformat'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field wordcount to be added to ouwiki_versions $table = new xmldb_table('ouwiki_versions'); $field = new xmldb_field('wordcount', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'xhtmlformat'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // we need to update all ouwiki_versions wordcounts $count = $DB->count_records_sql('SELECT COUNT(*) FROM {ouwiki_versions}'); $rs = $DB->get_recordset_sql('SELECT id, xhtml FROM {ouwiki_versions} ORDER BY id'); if ($rs->valid()) { $pbar = new progress_bar('countwordsouwikiversionsxhtml', 500, true); $i = 0; foreach ($rs as $entry) { $i++; upgrade_set_timeout(60); // set up timeout, may also abort execution $pbar->update($i, $count, "Counting words of ouwiki version entries - {$i}/{$count}."); // retrieve wordcount require_once $CFG->dirroot . '/mod/ouwiki/locallib.php'; $wordcount = ouwiki_count_words($entry->xhtml); $entry->wordcount = $wordcount; $DB->update_record('ouwiki_versions', $entry); } } $rs->close(); upgrade_mod_savepoint(true, 2011060100, 'ouwiki'); } if ($oldversion < 2011071300) { // Define field grade to be added to ouwiki $table = new xmldb_table('ouwiki'); $field = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'enablewordcount'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // we need to update all ouwiki_versions scales $rs = $DB->get_recordset_sql('SELECT id FROM {ouwiki} ORDER BY id'); if ($rs->valid()) { foreach ($rs as $entry) { $entry->grade = 0; $DB->update_record('ouwiki', $entry); } } $rs->close(); upgrade_mod_savepoint(true, 2011071300, 'ouwiki'); } if ($oldversion < 2011072000) { // Define field firstversionid to be added to ouwiki_pages $table = new xmldb_table('ouwiki_pages'); $field = new xmldb_field('firstversionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', 'locked'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field previousversionid to be added to ouwiki_versions $table = new xmldb_table('ouwiki_versions'); $field = new xmldb_field('previousversionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', 'wordcount'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // update all ouwiki_versions previousversionids and ouwiki_pages firstversionids // firstversionid $sql = 'SELECT v.pageid, (SELECT MIN(id) FROM {ouwiki_versions} v3 WHERE v3.pageid = p.id AND v3.deletedat IS NULL) AS firstversionid FROM {ouwiki_pages} p JOIN {ouwiki_versions} v ON v.pageid = p.id GROUP BY v.pageid, p.id ORDER BY v.pageid'; $rs = $DB->get_recordset_sql($sql); if ($rs->valid()) { foreach ($rs as $entry) { if (isset($entry->firstversionid)) { $DB->set_field('ouwiki_pages', 'firstversionid', $entry->firstversionid, array('id' => $entry->pageid)); } } } $rs->close(); // previousversionid $count = $DB->count_records_sql('SELECT COUNT(*) FROM {ouwiki_versions}'); $sql = 'SELECT v.id AS versionid, (SELECT MAX(v2.id) FROM {ouwiki_versions} v2 WHERE v2.pageid = p.id AND v2.id < v.id) AS previousversionid FROM {ouwiki_pages} p JOIN {ouwiki_versions} v ON v.pageid = p.id'; $rs = $DB->get_recordset_sql($sql); if ($rs->valid()) { $pbar = new progress_bar('ouwikifirstandpreviousversions', 500, true); $i = 0; foreach ($rs as $entry) { $i++; upgrade_set_timeout(60); // set up timeout, may also abort execution $pbar->update($i, $count, "Updating wiki metadata - {$i}/{$count}."); if (isset($entry->previousversionid)) { $DB->set_field('ouwiki_versions', 'previousversionid', $entry->previousversionid, array('id' => $entry->versionid)); } } } $rs->close(); upgrade_mod_savepoint(true, 2011072000, 'ouwiki'); } if ($oldversion < 2011102802) { // Delete any duplicate null values (these aren't caught by index) // Done in two stages in case mysql is a piece of ****. $rs = $DB->get_recordset_sql("\nSELECT\n p.id\nFROM\n {ouwiki_pages} p\n LEFT JOIN {ouwiki_pages} p2 ON p2.subwikiid = p.subwikiid AND p2.title IS NULL\n AND p.title IS NULL AND p2.id < p.id\nWHERE\n p2.id IS NOT NULL"); $ids = array(); foreach ($rs as $rec) { $ids[] = $rec->id; } $rs->close(); if ($ids) { list($sql, $params) = $DB->get_in_or_equal($ids); $DB->execute("DELETE FROM {ouwiki_pages} WHERE id {$sql}", $params); } // Set all the null values to blank $DB->execute("UPDATE {ouwiki_pages} SET title='' WHERE title IS NULL"); // Also in ousearch table if installed $table = new xmldb_table('local_ousearch_documents'); if ($dbman->table_exists($table)) { $DB->execute("UPDATE {local_ousearch_documents} SET stringref='' WHERE stringref IS NULL AND plugin='mod_ouwiki'"); } // Changing nullability of field title on table ouwiki_pages to not null $table = new xmldb_table('ouwiki_pages'); $field = new xmldb_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'subwikiid'); // Launch change of nullability for field title $dbman->change_field_notnull($table, $field); // Define index subwikiid-title (unique) to be added to ouwiki_pages $index = new xmldb_index('subwikiid-title', XMLDB_INDEX_UNIQUE, array('subwikiid', 'title')); // Conditionally launch add index subwikiid-title if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // ouwiki savepoint reached upgrade_mod_savepoint(true, 2011102802, 'ouwiki'); } if ($oldversion < 2013060600) { // Fix broken links due to annotations (current version unlocked page only). $likes = $DB->sql_like('l.tourl', '?'); $params = array('view.php%'); // Fix where relative has been turned into incorrect absolute. $likes .= ' or ' . $DB->sql_like('l.tourl', '?'); $params[] = "{$CFG->wwwroot}/view.php%"; // Only pickup links on pages where annotations have been used. $pagelike = $DB->sql_like('v.xhtml', '?'); $params[] = '<div class="ouwiki_content"%'; $params[] = 0; $sql = "select l.id as lid, l.tourl, v.id as vid, v.xhtml, p.id as pageid, p.subwikiid\n from {ouwiki_links} l\n inner join {ouwiki_versions} v on v.id = l.fromversionid\n inner join {ouwiki_pages} p on v.id = p.currentversionid\n where ({$likes})\n and {$pagelike} and p.locked = ?\n order by p.id"; $links = $DB->get_records_sql($sql, $params); $pagesprocessed = array(); $subwikipages = array(); foreach ($links as $linkdetails) { // For each link found fix content of page it belongs to (once per page). if (!in_array($linkdetails->pageid, $pagesprocessed)) { // Tidy up and revert converted content (links) back to original format. $pattern = '(<a\\b[^>]*?href="(' . preg_quote($CFG->wwwroot . '/') . ')?view\\.php[^"]*?page=([^"]*?)"[^>]*?>(.*?)<\\/a>)'; preg_match_all($pattern, $linkdetails->xhtml, $matches); $newxhtml = $linkdetails->xhtml; for ($i = 0; $i < count($matches[0]); $i++) { $tag = $matches[0][$i]; $page = urldecode($matches[2][$i]); $text = $matches[3][$i]; if (strip_tags($text) == $text) { // Only create 'proper' link where tag contents not formatted. $newxhtml = str_replace($tag, "[[{$page}]]", $newxhtml); } else { if (!empty($matches[1][$i])) { // Fix link if absolute to incorrect path. $newtag = str_replace("{$CFG->wwwroot}/view.php", "{$CFG->wwwroot}/mod/ouwiki/view.php", $tag); $newxhtml = str_replace($tag, $newtag, $newxhtml); } else { // Fix relative links to view.php as these break when page is edited. $newtag = str_replace('"view.php', "\"{$CFG->wwwroot}/mod/ouwiki/view.php", $tag); $newxhtml = str_replace($tag, $newtag, $newxhtml); } } } if ($newxhtml != $linkdetails->xhtml) { // Save updated page content. $update = new stdClass(); $update->id = $linkdetails->vid; $update->xhtml = $newxhtml; $DB->update_record('ouwiki_versions', $update); } $pagesprocessed[] = $linkdetails->pageid; // Don't process again. } // Attempt to turn tourl link into 'proper' wiki link so structure is correct. if (!isset($subwikipages[$linkdetails->subwikiid])) { // Store all pages from the subwiki (once) so we can find the relevant page. $subwikipages[$linkdetails->subwikiid] = $DB->get_records('ouwiki_pages', array('subwikiid' => $linkdetails->subwikiid), '', 'id,title'); } $pagetitle = ''; if ($pagechar = strpos($linkdetails->tourl, 'page=')) { // Get page title from url (always at end of url). $pagetitle = urldecode(substr($linkdetails->tourl, $pagechar + 5)); } $pageid = 0; // Find page title in sub wiki pages (includes start page match). if (!empty($subwikipages[$linkdetails->subwikiid])) { foreach ($subwikipages[$linkdetails->subwikiid] as $page) { if ($page->title === $pagetitle) { $pageid = $page->id; break; } } } // Update link record (will always tidy regardless). $update = new stdClass(); $update->id = $linkdetails->lid; $update->tourl = null; if ($pageid) { $update->topageid = $pageid; } else { $update->tomissingpage = strtoupper($pagetitle); } $DB->update_record('ouwiki_links', $update); } $links = null; $subwikipages = null; // ouwiki savepoint reached. upgrade_mod_savepoint(true, 2013060600, 'ouwiki'); } if ($oldversion < 2014012700) { // Define field allowimport to be added to ouwiki. $table = new xmldb_table('ouwiki'); $field = new xmldb_field('allowimport', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'grade'); // Conditionally launch add field allowimport. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field importversionid to be added to ouwiki_versions. $table = new xmldb_table('ouwiki_versions'); $field = new xmldb_field('importversionid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'previousversionid'); // Conditionally launch add field importversionid. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Ouwiki savepoint reached. upgrade_mod_savepoint(true, 2014012700, 'ouwiki'); } if ($oldversion < 2014031100) { // Define index ouwiki_subwikis_unique_group (unique) to be added to ouwiki_subwikis. $table = new xmldb_table('ouwiki_subwikis'); $index = new xmldb_index('ouwiki_subwikis_unique_group', XMLDB_INDEX_UNIQUE, array('wikiid', 'groupid')); // Conditionally launch add index ouwiki_subwikis_unique_group. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Define index ouwiki_subwikis_unique_user (unique) to be added to ouwiki_subwikis. $table = new xmldb_table('ouwiki_subwikis'); $index = new xmldb_index('ouwiki_subwikis_unique_user', XMLDB_INDEX_UNIQUE, array('wikiid', 'userid')); // Conditionally launch add index ouwiki_subwikis_unique_user. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Ouwiki savepoint reached. upgrade_mod_savepoint(true, 2014031100, 'ouwiki'); } // Must always return true from these functions return true; }
/** * @global moodle_database $DB * @param int $oldversion * @return bool */ function xmldb_scorm_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// // Adding missing 'whatgrade' field to table scorm if ($oldversion < 2008073000) { $table = new xmldb_table('scorm'); $field = new xmldb_field('whatgrade'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grademethod'); /// Launch add field whatgrade if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); $whatgradefixed = get_config('scorm', 'whatgradefixed'); if (empty($whatgradefixed)) { /// fix bad usage of whatgrade/grading method. $scorms = $DB->get_records('scorm'); foreach ($scorms as $scorm) { $scorm->whatgrade = $scorm->grademethod / 10; $DB->update_record('scorm', $scorm); } } } else { //dump this config var as it isn't needed anymore. unset_config('whatgradefixed', 'scorm'); } upgrade_mod_savepoint(true, 2008073000, 'scorm'); } if ($oldversion < 2008082500) { /// Define field scormtype to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('scormtype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, 'local', 'name'); /// Launch add field scormtype $dbman->add_field($table, $field); /// scorm savepoint reached upgrade_mod_savepoint(true, 2008082500, 'scorm'); } if ($oldversion < 2008090300) { /// Define field sha1hash to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('sha1hash', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'updatefreq'); /// Launch add field sha1hash $dbman->add_field($table, $field); /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090300, 'scorm'); } if ($oldversion < 2008090301) { /// Define field revision to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'md5hash'); /// Launch add field revision $dbman->add_field($table, $field); /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090301, 'scorm'); } if ($oldversion < 2008090302) { $sql = "UPDATE {scorm}\n SET scormtype = 'external'\n WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?"; $DB->execute($sql, array('http://%imsmanifest.xml', 'https://%imsmanifest.xml', 'www.%imsmanifest.xml')); $sql = "UPDATE {scorm}\n SET scormtype = 'localsync'\n WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?\n OR reference LIKE ? OR reference LIKE ? OR reference LIKE ?"; $DB->execute($sql, array('http://%.zip', 'https://%.zip', 'www.%.zip', 'http://%.pif', 'https://%.pif', 'www.%.pif')); $sql = "UPDATE {scorm} SET scormtype = 'imsrepository' WHERE reference LIKE ?"; $DB->execute($sql, array('#%')); /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090302, 'scorm'); } if ($oldversion < 2008090303) { //remove obsoleted config settings unset_config('scorm_advancedsettings'); unset_config('scorm_windowsettings'); /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090303, 'scorm'); } if ($oldversion < 2008090304) { ///////////////////////////////////// /// new file storage upgrade code /// ///////////////////////////////////// require_once "{$CFG->dirroot}/mod/scorm/db/upgradelib.php"; $fs = get_file_storage(); $sqlfrom = "FROM {scorm} s\n JOIN {modules} m ON m.name = 'scorm'\n JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = s.id)"; $count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}"); $rs = $DB->get_recordset_sql("SELECT s.id, s.scormtype, s.reference, s.course, cm.id AS cmid {$sqlfrom} ORDER BY s.course, s.id"); if ($rs->valid()) { $pbar = new progress_bar('migratescormfiles', 500, true); $i = 0; foreach ($rs as $scorm) { $i++; upgrade_set_timeout(180); // set up timeout, may also abort execution $pbar->update($i, $count, "Migrating scorm files - {$i}/{$count}."); $context = get_context_instance(CONTEXT_MODULE, $scorm->cmid); $coursecontext = get_context_instance(CONTEXT_COURSE, $scorm->course); if ($scorm->scormtype === 'local' and preg_match('/.*(\\.zip|\\.pif)$/i', $scorm->reference)) { // first copy local packages if found - do not delete in case they are shared ;-) $packagefile = clean_param($scorm->reference, PARAM_PATH); $pathnamehash = sha1("/{$coursecontext->id}/course/legacy/0/{$packagefile}"); if ($file = $fs->get_file_by_hash($pathnamehash)) { $file_record = array('contextid' => $context->id, 'component' => 'mod_scorm', 'filearea' => 'package', 'itemid' => 0, 'filepath' => '/'); try { $fs->create_file_from_storedfile($file_record, $file); } catch (Exception $x) { // ignore any errors, we can not do much anyway } $scorm->reference = $file->get_filepath() . $file->get_filename(); } else { $scorm->reference = ''; } $DB->update_record('scorm', $scorm); // the package should be already extracted, we need to move the files there // just in case somebody modified it directly there scorm_migrate_moddata_files($scorm, $context); } else { if ($scorm->scormtype === 'local' and preg_match('/.*\\/imsmanifest\\.xml$/i', $scorm->reference)) { // ignore imsmanifest in course root because we would be duplicating all course files which is not acceptable // moddata dir is not used at all, ignore any rubbish there $manifest = clean_param($scorm->reference, PARAM_PATH); $pathnamehash = sha1("/{$coursecontext->id}/course/legacy/0/{$manifest}"); if ($file = $fs->get_file_by_hash($pathnamehash)) { $scorm->reference = $file->get_filepath() . $file->get_filename(); $manifestdir = '/' . str_ireplace('/imsmanifest.xml', '', $manifest) . '/'; $pregmanifestdir = preg_quote($manifestdir, '/'); $file_record = array('contextid' => $context->id, 'component' => 'mod_scorm', 'filearea' => 'content', 'itemid' => 0); if ($files = $fs->get_directory_files($coursecontext->id, 'course', 'legacy', 0, $manifestdir, true)) { foreach ($files as $file) { $file_record['filepath'] = preg_replace("/^{$pregmanifestdir}/", '/', $file->get_filepath()); try { $fs->create_file_from_storedfile($file_record, $file); } catch (Exception $x) { // ignore any errors, we can not do much anyway } } } } else { $scorm->reference = ''; } $DB->update_record('scorm', $scorm); } else { // just try to migrate anything from moddata scorm_migrate_moddata_files($scorm, $context); } } // remove dirs if empty @rmdir("{$CFG->dataroot}/{$scorm->course}/{$CFG->moddata}/scorm/{$scorm->id}/"); @rmdir("{$CFG->dataroot}/{$scorm->course}/{$CFG->moddata}/scorm/"); @rmdir("{$CFG->dataroot}/{$scorm->course}/{$CFG->moddata}/"); } } $rs->close(); /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090304, 'scorm'); } if ($oldversion < 2008090305) { /// Define new fields forcecompleted, forcenewattempt, displayattemptstatus, and displaycoursestructure to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'maxattempt'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcecompleted'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcenewattempt'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'lastattemptlock'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'displayattemptstatus'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090305, 'scorm'); } // remove redundant config values if ($oldversion < 2008090306) { /* * comment this out as it is handled by the update mark 2008090310 below * left for historical documentation as some early adopters may have done * this already. $redundant_config = array( 'scorm_allowapidebug', 'scorm_allowtypeexternal', 'scorm_allowtypeimsrepository', 'scorm_allowtypelocalsync', 'scorm_apidebugmask', 'scorm_frameheight', 'scorm_framewidth', 'scorm_maxattempts', 'scorm_updatetime'); foreach ($redundant_config as $rcfg) { if (isset($CFG->$rcfg)) { unset_config($rcfg); } } */ /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090306, 'scorm'); } // remove redundant config values if ($oldversion < 2008090307) { /* * comment this out as it is handled by the update mark 2008090310 below * left for historical documentation as some early adopters may have done * this already. $redundant_config = array( 'scorm_allowapidebug', 'scorm_allowtypeexternal', 'scorm_allowtypeimsrepository', 'scorm_allowtypelocalsync', 'scorm_apidebugmask', 'scorm_frameheight', 'scorm_framewidth', 'scorm_maxattempts', 'scorm_updatetime', 'scorm_resizable', 'scorm_scrollbars', 'scorm_directories', 'scorm_location', 'scorm_menubar', 'scorm_toolbar', 'scorm_status', 'scorm_grademethod', 'scorm_maxgrade', 'scorm_whatgrade', 'scorm_popup', 'scorm_skipview', 'scorm_hidebrowse', 'scorm_hidetoc', 'scorm_hidenav', 'scorm_auto', 'scorm_updatefreq' ); foreach ($redundant_config as $rcfg) { if (isset($CFG->$rcfg)) { unset_config($rcfg); } } */ /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090307, 'scorm'); } if ($oldversion < 2008090308) { $table = new xmldb_table('scorm'); $field = new xmldb_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'height'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeopen'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090308, 'scorm'); } if ($oldversion < 2008090310) { // take above blocks that delete config and move the values in to config_plugins $redundant_config = array('scorm_allowapidebug', 'scorm_allowtypeexternal', 'scorm_allowtypeimsrepository', 'scorm_allowtypelocalsync', 'scorm_apidebugmask', 'scorm_frameheight', 'scorm_framewidth', 'scorm_maxattempts', 'scorm_updatetime', 'scorm_resizable', 'scorm_scrollbars', 'scorm_directories', 'scorm_location', 'scorm_menubar', 'scorm_toolbar', 'scorm_status', 'scorm_grademethod', 'scorm_maxgrade', 'scorm_whatgrade', 'scorm_popup', 'scorm_skipview', 'scorm_hidebrowse', 'scorm_hidetoc', 'scorm_hidenav', 'scorm_auto', 'scorm_updatefreq', 'scorm_displayattemptstatus', 'scorm_displaycoursestructure', 'scorm_forcecompleted', 'scorm_forcenewattempt', 'scorm_lastattemptlock'); foreach ($redundant_config as $rcfg) { if (isset($CFG->{$rcfg})) { $shortname = substr($rcfg, 6); set_config($shortname, $CFG->{$rcfg}, 'scorm'); unset_config($rcfg); } } /// scorm savepoint reached upgrade_mod_savepoint(true, 2008090310, 'scorm'); } if ($oldversion < 2009042000) { /// Rename field summary on table scorm to intro $table = new xmldb_table('scorm'); $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'reference'); /// Launch rename field summary $dbman->rename_field($table, $field, 'intro'); /// scorm savepoint reached upgrade_mod_savepoint(true, 2009042000, 'scorm'); } if ($oldversion < 2009042001) { /// Define field introformat to be added to scorm $table = new xmldb_table('scorm'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Launch add field introformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('scorm', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $s) { $s->intro = text_to_html($s->intro, false, false, true); $s->introformat = FORMAT_HTML; $DB->update_record('scorm', $s); upgrade_set_timeout(); } $rs->close(); } /// scorm savepoint reached upgrade_mod_savepoint(true, 2009042001, 'scorm'); } if ($oldversion < 2009042002) { /// Define field introformat to be added to scorm $table = new xmldb_table('scorm_scoes'); $field = new xmldb_field('launch', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); /// Launch add field introformat $dbman->change_field_type($table, $field); /// scorm savepoint reached upgrade_mod_savepoint(true, 2009042002, 'scorm'); } if ($oldversion < 2010070800) { //check to see if this has already been tidied up by a 1.9 upgrade. $grademethodfixed = get_config('scorm', 'grademethodfixed'); if (empty($grademethodfixed)) { /// fix bad usage of whatgrade/grading method. $scorms = $DB->get_records('scorm'); if (!empty($scorm)) { foreach ($scorms as $scorm) { $scorm->grademethod = $scorm->grademethod % 10; $DB->update_record('scorm', $scorm); } } } else { //dump this config var as it isn't needed anymore. unset_config('grademethodfixed', 'scorm'); } /// scorm savepoint reached upgrade_mod_savepoint(true, 2010070800, 'scorm'); } if ($oldversion < 2010092400) { $count = $DB->count_records('scorm', array('scormtype' => 'external')); if (!empty($count)) { set_config('allowtypeexternal', '1', 'scorm'); } $count = $DB->count_records('scorm', array('scormtype' => 'localsync')); if (!empty($count)) { set_config('allowtypelocalsync', '1', 'scorm'); } $count = $DB->count_records('scorm', array('scormtype' => 'imsrepository')); if (!empty($count)) { set_config('allowtypeimsrepository', '1', 'scorm'); } /// scorm savepoint reached upgrade_mod_savepoint(true, 2010092400, 'scorm'); } if ($oldversion < 2011011400) { // Fix scorm in the post table after upgrade from 1.9 $table = new xmldb_table('scorm'); $columns = $DB->get_columns('scorm'); // forcecompleted should be int(1) not null default 1 // Changing to NOT NULL, let's fill the current nulls with default 1 $DB->set_field('scorm', 'forcecompleted', 1, array('forcecompleted' => null)); $field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'maxattempt'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_precision($table, $field); } if (array_key_exists('forcenewattempt', $columns) && empty($columns['forcenewattempt']->not_null)) { // forcenewattempt should be int(1) not null default 0 // Changing to NOT NULL, let's fill the current nulls with default 0 $DB->set_field('scorm', 'forcenewattempt', 0, array('forcenewattempt' => null)); $field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcecompleted'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } } if (array_key_exists('lastattemptlock', $columns) && empty($columns['lastattemptlock']->not_null)) { // lastattemptlock should be int(1) not null default 0 // Changing to NOT NULL, let's fill the current nulls with default 0 $DB->set_field('scorm', 'lastattemptlock', 0, array('lastattemptlock' => null)); $field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcenewattempt'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } } if (array_key_exists('displayattemptstatus', $columns) && empty($columns['displayattemptstatus']->not_null)) { // displayattemptstatus should be int(1) not null default 1 // Changing to NOT NULL, let's fill the current nulls with default 1 $DB->set_field('scorm', 'displayattemptstatus', 1, array('displayattemptstatus' => null)); $field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'lastattemptlock'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } } if (array_key_exists('displaycoursestructure', $columns) && empty($columns['displaycoursestructure']->not_null)) { // displaycoursestructure should be int(1) not null default 1 // Changing to NOT NULL, let's fill the current nulls with default 1 $DB->set_field('scorm', 'displaycoursestructure', 1, array('displaycoursestructure' => null)); $field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'displayattemptstatus'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } } upgrade_mod_savepoint(true, 2011011400, 'scorm'); } if ($oldversion < 2011021402) { unset_config('updatetime', 'scorm'); upgrade_mod_savepoint(true, 2011021402, 'scorm'); } if ($oldversion < 2011021403) { //MDL-28295 the behaviour of pop-up windows has now changed - it now loads the full Player in the window //because of this, pop-up windows now include the TOC and the nav bar - disabling these for existing SCORMS //as it is a change that most users won't expect. //get all SCORMS that use a new window. require_once $CFG->dirroot . "/mod/scorm/lib.php"; $rs = $DB->get_recordset('scorm', array('popup' => 1), '', 'id,hidetoc,hidenav'); foreach ($rs as $scorm) { $scorm->hidetoc = 1; $scorm->hidenav = 1; $DB->update_record('scorm', $scorm); } $rs->close(); upgrade_mod_savepoint(true, 2011021403, 'scorm'); } return true; }
/** * * @global stdClass $CFG * @global stdClass $USER * @global moodle_database $DB * @global core_renderer $OUTPUT * @param int $oldversion * @return bool always true */ function xmldb_main_upgrade($oldversion) { global $CFG, $USER, $DB, $OUTPUT; require_once $CFG->libdir . '/db/upgradelib.php'; // Core Upgrade-related functions $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes //////////////////////////////////////// ///upgrade supported only from 1.9.x /// //////////////////////////////////////// if ($oldversion < 2008030600) { //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported /// Define table upgrade_log to be created $table = new xmldb_table('upgrade_log'); /// Adding fields to table upgrade_log $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('targetversion', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table upgrade_log $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Adding indexes to table upgrade_log $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified')); /// Create table for upgrade_log $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2008030600); } if ($oldversion < 2008030601) { //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported /// Define table log_queries to be created $table = new xmldb_table('log_queries'); /// Adding fields to table log_queries $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('qtype', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('sqltext', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null); $table->add_field('sqlparams', XMLDB_TYPE_TEXT, 'big', null, null, null, null); $table->add_field('error', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('info', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('exectime', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null); $table->add_field('timelogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table log_queries $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for log_queries $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2008030601); } if ($oldversion < 2008030602) { @unlink($CFG->dataroot . '/cache/languages'); if (file_exists("{$CFG->dataroot}/lang")) { // rename old lang directory so that the new and old langs do not mix if (rename("{$CFG->dataroot}/lang", "{$CFG->dataroot}/oldlang")) { $oldlang = "{$CFG->dataroot}/oldlang"; } else { $oldlang = "{$CFG->dataroot}/lang"; } } else { $oldlang = ''; } // TODO: fetch previously installed languages ("*_utf8") found in $oldlang from moodle.org upgrade_set_timeout(60 * 20); // this may take a while // TODO: add some info file to $oldlang describing what to do with "$oldlang/*_utf8_local" dirs // Main savepoint reached upgrade_main_savepoint(true, 2008030602); } if ($oldversion < 2008030700) { upgrade_set_timeout(60 * 20); // this may take a while /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters $table = new xmldb_table('grade_letters'); $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary')); /// Launch drop index contextid-lowerboundary if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters $table = new xmldb_table('grade_letters'); $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter')); /// Launch add index contextid-lowerboundary-letter $dbman->add_index($table, $index); /// Main savepoint reached upgrade_main_savepoint(true, 2008030700); } if ($oldversion < 2008050100) { // Update courses that used weekscss to weeks $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss')); upgrade_main_savepoint(true, 2008050100); } if ($oldversion < 2008050200) { // remove unused config options unset_config('statsrolesupgraded'); upgrade_main_savepoint(true, 2008050200); } if ($oldversion < 2008050700) { upgrade_set_timeout(60 * 20); // this may take a while /// Fix minor problem caused by MDL-5482. require_once $CFG->dirroot . '/question/upgrade.php'; question_fix_random_question_parents(); upgrade_main_savepoint(true, 2008050700); } if ($oldversion < 2008051201) { echo $OUTPUT->notification('Increasing size of user idnumber field, this may take a while...', 'notifysuccess'); upgrade_set_timeout(60 * 20); // this may take a while /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859 $dbfamily = $DB->get_dbfamily(); if ($dbfamily === 'mysql' || $dbfamily === 'postgres') { $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL"); } /// Define index idnumber (not unique) to be dropped form user $table = new xmldb_table('user'); $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); /// Launch drop index idnumber if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } /// Changing precision of field idnumber on table user to (255) $table = new xmldb_table('user'); $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password'); /// Launch change of precision for field idnumber $dbman->change_field_precision($table, $field); /// Launch add index idnumber again $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); $dbman->add_index($table, $index); /// Main savepoint reached upgrade_main_savepoint(true, 2008051201); } if ($oldversion < 2008051203) { $table = new xmldb_table('mnet_enrol_course'); $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); $dbman->change_field_precision($table, $field); upgrade_main_savepoint(true, 2008051203); } if ($oldversion < 2008063001) { upgrade_set_timeout(60 * 20); // this may take a while // table to be modified $table = new xmldb_table('tag_instance'); // add field $field = new xmldb_field('tiuserid'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid'); $dbman->add_field($table, $field); } // modify index $index = new xmldb_index('itemtype-itemid-tagid'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid')); if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } $index = new xmldb_index('itemtype-itemid-tagid-tiuserid'); $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Main savepoint reached upgrade_main_savepoint(true, 2008063001); } if ($oldversion < 2008070300) { $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false)); upgrade_main_savepoint(true, 2008070300); } if ($oldversion < 2008070701) { /// Define table portfolio_instance to be created $table = new xmldb_table('portfolio_instance'); /// Adding fields to table portfolio_instance $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); /// Adding keys to table portfolio_instance $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for portfolio_instance if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table portfolio_instance_config to be created $table = new xmldb_table('portfolio_instance_config'); /// Adding fields to table portfolio_instance_config $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); /// Adding keys to table portfolio_instance_config $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); /// Adding indexes to table portfolio_instance_config $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name')); /// Conditionally launch create table for portfolio_instance_config if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table portfolio_instance_user to be created $table = new xmldb_table('portfolio_instance_user'); /// Adding fields to table portfolio_instance_user $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); /// Adding keys to table portfolio_instance_user $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Conditionally launch create table for portfolio_instance_user if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2008070701); } if ($oldversion < 2008072400) { /// Create the database tables for message_processors $table = new xmldb_table('message_processors'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $dbman->create_table($table); /// delete old and create new fields $table = new xmldb_table('message'); $field = new xmldb_field('messagetype'); $dbman->drop_field($table, $field); /// fields to rename $field = new xmldb_field('message'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); $dbman->rename_field($table, $field, 'fullmessage'); $field = new xmldb_field('format'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null); $dbman->rename_field($table, $field, 'fullmessageformat'); /// new message fields $field = new xmldb_field('subject'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); $dbman->add_field($table, $field); $field = new xmldb_field('fullmessagehtml'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null); $dbman->add_field($table, $field); $field = new xmldb_field('smallmessage'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); $dbman->add_field($table, $field); $table = new xmldb_table('message_read'); $field = new xmldb_field('messagetype'); $dbman->drop_field($table, $field); $field = new xmldb_field('mailed'); $dbman->drop_field($table, $field); /// fields to rename $field = new xmldb_field('message'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); $dbman->rename_field($table, $field, 'fullmessage'); $field = new xmldb_field('format'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null); $dbman->rename_field($table, $field, 'fullmessageformat'); /// new message fields $field = new xmldb_field('subject'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); $dbman->add_field($table, $field); $field = new xmldb_field('fullmessagehtml'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null); $dbman->add_field($table, $field); $field = new xmldb_field('smallmessage'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); $dbman->add_field($table, $field); /// new table $table = new xmldb_table('message_working'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $dbman->create_table($table); upgrade_main_savepoint(true, 2008072400); } if ($oldversion < 2008072800) { /// Define field enablecompletion to be added to course $table = new xmldb_table('course'); $field = new xmldb_field('enablecompletion'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole'); /// Launch add field enablecompletion if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field completion to be added to course_modules $table = new xmldb_table('course_modules'); $field = new xmldb_field('completion'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly'); /// Launch add field completion if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field completiongradeitemnumber to be added to course_modules $field = new xmldb_field('completiongradeitemnumber'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion'); /// Launch add field completiongradeitemnumber if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field completionview to be added to course_modules $field = new xmldb_field('completionview'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber'); /// Launch add field completionview if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field completionexpected to be added to course_modules $field = new xmldb_field('completionexpected'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview'); /// Launch add field completionexpected if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define table course_modules_completion to be created $table = new xmldb_table('course_modules_completion'); if (!$dbman->table_exists($table)) { /// Adding fields to table course_modules_completion $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table course_modules_completion $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table course_modules_completion $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid')); $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); /// Launch create table for course_modules_completion $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2008072800); } if ($oldversion < 2008073000) { /// Define table portfolio_log to be created $table = new xmldb_table('portfolio_log'); /// Adding fields to table portfolio_log $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null); $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('tempdataid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); $table->add_field('returnurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('continueurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); /// Adding keys to table portfolio_log $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id')); /// Conditionally launch create table for portfolio_log if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2008073000); } if ($oldversion < 2008073104) { /// Drop old table that might exist for some people $table = new xmldb_table('message_providers'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Define table message_providers to be created $table = new xmldb_table('message_providers'); /// Adding fields to table message_providers $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null); /// Adding keys to table message_providers $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table message_providers $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name')); /// Create table for message_providers $dbman->create_table($table); upgrade_main_savepoint(true, 2008073104); } if ($oldversion < 2008073111) { /// Define table files to be created $table = new xmldb_table('files'); /// Adding fields to table files $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table files $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Adding indexes to table files $table->add_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid')); $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash')); $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash')); /// Conditionally launch create table for files $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2008073111); } if ($oldversion < 2008073112) { // Define field legacyfiles to be added to course $table = new xmldb_table('course'); $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes'); // Launch add field legacyfiles $dbman->add_field($table, $field); // enable legacy files in all courses $DB->execute("UPDATE {course} SET legacyfiles = 2"); // Main savepoint reached upgrade_main_savepoint(true, 2008073112); } if ($oldversion < 2008073113) { /// move all course, backup and other files to new filepool based storage upgrade_migrate_files_courses(); /// Main savepoint reached upgrade_main_savepoint(true, 2008073113); } if ($oldversion < 2008073114) { /// move all course, backup and other files to new filepool based storage upgrade_migrate_files_blog(); /// Main savepoint reached upgrade_main_savepoint(true, 2008073114); } if ($oldversion < 2008080400) { // Add field ssl_jump_url to mnet application, and populate existing default applications $table = new xmldb_table('mnet_application'); $field = new xmldb_field('sso_jump_url'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $dbman->add_field($table, $field); $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle')); $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara')); } /// Main savepoint reached upgrade_main_savepoint(true, 2008080400); } if ($oldversion < 2008080500) { /// Define table portfolio_tempdata to be created $table = new xmldb_table('portfolio_tempdata'); /// Adding fields to table portfolio_tempdata $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null); $table->add_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', null, null, null, '0'); /// Adding keys to table portfolio_tempdata $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); /// Conditionally launch create table for portfolio_tempdata if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2008080500); } if ($oldversion < 2008081500) { /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7). $table = new xmldb_table('question'); $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1.0000000', 'generalfeedback'); $dbman->change_field_type($table, $field); upgrade_main_savepoint(true, 2008081500); } if ($oldversion < 2008081501) { $table = new xmldb_table('question'); $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0.1000000', 'defaultgrade'); $dbman->change_field_type($table, $field); upgrade_main_savepoint(true, 2008081501); } if ($oldversion < 2008081502) { $table = new xmldb_table('question_answers'); $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'answer'); $dbman->change_field_type($table, $field); upgrade_main_savepoint(true, 2008081502); } if ($oldversion < 2008081503) { $table = new xmldb_table('question_sessions'); $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'newgraded'); $dbman->change_field_type($table, $field); upgrade_main_savepoint(true, 2008081503); } if ($oldversion < 2008081504) { $table = new xmldb_table('question_states'); $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'event'); $dbman->change_field_type($table, $field); upgrade_main_savepoint(true, 2008081504); } if ($oldversion < 2008081505) { $table = new xmldb_table('question_states'); $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'grade'); $dbman->change_field_type($table, $field); upgrade_main_savepoint(true, 2008081505); } if ($oldversion < 2008081506) { $table = new xmldb_table('question_states'); $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'raw_grade'); $dbman->change_field_type($table, $field); upgrade_main_savepoint(true, 2008081506); } if ($oldversion < 2008081600) { /// all 1.9 sites and fresh installs must already be unicode, not needed anymore unset_config('unicodedb'); /// Main savepoint reached upgrade_main_savepoint(true, 2008081600); } if ($oldversion < 2008082602) { /// Define table repository to be dropped $table = new xmldb_table('repository'); /// Conditionally launch drop table for repository if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Define table repository to be created $table = new xmldb_table('repository'); /// Adding fields to table repository $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1'); $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table repository $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for repository if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table repository_instances to be created $table = new xmldb_table('repository_instances'); /// Adding fields to table repository_instances $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table repository_instances $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for repository_instances if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table repository_instance_config to be created $table = new xmldb_table('repository_instance_config'); /// Adding fields to table repository_instance_config $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); /// Adding keys to table repository_instance_config $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for repository_instance_config if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2008082602); } if ($oldversion < 2008082700) { /// Add a new column to the question sessions table to record whether a /// question has been flagged. /// Define field flagged to be added to question_sessions $table = new xmldb_table('question_sessions'); $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment'); /// Conditionally launch add field flagged if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2008082700); } if ($oldversion < 2008082900) { /// Changing precision of field parent_type on table mnet_rpc to (20) $table = new xmldb_table('mnet_rpc'); $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path'); /// Launch change of precision for field parent_type $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2008082900); } // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins. if ($oldversion < 2008091000) { foreach (get_object_vars($CFG) as $name => $value) { if (substr($name, strlen($name) - 8) !== '_version') { continue; } $pluginname = substr($name, 0, strlen($name) - 8); if (!strpos($pluginname, '_')) { // Skip things like backup_version that don't contain an extra _ continue; } if ($pluginname == 'enrol_ldap_version') { // Special case - this is something different from a plugin version number. continue; } if (!preg_match('/^\\d{10}$/', $value)) { // Extra safety check, skip anything that does not look like a Moodle // version number (10 digits). continue; } set_config('version', $value, $pluginname); unset_config($name); } upgrade_main_savepoint(true, 2008091000); } if ($oldversion < 2008092300) { unset_config('editorspelling'); unset_config('editordictionary'); /// Main savepoint reached upgrade_main_savepoint(true, 2008092300); } if ($oldversion < 2008101300) { if (!get_config(NULL, 'statsruntimedays')) { set_config('statsruntimedays', '31'); } /// Main savepoint reached upgrade_main_savepoint(true, 2008101300); } /// Drop the deprecated teacher, teachers, student and students columns from the course table. if ($oldversion < 2008111200) { $table = new xmldb_table('course'); /// Conditionally launch drop field teacher $field = new xmldb_field('teacher'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Conditionally launch drop field teacher $field = new xmldb_field('teachers'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Conditionally launch drop field teacher $field = new xmldb_field('student'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Conditionally launch drop field teacher $field = new xmldb_field('students'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2008111200); } /// Add a unique index to the role.name column. if ($oldversion < 2008111800) { /// Define index name (unique) to be added to role $table = new xmldb_table('role'); $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); /// Conditionally launch add index name if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Main savepoint reached upgrade_main_savepoint(true, 2008111800); } /// Add a unique index to the role.shortname column. if ($oldversion < 2008111801) { /// Define index shortname (unique) to be added to role $table = new xmldb_table('role'); $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname')); /// Conditionally launch add index shortname if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Main savepoint reached upgrade_main_savepoint(true, 2008111801); } if ($oldversion < 2008120700) { /// Changing precision of field shortname on table course_request to (100) $table = new xmldb_table('course_request'); $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname'); /// Before changing the field, drop dependent indexes /// Define index shortname (not unique) to be dropped form course_request $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname')); /// Conditionally launch drop index shortname if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } /// Launch change of precision for field shortname $dbman->change_field_precision($table, $field); /// After changing the field, recreate dependent indexes /// Define index shortname (not unique) to be added to course_request $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname')); /// Conditionally launch add index shortname if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Main savepoint reached upgrade_main_savepoint(true, 2008120700); } if ($oldversion < 2008120801) { /// Changing precision of field shortname on table mnet_enrol_course to (100) $table = new xmldb_table('mnet_enrol_course'); $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname'); /// Launch change of precision for field shortname $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2008120801); } if ($oldversion < 2008121701) { /// Define field availablefrom to be added to course_modules $table = new xmldb_table('course_modules'); $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected'); /// Conditionally launch add field availablefrom if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field availableuntil to be added to course_modules $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom'); /// Conditionally launch add field availableuntil if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field showavailability to be added to course_modules $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil'); /// Conditionally launch add field showavailability if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define table course_modules_availability to be created $table = new xmldb_table('course_modules_availability'); /// Adding fields to table course_modules_availability $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); /// Adding keys to table course_modules_availability $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id')); $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id')); $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id')); /// Conditionally launch create table for course_modules_availability if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Changes to modinfo mean we need to rebuild course cache require_once $CFG->dirroot . '/course/lib.php'; rebuild_course_cache(0, true); /// Main savepoint reached upgrade_main_savepoint(true, 2008121701); } if ($oldversion < 2009010500) { /// clean up config table a bit unset_config('session_error_counter'); /// Main savepoint reached upgrade_main_savepoint(true, 2009010500); } if ($oldversion < 2009010600) { /// Define field originalquestion to be dropped from question_states $table = new xmldb_table('question_states'); $field = new xmldb_field('originalquestion'); /// Conditionally launch drop field originalquestion if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2009010600); } if ($oldversion < 2009010601) { /// Changing precision of field ip on table log to (45) $table = new xmldb_table('log'); $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid'); /// Launch change of precision for field ip $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009010601); } if ($oldversion < 2009010602) { /// Changing precision of field lastip on table user to (45) $table = new xmldb_table('user'); $field = new xmldb_field('lastip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'currentlogin'); /// Launch change of precision for field lastip $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009010602); } if ($oldversion < 2009010603) { /// Changing precision of field ip_address on table mnet_host to (45) $table = new xmldb_table('mnet_host'); $field = new xmldb_field('ip_address', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'wwwroot'); /// Launch change of precision for field ip_address $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009010603); } if ($oldversion < 2009010604) { /// Changing precision of field ip on table mnet_log to (45) $table = new xmldb_table('mnet_log'); $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid'); /// Launch change of precision for field ip $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009010604); } if ($oldversion < 2009011000) { /// Changing nullability of field configdata on table block_instance to null $table = new xmldb_table('block_instance'); $field = new xmldb_field('configdata'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'visible'); /// Launch change of nullability for field configdata $dbman->change_field_notnull($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009011000); } if ($oldversion < 2009011100) { /// Remove unused settings unset_config('zip'); unset_config('unzip'); unset_config('adminblocks_initialised'); /// Main savepoint reached upgrade_main_savepoint(true, 2009011100); } if ($oldversion < 2009011101) { /// Migrate backup settings to core plugin config table $configs = $DB->get_records('backup_config'); foreach ($configs as $config) { set_config($config->name, $config->value, 'backup'); } /// Define table to be dropped $table = new xmldb_table('backup_config'); /// Launch drop table for old backup config $dbman->drop_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009011101); } if ($oldversion < 2009011303) { /// Define table config_log to be created $table = new xmldb_table('config_log'); /// Adding fields to table config_log $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null); /// Adding keys to table config_log $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Adding indexes to table config_log $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); /// Launch create table for config_log $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009011303); } if ($oldversion < 2009011900) { /// Define table sessions2 to be dropped $table = new xmldb_table('sessions2'); /// Conditionally launch drop table for sessions if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Define table sessions to be dropped $table = new xmldb_table('sessions'); /// Conditionally launch drop table for sessions if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Define table sessions to be created $table = new xmldb_table('sessions'); /// Adding fields to table sessions $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('state', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null); $table->add_field('lastip', XMLDB_TYPE_CHAR, '45', null, null, null, null); /// Adding keys to table sessions $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Adding indexes to table sessions $table->add_index('state', XMLDB_INDEX_NOTUNIQUE, array('state')); $table->add_index('sid', XMLDB_INDEX_UNIQUE, array('sid')); $table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated')); $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); /// Launch create table for sessions $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009011900); } if ($oldversion < 2009021800) { // Converting format of grade conditions, if any exist, to percentages. $DB->execute("\nUPDATE {course_modules_availability} SET grademin=(\n SELECT 100.0*({course_modules_availability}.grademin-gi.grademin)\n /(gi.grademax-gi.grademin)\n FROM {grade_items} gi\n WHERE gi.id={course_modules_availability}.gradeitemid)\nWHERE gradeitemid IS NOT NULL AND grademin IS NOT NULL"); $DB->execute("\nUPDATE {course_modules_availability} SET grademax=(\n SELECT 100.0*({course_modules_availability}.grademax-gi.grademin)\n /(gi.grademax-gi.grademin)\n FROM {grade_items} gi\n WHERE gi.id={course_modules_availability}.gradeitemid)\nWHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); /// Main savepoint reached upgrade_main_savepoint(true, 2009021800); } if ($oldversion < 2009021801) { /// Define field backuptype to be added to backup_log $table = new xmldb_table('backup_log'); $field = new xmldb_field('backuptype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'info'); /// Conditionally Launch add field backuptype and set all old records as 'scheduledbackup' records. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); $DB->execute("UPDATE {backup_log} SET backuptype='scheduledbackup'"); } /// Main savepoint reached upgrade_main_savepoint(true, 2009021801); } /// Add default sort order for question types. if ($oldversion < 2009030300) { set_config('multichoice_sortorder', 1, 'question'); set_config('truefalse_sortorder', 2, 'question'); set_config('shortanswer_sortorder', 3, 'question'); set_config('numerical_sortorder', 4, 'question'); set_config('calculated_sortorder', 5, 'question'); set_config('essay_sortorder', 6, 'question'); set_config('match_sortorder', 7, 'question'); set_config('randomsamatch_sortorder', 8, 'question'); set_config('multianswer_sortorder', 9, 'question'); set_config('description_sortorder', 10, 'question'); set_config('random_sortorder', 11, 'question'); set_config('missingtype_sortorder', 12, 'question'); upgrade_main_savepoint(true, 2009030300); } /// MDL-18132 replace the use a new Role allow switch settings page, instead of /// $CFG->allowuserswitchrolestheycantassign if ($oldversion < 2009032000) { /// First create the new table. $table = new xmldb_table('role_allow_switch'); /// Adding fields to table role_allow_switch $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('allowswitch', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table role_allow_switch $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); $table->add_key('allowswitch', XMLDB_KEY_FOREIGN, array('allowswitch'), 'role', array('id')); /// Adding indexes to table role_allow_switch $table->add_index('roleid-allowoverride', XMLDB_INDEX_UNIQUE, array('roleid', 'allowswitch')); /// Conditionally launch create table for role_allow_switch if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2009032000); } if ($oldversion < 2009032001) { /// Copy from role_allow_assign into the new table. $DB->execute('INSERT INTO {role_allow_switch} (roleid, allowswitch) SELECT roleid, allowassign FROM {role_allow_assign}'); /// Unset the config variable used in 1.9. unset_config('allowuserswitchrolestheycantassign'); /// Main savepoint reached upgrade_main_savepoint(true, 2009032001); } if ($oldversion < 2009040300) { /// Define table filter_active to be created $table = new xmldb_table('filter_active'); /// Adding fields to table filter_active $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('active', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); /// Adding keys to table filter_active $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); /// Adding indexes to table filter_active $table->add_index('contextid-filter', XMLDB_INDEX_UNIQUE, array('contextid', 'filter')); /// Conditionally launch create table for filter_active if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2009040300); } if ($oldversion < 2009040301) { /// Define table filter_config to be created $table = new xmldb_table('filter_config'); /// Adding fields to table filter_config $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); /// Adding keys to table filter_config $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); /// Adding indexes to table filter_config $table->add_index('contextid-filter-name', XMLDB_INDEX_UNIQUE, array('contextid', 'filter', 'name')); /// Conditionally launch create table for filter_config if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2009040301); } if ($oldversion < 2009040302) { /// Transfer current settings from $CFG->textfilters $disabledfilters = filter_get_all_installed(); if (empty($CFG->textfilters)) { $activefilters = array(); } else { $activefilters = explode(',', $CFG->textfilters); } $syscontext = get_context_instance(CONTEXT_SYSTEM); $sortorder = 1; foreach ($activefilters as $filter) { filter_set_global_state($filter, TEXTFILTER_ON, $sortorder); $sortorder += 1; unset($disabledfilters[$filter]); } foreach ($disabledfilters as $filter => $notused) { filter_set_global_state($filter, TEXTFILTER_DISABLED, $sortorder); $sortorder += 1; } /// Main savepoint reached upgrade_main_savepoint(true, 2009040302); } if ($oldversion < 2009040600) { /// Ensure that $CFG->stringfilters is set. if (empty($CFG->stringfilters)) { if (!empty($CFG->filterall)) { set_config('stringfilters', $CFG->textfilters); } else { set_config('stringfilters', ''); } } set_config('filterall', !empty($CFG->stringfilters)); unset_config('textfilters'); /// Main savepoint reached upgrade_main_savepoint(true, 2009040600); } if ($oldversion < 2009041700) { /// To ensure the UI remains consistent with no behaviour change, any /// 'until' date in an activity condition should have 1 second subtracted /// (to go from 0:00 on the following day to 23:59 on the previous one). $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0'); require_once $CFG->dirroot . '/course/lib.php'; rebuild_course_cache(0, true); /// Main savepoint reached upgrade_main_savepoint(true, 2009041700); } if ($oldversion < 2009042600) { /// Deleting orphaned messages from deleted users. require_once $CFG->dirroot . '/message/lib.php'; /// Detect deleted users with messages sent(useridfrom) and not read if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id FROM {user} u JOIN {message} m ON m.useridfrom = u.id WHERE u.deleted = ?', array(1))) { foreach ($deletedusers as $deleteduser) { message_move_userfrom_unread2read($deleteduser->id); // move messages } } /// Main savepoint reached upgrade_main_savepoint(true, 2009042600); } /// Dropping all enums/check contraints from core. MDL-18577 if ($oldversion < 2009042700) { /// Changing list of values (enum) of field stattype on table stats_daily to none $table = new xmldb_table('stats_daily'); $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); /// Launch change of list of values for field stattype $dbman->drop_enum_from_field($table, $field); /// Changing list of values (enum) of field stattype on table stats_weekly to none $table = new xmldb_table('stats_weekly'); $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); /// Launch change of list of values for field stattype $dbman->drop_enum_from_field($table, $field); /// Changing list of values (enum) of field stattype on table stats_monthly to none $table = new xmldb_table('stats_monthly'); $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); /// Launch change of list of values for field stattype $dbman->drop_enum_from_field($table, $field); /// Changing list of values (enum) of field publishstate on table post to none $table = new xmldb_table('post'); $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment'); /// Launch change of list of values for field publishstate $dbman->drop_enum_from_field($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009042700); } if ($oldversion < 2009043000) { unset_config('grade_report_showgroups'); upgrade_main_savepoint(true, 2009043000); } if ($oldversion < 2009050600) { /// Site front page blocks need to be moved due to page name change. $DB->set_field('block_instance', 'pagetype', 'site-index', array('pagetype' => 'course-view', 'pageid' => SITEID)); /// Main savepoint reached upgrade_main_savepoint(true, 2009050600); } if ($oldversion < 2009050601) { /// Define table block_instance to be renamed to block_instances $table = new xmldb_table('block_instance'); /// Launch rename table for block_instance $dbman->rename_table($table, 'block_instances'); /// Main savepoint reached upgrade_main_savepoint(true, 2009050601); } if ($oldversion < 2009050602) { /// Define table block_instance to be renamed to block_instance_old $table = new xmldb_table('block_pinned'); /// Launch rename table for block_instance $dbman->rename_table($table, 'block_pinned_old'); /// Main savepoint reached upgrade_main_savepoint(true, 2009050602); } if ($oldversion < 2009050603) { /// Define table block_instance_old to be created $table = new xmldb_table('block_instance_old'); /// Adding fields to table block_instance_old $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); $table->add_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0'); $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0'); $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null); /// Adding keys to table block_instance_old $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id')); /// Adding indexes to table block_instance_old $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid')); $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype')); /// Conditionally launch create table for block_instance_old if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2009050603); } if ($oldversion < 2009050604) { /// Copy current blocks data from block_instances to block_instance_old $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata) SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id'); upgrade_main_savepoint(true, 2009050604); } if ($oldversion < 2009050605) { /// Define field multiple to be dropped from block $table = new xmldb_table('block'); $field = new xmldb_field('multiple'); /// Conditionally launch drop field multiple if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2009050605); } if ($oldversion < 2009050606) { $table = new xmldb_table('block_instances'); /// Rename field weight on table block_instances to defaultweight $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, 'position'); $dbman->rename_field($table, $field, 'defaultweight'); /// Rename field position on table block_instances to defaultregion $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'pagetype'); $dbman->rename_field($table, $field, 'defaultregion'); /// Main savepoint reached upgrade_main_savepoint(true, 2009050606); } if ($oldversion < 2009050607) { /// Changing precision of field defaultregion on table block_instances to (16) $table = new xmldb_table('block_instances'); $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'pagetype'); /// Launch change of precision for field defaultregion $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009050607); } if ($oldversion < 2009050608) { /// Change regions to the new notation $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l')); $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r')); $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c')); // This third one is a custom value from contrib/patches/center_blocks_position_patch and the // flex page course format. Hopefully this new value is an adequate alternative. /// Main savepoint reached upgrade_main_savepoint(true, 2009050608); } if ($oldversion < 2009050609) { /// Define key blockname (unique) to be added to block $table = new xmldb_table('block'); $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name')); /// Launch add key blockname $dbman->add_key($table, $key); /// Main savepoint reached upgrade_main_savepoint(true, 2009050609); } if ($oldversion < 2009050610) { $table = new xmldb_table('block_instances'); /// Define field blockname to be added to block_instances $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'blockid'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field contextid to be added to block_instances $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'blockname'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field showinsubcontexts to be added to block_instances $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'contextid'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field subpagepattern to be added to block_instances $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'pagetype'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2009050610); } if ($oldversion < 2009050611) { $table = new xmldb_table('block_instances'); /// Fill in blockname from blockid $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)"); /// Set showinsubcontexts = 0 for all rows. $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0"); /// Main savepoint reached upgrade_main_savepoint(true, 2009050611); } if ($oldversion < 2009050612) { /// Rename field pagetype on table block_instances to pagetypepattern $table = new xmldb_table('block_instances'); $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'pageid'); /// Launch rename field pagetype $dbman->rename_field($table, $field, 'pagetypepattern'); /// Main savepoint reached upgrade_main_savepoint(true, 2009050612); } if ($oldversion < 2009050613) { /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid /// site-index $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); $DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ",\n pagetypepattern = 'site-index',\n subpagepattern = NULL\n WHERE pagetypepattern = 'site-index'"); /// course-view $DB->execute("UPDATE {block_instances} SET\n contextid = (\n SELECT {context}.id\n FROM {context}\n JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . "\n WHERE {course}.id = pageid\n ),\n pagetypepattern = 'course-view-*',\n subpagepattern = NULL\n WHERE pagetypepattern = 'course-view'"); /// admin $syscontext = get_context_instance(CONTEXT_SYSTEM); $DB->execute("UPDATE {block_instances} SET\n contextid = " . $syscontext->id . ",\n pagetypepattern = 'admin-*',\n subpagepattern = NULL\n WHERE pagetypepattern = 'admin'"); /// my-index $DB->execute("UPDATE {block_instances} SET\n contextid = (\n SELECT {context}.id\n FROM {context}\n JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "\n WHERE {user}.id = pageid\n ),\n pagetypepattern = 'my-index',\n subpagepattern = NULL\n WHERE pagetypepattern = 'my-index'"); /// tag-index $DB->execute("UPDATE {block_instances} SET\n contextid = " . $syscontext->id . ",\n pagetypepattern = 'tag-index',\n subpagepattern = pageid\n WHERE pagetypepattern = 'tag-index'"); /// blog-view $DB->execute("UPDATE {block_instances} SET\n contextid = (\n SELECT {context}.id\n FROM {context}\n JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "\n WHERE {user}.id = pageid\n ),\n pagetypepattern = 'blog-index',\n subpagepattern = NULL\n WHERE pagetypepattern = 'blog-view'"); /// mod-xxx-view $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog'); foreach ($moduleswithblocks as $modname) { if (!$dbman->table_exists($modname)) { continue; } $DB->execute("UPDATE {block_instances} SET\n contextid = (\n SELECT {context}.id\n FROM {context}\n JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . "\n JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '{$modname}'\n JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id\n WHERE {{$modname}}.id = pageid\n ),\n pagetypepattern = 'blog-index',\n subpagepattern = NULL\n WHERE pagetypepattern = 'blog-view'"); } /// Main savepoint reached upgrade_main_savepoint(true, 2009050613); } if ($oldversion < 2009050614) { /// fill in any missing contextids with a dummy value, so we can add the not-null constraint. $DB->execute("UPDATE {block_instances} SET contextid = 0 WHERE contextid IS NULL"); /// Main savepoint reached upgrade_main_savepoint(true, 2009050614); } if ($oldversion < 2009050615) { $table = new xmldb_table('block_instances'); /// Arrived here, any block_instances record without blockname is one /// orphan block coming from 1.9. Just delete them. MDL-22503 $DB->delete_records_select('block_instances', 'blockname IS NULL'); /// Changing nullability of field blockname on table block_instances to not null $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id'); $dbman->change_field_notnull($table, $field); /// Changing nullability of field contextid on table block_instances to not null $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname'); $dbman->change_field_notnull($table, $field); /// Changing nullability of field showinsubcontexts on table block_instances to not null $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, 'contextid'); $dbman->change_field_notnull($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009050615); } if ($oldversion < 2009050616) { /// Add exiting sticky blocks. $blocks = $DB->get_records('block'); $syscontext = get_context_instance(CONTEXT_SYSTEM); $newregions = array('l' => 'side-pre', 'r' => 'side-post', 'c' => 'course-view-top'); $stickyblocks = $DB->get_recordset('block_pinned_old'); foreach ($stickyblocks as $stickyblock) { // Only if the block exists (avoid orphaned sticky blocks) if (!isset($blocks[$stickyblock->blockid]) || empty($blocks[$stickyblock->blockid]->name)) { continue; } $newblock = new stdClass(); $newblock->blockname = $blocks[$stickyblock->blockid]->name; $newblock->contextid = $syscontext->id; $newblock->showinsubcontexts = 1; switch ($stickyblock->pagetype) { case 'course-view': $newblock->pagetypepattern = 'course-view-*'; break; default: $newblock->pagetypepattern = $stickyblock->pagetype; } $newblock->defaultregion = $newregions[$stickyblock->position]; $newblock->defaultweight = $stickyblock->weight; $newblock->configdata = $stickyblock->configdata; $newblock->visible = 1; $DB->insert_record('block_instances', $newblock); } /// Main savepoint reached upgrade_main_savepoint(true, 2009050616); } if ($oldversion < 2009050617) { /// Define table block_positions to be created $table = new xmldb_table('block_positions'); /// Adding fields to table block_positions $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null); $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null); $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null); $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); /// Adding keys to table block_positions $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); /// Adding indexes to table block_positions $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage')); /// Conditionally launch create table for block_positions if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2009050617); } if ($oldversion < 2009050618) { /// And block instances with visible = 0, copy that information to block_positions $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight)\n SELECT bi.id, bi.contextid,\n CASE WHEN bi.pagetypepattern = 'course-view-*'\n THEN (SELECT " . $DB->sql_concat("'course-view-'", 'c.format') . "\n FROM {course} c\n JOIN {context} ctx ON c.id = ctx.instanceid\n WHERE ctx.id = bi.contextid)\n ELSE bi.pagetypepattern END,\n CASE WHEN bi.subpagepattern IS NULL\n THEN '" . $DB->sql_empty() . "'\n ELSE bi.subpagepattern END,\n 0, bi.defaultregion, bi.defaultweight\n FROM {block_instances} bi\n WHERE bi.visible = 0 AND bi.pagetypepattern <> 'admin-*' AND bi.pagetypepattern IS NOT NULL"); // note: MDL-25031 all block instances should have a pagetype pattern, NULL is not allowed, // if we manage to find out how NULLs get there we should fix them before this step /// Main savepoint reached upgrade_main_savepoint(true, 2009050618); } if ($oldversion < 2009050619) { $table = new xmldb_table('block_instances'); /// Define field blockid to be dropped from block_instances $field = new xmldb_field('blockid'); if ($dbman->field_exists($table, $field)) { /// Before dropping the field, drop dependent indexes $index = new xmldb_index('blockid', XMLDB_INDEX_NOTUNIQUE, array('blockid')); if ($dbman->index_exists($table, $index)) { /// Launch drop index blockid $dbman->drop_index($table, $index); } $dbman->drop_field($table, $field); } /// Define field pageid to be dropped from block_instances $field = new xmldb_field('pageid'); if ($dbman->field_exists($table, $field)) { /// Before dropping the field, drop dependent indexes $index = new xmldb_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid')); if ($dbman->index_exists($table, $index)) { /// Launch drop index pageid $dbman->drop_index($table, $index); } $dbman->drop_field($table, $field); } /// Define field visible to be dropped from block_instances $field = new xmldb_field('visible'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2009050619); } if ($oldversion < 2009051200) { /// Let's check the status of mandatory mnet_host records, fixing them /// and moving "orphan" users to default localhost record. MDL-16879 echo $OUTPUT->notification('Fixing mnet records, this may take a while...', 'notifysuccess'); upgrade_fix_incorrect_mnethostids(); /// Main savepoint reached upgrade_main_savepoint(true, 2009051200); } if ($oldversion < 2009051700) { /// migrate editor settings if (empty($CFG->htmleditor)) { set_config('texteditors', 'textarea'); } else { set_config('texteditors', 'tinymce,textarea'); } unset_config('htmleditor'); unset_config('defaulthtmleditor'); /// Main savepoint reached upgrade_main_savepoint(true, 2009051700); } /// Repeat 2009050607 upgrade step, which Petr commented out because of XMLDB /// stupidity, so lots of people will have missed. if ($oldversion < 2009061600) { /// Changing precision of field defaultregion on table block_instances to (16) $table = new xmldb_table('block_instances'); $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'configdata'); /// Launch change of precision for field defaultregion $dbman->change_field_precision($table, $field); /// Main savepoint reached upgrade_main_savepoint(true, 2009061600); } if ($oldversion < 2009061702) { // standardizing plugin names if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'quizreport_%'")) { foreach ($configs as $config) { unset_config($config->name, $config->plugin); /// unset old config $config->plugin = str_replace('quizreport_', 'quiz_', $config->plugin); set_config($config->name, $config->value, $config->plugin); /// set new config } } unset($configs); upgrade_main_savepoint(true, 2009061702); } if ($oldversion < 2009061703) { // standardizing plugin names if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'assignment_type_%'")) { foreach ($configs as $config) { unset_config($config->name, $config->plugin); /// unset old config $config->plugin = str_replace('assignment_type_', 'assignment_', $config->plugin); set_config($config->name, $config->value, $config->plugin); /// set new config } } unset($configs); upgrade_main_savepoint(true, 2009061703); } if ($oldversion < 2009061704) { // change component string in capability records to new "_" format if ($caps = $DB->get_records('capabilities')) { foreach ($caps as $cap) { $cap->component = str_replace('/', '_', $cap->component); $DB->update_record('capabilities', $cap); } } unset($caps); upgrade_main_savepoint(true, 2009061704); } if ($oldversion < 2009063000) { // upgrade format of _with_advanced settings - quiz only // note: this can be removed later, not needed for upgrades from 1.9.x if ($quiz = get_config('quiz')) { foreach ($quiz as $name => $value) { if (strpos($name, 'fix_') !== 0) { continue; } $newname = substr($name, 4) . '_adv'; set_config($newname, $value, 'quiz'); unset_config($name, 'quiz'); } } upgrade_main_savepoint(true, 2009063000); } if ($oldversion < 2009071000) { /// Rename field contextid on table block_instances to parentcontextid $table = new xmldb_table('block_instances'); $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname'); /// Launch rename field parentcontextid $dbman->rename_field($table, $field, 'parentcontextid'); /// Main savepoint reached upgrade_main_savepoint(true, 2009071000); } if ($oldversion < 2009071600) { /// Define field summaryformat to be added to post $table = new xmldb_table('post'); $field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'format'); /// Conditionally launch add field summaryformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2009071600); } if ($oldversion < 2009072400) { /// Define table comments to be created $table = new xmldb_table('comments'); /// Adding fields to table comments $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('commentarea', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table comments $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for comments if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2009072400); } /** * This upgrade is to set up the new navigation blocks that have been developed * as part of Moodle 2.0 * Now I [Sam Hemelryk] hit a conundrum while exploring how to go about this * as not only do we want to install the new blocks but we also want to set up * default instances of them, and at the same time remove instances of the blocks * that were/will-be outmoded by the two new navigation blocks. * After talking it through with Tim Hunt {@link http://moodle.org/mod/cvsadmin/view.php?conversationid=3112} * we decided that the best way to go about this was to put the bulk of the * upgrade operation into core upgrade `here` but to let the plugins block * still install the blocks. * This leaves one hairy end in that we will create block_instances within the * DB before the blocks themselves are created within the DB */ if ($oldversion < 2009082800) { echo $OUTPUT->notification(get_string('navigationupgrade', 'admin')); // Get the system context so we can set the block instances to it $syscontext = get_context_instance(CONTEXT_SYSTEM); // An array to contain the new block instances we will create $newblockinstances = array('globalnavigation' => new stdClass(), 'settingsnavigation' => new stdClass()); // The new global navigation block instance as a stdClass $newblockinstances['globalnavigation']->blockname = 'global_navigation_tree'; $newblockinstances['globalnavigation']->parentcontextid = $syscontext->id; // System context $newblockinstances['globalnavigation']->showinsubcontexts = true; // Show absolutely everywhere $newblockinstances['globalnavigation']->pagetypepattern = '*'; // Thats right everywhere $newblockinstances['globalnavigation']->subpagetypepattern = null; $newblockinstances['globalnavigation']->defaultregion = BLOCK_POS_LEFT; $newblockinstances['globalnavigation']->defaultweight = -10; // Try make this first $newblockinstances['globalnavigation']->configdata = ''; // The new settings navigation block instance as a stdClass $newblockinstances['settingsnavigation']->blockname = 'settings_navigation_tree'; $newblockinstances['settingsnavigation']->parentcontextid = $syscontext->id; $newblockinstances['settingsnavigation']->showinsubcontexts = true; $newblockinstances['settingsnavigation']->pagetypepattern = '*'; $newblockinstances['settingsnavigation']->subpagetypepattern = null; $newblockinstances['settingsnavigation']->defaultregion = BLOCK_POS_LEFT; $newblockinstances['settingsnavigation']->defaultweight = -9; // Try make this second $newblockinstances['settingsnavigation']->configdata = ''; // Blocks that are outmoded and for whom the bells will toll... by which I // mean we will delete all instances of $outmodedblocks = array('participants', 'admin_tree', 'activity_modules', 'admin', 'course_list'); $outmodedblocksstring = '\'' . join('\',\'', $outmodedblocks) . '\''; unset($outmodedblocks); // Retrieve the block instance id's and parent contexts, so we can join them an GREATLY // cut down the number of delete queries we will need to run $allblockinstances = $DB->get_recordset_select('block_instances', 'blockname IN (' . $outmodedblocksstring . ')', array(), '', 'id, parentcontextid'); $contextids = array(); $instanceids = array(); // Iterate through all block instances foreach ($allblockinstances as $blockinstance) { if (!in_array($blockinstance->parentcontextid, $contextids)) { $contextids[] = $blockinstance->parentcontextid; // If we have over 1000 contexts clean them up and reset the array // this ensures we don't hit any nasty memory limits or such if (count($contextids) > 1000) { upgrade_cleanup_unwanted_block_contexts($contextids); $contextids = array(); } } if (!in_array($blockinstance->id, $instanceids)) { $instanceids[] = $blockinstance->id; // If we have more than 1000 block instances now remove all block positions // and empty the array if (count($contextids) > 1000) { $instanceidstring = join(',', $instanceids); $DB->delete_records_select('block_positions', 'blockinstanceid IN (' . $instanceidstring . ')'); $instanceids = array(); } } } upgrade_cleanup_unwanted_block_contexts($contextids); $instanceidstring = join(',', $instanceids); $DB->delete_records_select('block_positions', 'blockinstanceid IN (' . $instanceidstring . ')'); unset($allblockinstances); unset($contextids); unset($instanceids); unset($instanceidstring); // Now remove the actual block instance $DB->delete_records_select('block_instances', 'blockname IN (' . $outmodedblocksstring . ')'); unset($outmodedblocksstring); // Insert the new block instances. Remember they have not been installed yet // however this should not be a problem foreach ($newblockinstances as $blockinstance) { $blockinstance->id = $DB->insert_record('block_instances', $blockinstance); // Ensure the block context is created. get_context_instance(CONTEXT_BLOCK, $blockinstance->id); } unset($newblockinstances); upgrade_main_savepoint(true, 2009082800); // The end of the navigation upgrade } if ($oldversion < 2009100602) { /// Define table external_functions to be created $table = new xmldb_table('external_functions'); /// Adding fields to table external_functions $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); $table->add_field('classname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('methodname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('classpath', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); /// Adding keys to table external_functions $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table external_functions $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name')); /// Launch create table for external_functions $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009100602); } if ($oldversion < 2009100603) { /// Define table external_services to be created $table = new xmldb_table('external_services'); /// Adding fields to table external_services $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('requiredcapability', XMLDB_TYPE_CHAR, '150', null, null, null, null); $table->add_field('restrictedusers', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); /// Adding keys to table external_services $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table external_services $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name')); /// Launch create table for external_services $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009100603); } if ($oldversion < 2009100604) { /// Define table external_services_functions to be created $table = new xmldb_table('external_services_functions'); /// Adding fields to table external_services_functions $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('functionname', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); /// Adding keys to table external_services_functions $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id')); /// Launch create table for external_services_functions $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009100604); } if ($oldversion < 2009100605) { /// Define table external_services_users to be created $table = new xmldb_table('external_services_users'); /// Adding fields to table external_services_users $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); /// Adding keys to table external_services_users $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Launch create table for external_services_users $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009100605); } if ($oldversion < 2009102600) { /// Define table external_tokens to be created $table = new xmldb_table('external_tokens'); /// Adding fields to table external_tokens $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('token', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null); $table->add_field('tokentype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, null, null, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('creatorid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('lastaccess', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); /// Adding keys to table external_tokens $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); $table->add_key('creatorid', XMLDB_KEY_FOREIGN, array('creatorid'), 'user', array('id')); /// Launch create table for external_tokens $dbman->create_table($table); /// Main savepoint reached upgrade_main_savepoint(true, 2009102600); } if ($oldversion < 2009103000) { /// Define table blog_association to be created $table = new xmldb_table('blog_association'); /// Adding fields to table blog_association $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('blogid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table blog_association $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); $table->add_key('blogid', XMLDB_KEY_FOREIGN, array('blogid'), 'post', array('id')); /// Conditionally launch create table for blog_association if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table blog_external to be created $table = new xmldb_table('blog_external'); /// Adding fields to table blog_external $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('url', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('filtertags', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('failedlastsync', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timefetched', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table blog_external $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Conditionally launch create table for blog_external if ($dbman->table_exists($table)) { // Delete the existing one first (comes from early dev version) $dbman->drop_table($table); } $dbman->create_table($table); // now inform admins that some settings require attention after upgrade if (($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete)) { echo $OUTPUT->notification(get_string('bloglevelupgradenotice', 'admin')); $site = get_site(); $a = new StdClass(); $a->sitename = $site->fullname; $a->fixurl = "{$CFG->wwwroot}/{$CFG->admin}/bloglevelupgrade.php"; $subject = get_string('bloglevelupgrade', 'admin'); $description = get_string('bloglevelupgradedescription', 'admin', $a); // can not use messaging here because it is not configured yet! upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description); } /// Main savepoint reached upgrade_main_savepoint(true, 2009103000); } if ($oldversion < 2009110400) { // list of tables where we need to add new format field and convert texts $extendtables = array('course' => 'summary', 'course_categories' => 'description', 'course_categories' => 'description', 'course_request' => 'summary', 'grade_outcomes' => 'description', 'groups' => 'description', 'groupings' => 'description', 'scale' => 'description', 'user_info_field' => 'description', 'user_info_field' => 'defaultdata', 'user_info_data' => 'data'); foreach ($extendtables as $tablestr => $fieldstr) { $formatfieldstr = $fieldstr . 'format'; $table = new xmldb_table($tablestr); $field = new xmldb_field($formatfieldstr, XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', $fieldstr); // Check that the field doesn't already exists if (!$dbman->field_exists($table, $field)) { // Add the new field $dbman->add_field($table, $field); } if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset($tablestr, array($formatfieldstr => FORMAT_MOODLE), '', "id,{$fieldstr},{$formatfieldstr}"); foreach ($rs as $rec) { $rec->{$fieldstr} = text_to_html($rec->{$fieldstr}, false, false, true); $rec->{$formatfieldstr} = FORMAT_HTML; $DB->update_record($tablestr, $rec); upgrade_set_timeout(); } $rs->close(); unset($rs); } } unset($rec); unset($extendtables); upgrade_main_savepoint(true, 2009110400); } if ($oldversion < 2009110401) { $table = new xmldb_table('user'); // Change the precision of the description field first up. // This may grow! $field = new xmldb_field('description', XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'url'); $dbman->change_field_precision($table, $field); $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description'); // Check that the field doesn't already exists if (!$dbman->field_exists($table, $field)) { // Add the new field $dbman->add_field($table, $field); } if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('user', array('descriptionformat' => FORMAT_MOODLE, 'deleted' => 0, 'htmleditor' => 1), '', "id,description,descriptionformat"); foreach ($rs as $rec) { $rec->description = text_to_html($rec->description, false, false, true); $rec->descriptionformat = FORMAT_HTML; $DB->update_record('user', $rec); upgrade_set_timeout(); } $rs->close(); } upgrade_main_savepoint(true, 2009110401); } if ($oldversion < 2009112400) { if (empty($CFG->passwordsaltmain)) { $subject = get_string('check_passwordsaltmain_name', 'report_security'); $description = get_string('check_passwordsaltmain_warning', 'report_security'); upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description); } upgrade_main_savepoint(true, 2009112400); } if ($oldversion < 2010011200) { $table = new xmldb_table('grade_categories'); $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'timemodified'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_main_savepoint(true, 2010011200); } if ($oldversion < 2010012500) { upgrade_fix_incorrect_mnethostids(); upgrade_main_savepoint(true, 2010012500); } if ($oldversion < 2010012600) { // do stuff to the mnet table $table = new xmldb_table('mnet_rpc'); $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path'); $dbman->rename_field($table, $field, 'plugintype'); $field = new xmldb_field('parent', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path'); $dbman->rename_field($table, $field, 'pluginname'); $field = new xmldb_field('filename', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'profile'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('classname', XMLDB_TYPE_CHAR, '150', null, null, null, null, 'filename'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('static', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'classname'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010012600); } if ($oldversion < 2010012900) { /// Define table mnet_remote_rpc to be created $table = new xmldb_table('mnet_remote_rpc'); /// Adding fields to table mnet_remote_rpc $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('functionname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); $table->add_field('xmlrpcpath', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null); /// Adding keys to table mnet_remote_rpc $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for mnet_remote_rpc if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table mnet_remote_service2rpc to be created $table = new xmldb_table('mnet_remote_service2rpc'); /// Adding fields to table mnet_remote_service2rpc $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table mnet_remote_service2rpc $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table mnet_remote_service2rpc $table->add_index('rpcid_serviceid', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid')); /// Conditionally launch create table for mnet_remote_service2rpc if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Rename field function_name on table mnet_rpc to functionname $table = new xmldb_table('mnet_rpc'); $field = new xmldb_field('function_name', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id'); /// Launch rename field function_name $dbman->rename_field($table, $field, 'functionname'); /// Rename field xmlrpc_path on table mnet_rpc to xmlrpcpath $table = new xmldb_table('mnet_rpc'); $field = new xmldb_field('xmlrpc_path', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null, 'function_name'); /// Launch rename field xmlrpc_path $dbman->rename_field($table, $field, 'xmlrpcpath'); /// Main savepoint reached upgrade_main_savepoint(true, 2010012900); } if ($oldversion < 2010012901) { /// Define field plugintype to be added to mnet_remote_rpc $table = new xmldb_table('mnet_remote_rpc'); $field = new xmldb_field('plugintype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpcpath'); /// Conditionally launch add field plugintype if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field pluginname to be added to mnet_remote_rpc $field = new xmldb_field('pluginname', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'plugintype'); /// Conditionally launch add field pluginname if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010012901); } if ($oldversion < 2010012902) { /// Define field enabled to be added to mnet_remote_rpc $table = new xmldb_table('mnet_remote_rpc'); $field = new xmldb_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, 'pluginname'); /// Conditionally launch add field enabled if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010012902); } /// MDL-17863. Increase the portno column length on mnet_host to handle any port number if ($oldversion < 2010020100) { /// Changing precision of field portno on table mnet_host to (5) $table = new xmldb_table('mnet_host'); $field = new xmldb_field('portno', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'transport'); /// Launch change of precision for field portno $dbman->change_field_precision($table, $field); upgrade_main_savepoint(true, 2010020100); } if ($oldversion < 2010020300) { /// Define field timecreated to be added to user $table = new xmldb_table('user'); $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'trackforums'); if (!$dbman->field_exists($table, $field)) { /// Launch add field timecreated $dbman->add_field($table, $field); $DB->execute("UPDATE {user} SET timecreated = firstaccess"); $sql = "UPDATE {user} SET timecreated = " . time() . " where timecreated = 0"; $DB->execute($sql); } upgrade_main_savepoint(true, 2010020300); } // MDL-21407. Trim leading spaces from default tex latexpreamble causing problems under some confs if ($oldversion < 2010020301) { if ($preamble = $CFG->filter_tex_latexpreamble) { $preamble = preg_replace('/^ +/m', '', $preamble); set_config('filter_tex_latexpreamble', $preamble); } upgrade_main_savepoint(true, 2010020301); } if ($oldversion < 2010021400) { /// Changes to modinfo mean we need to rebuild course cache require_once $CFG->dirroot . '/course/lib.php'; rebuild_course_cache(0, true); upgrade_main_savepoint(true, 2010021400); } if ($oldversion < 2010021800) { $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle')); upgrade_main_savepoint(true, 2010021800); } if ($oldversion < 2010031900) { // regeneration of sessions is always enabled, no need for this setting any more unset_config('regenloginsession'); upgrade_main_savepoint(true, 2010031900); } if ($oldversion < 2010033101.02) { /// Define table license to be created $table = new xmldb_table('license'); /// Adding fields to table license $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('fullname', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table->add_field('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); /// Adding keys to table license $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for license if (!$dbman->table_exists($table)) { $dbman->create_table($table); } $active_licenses = array(); $license = new stdClass(); // add unknown license $license->shortname = 'unknown'; $license->fullname = 'Unknown license'; $license->source = ''; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add all rights reserved license $license->shortname = 'allrightsreserved'; $license->fullname = 'All rights reserved'; $license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->id = $record->id; $license->enabled = $record->enabled; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add public domain license $license->shortname = 'public'; $license->fullname = 'Public Domain'; $license->source = 'http://creativecommons.org/licenses/publicdomain/'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add creative commons license $license->shortname = 'cc'; $license->fullname = 'Creative Commons'; $license->source = 'http://creativecommons.org/licenses/by/3.0/'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add creative commons no derivs license $license->shortname = 'cc-nd'; $license->fullname = 'Creative Commons - NoDerivs'; $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add creative commons no commercial no derivs license $license->shortname = 'cc-nc-nd'; $license->fullname = 'Creative Commons - No Commercial NoDerivs'; $license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add creative commons no commercial $license->shortname = 'cc-nc-nd'; $license->shortname = 'cc-nc'; $license->fullname = 'Creative Commons - No Commercial'; $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add creative commons no commercial sharealike $license->shortname = 'cc-nc-sa'; $license->fullname = 'Creative Commons - No Commercial ShareAlike'; $license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } // add creative commons sharealike $license->shortname = 'cc-sa'; $license->fullname = 'Creative Commons - ShareAlike'; $license->source = 'http://creativecommons.org/licenses/by-sa/3.0/'; $license->enabled = 1; $license->version = '2010033100'; $active_licenses[] = $license->shortname; if ($record = $DB->get_record('license', array('shortname' => $license->shortname))) { if ($record->version < $license->version) { // update license record $license->enabled = $record->enabled; $license->id = $record->id; $DB->update_record('license', $license); } } else { $DB->insert_record('license', $license); } set_config('licenses', implode(',', $active_licenses)); /// set site default license set_config('sitedefaultlicense', 'allrightsreserved'); /// Main savepoint reached upgrade_main_savepoint(true, 2010033101.02); } if ($oldversion < 2010033102.0) { // rename course view capability to participate $params = array('viewcap' => 'moodle/course:view', 'participatecap' => 'moodle/course:participate'); $sql = "UPDATE {role_capabilities} SET capability = :participatecap WHERE capability = :viewcap"; $DB->execute($sql, $params); $sql = "UPDATE {capabilities} SET name = :participatecap WHERE name = :viewcap"; $DB->execute($sql, $params); // note: the view capability is readded again at the end of upgrade, but with different meaning upgrade_main_savepoint(true, 2010033102.0); } if ($oldversion < 2010033102.01) { // Define field archetype to be added to role table $table = new xmldb_table('role'); $field = new xmldb_field('archetype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, 'sortorder'); $dbman->add_field($table, $field); upgrade_main_savepoint(true, 2010033102.01); } if ($oldversion < 2010033102.02) { // Set archetype for existing roles and change admin role to manager role $sql = "SELECT r.*, rc.capability\n FROM {role} r\n JOIN {role_capabilities} rc ON rc.roleid = r.id\n WHERE rc.contextid = :syscontextid AND rc.capability LIKE :legacycaps\n ORDER BY r.id"; $params = array('syscontextid' => SYSCONTEXTID, 'legacycaps' => 'moodle/legacy:%'); $substart = strlen('moodle/legacy:'); $roles = $DB->get_recordset_sql($sql, $params); // in theory could be multiple legacy flags in one role foreach ($roles as $role) { $role->archetype = substr($role->capability, $substart); unset($role->capability); if ($role->archetype === 'admin') { $i = ''; if ($DB->record_exists('role', array('shortname' => 'manager')) or $DB->record_exists('role', array('name' => get_string('manager', 'role')))) { $i = 2; while ($DB->record_exists('role', array('shortname' => 'manager' . $i)) or $DB->record_exists('role', array('name' => get_string('manager', 'role') . $i))) { $i++; } } $role->archetype = 'manager'; if ($role->shortname === 'admin') { $role->shortname = 'manager' . $i; $role->name = get_string('manager', 'role') . $i; $role->description = get_string('managerdescription', 'role'); } } $DB->update_record('role', $role); } $roles->close(); upgrade_main_savepoint(true, 2010033102.02); } if ($oldversion < 2010033102.03) { // Now pick site admins (===have manager role assigned at the system context) // and store them in the new $CFG->siteadmins setting as comma separated list $sql = "SELECT ra.id, ra.userid\n FROM {role_assignments} ra\n JOIN {role} r ON r.id = ra.roleid\n JOIN {user} u ON u.id = ra.userid\n WHERE ra.contextid = :syscontext AND r.archetype = 'manager' AND u.deleted = 0\n ORDER BY ra.id"; $ras = $DB->get_records_sql($sql, array('syscontext' => SYSCONTEXTID)); $admins = array(); foreach ($ras as $ra) { $admins[$ra->userid] = $ra->userid; set_config('siteadmins', implode(',', $admins)); // better to save it repeatedly, we do need at least one admin $DB->delete_records('role_assignments', array('id' => $ra->id)); } upgrade_main_savepoint(true, 2010033102.03); } if ($oldversion < 2010033102.04) { // clean up the manager roles $managers = $DB->get_records('role', array('archetype' => 'manager')); foreach ($managers as $manager) { // now sanitize the capabilities and overrides $DB->delete_records('role_capabilities', array('capability' => 'moodle/site:config', 'roleid' => $manager->id)); // only site admins may configure servers // note: doanything and legacy caps are deleted automatically, they get moodle/course:view later at the end of the upgrade // remove manager role assignments bellow the course context level - admin role was never intended for activities and blocks, // the problem is that those assignments would not be visible after upgrade and old style admins in activities make no sense anyway $DB->delete_records_select('role_assignments', "roleid = :manager AND contextid IN (SELECT id FROM {context} WHERE contextlevel > 50)", array('manager' => $manager->id)); // allow them to assign all roles except default user, guest and frontpage - users get these roles automatically on the fly when needed $DB->delete_records('role_allow_assign', array('roleid' => $manager->id)); $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype <> 'user' AND archetype <> 'guest' AND archetype <> 'frontpage'"); foreach ($roles as $role) { $record = (object) array('roleid' => $manager->id, 'allowassign' => $role->id); $DB->insert_record('role_allow_assign', $record); } // allow them to override all roles $DB->delete_records('role_allow_override', array('roleid' => $manager->id)); $roles = $DB->get_records_sql("SELECT * FROM {role}"); foreach ($roles as $role) { $record = (object) array('roleid' => $manager->id, 'allowoverride' => $role->id); $DB->insert_record('role_allow_override', $record); } // allow them to switch to all following roles $DB->delete_records('role_allow_switch', array('roleid' => $manager->id)); $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype IN ('student', 'teacher', 'editingteacher')"); foreach ($roles as $role) { $record = (object) array('roleid' => $manager->id, 'allowswitch' => $role->id); $DB->insert_record('role_allow_switch', $record); } } upgrade_main_savepoint(true, 2010033102.04); } if ($oldversion < 2010033102.05) { // remove course:view from all roles that are not used for enrolment, it does NOT belong there because it really means user is enrolled! $noenrolroles = $DB->get_records_select('role', "archetype IN ('guest', 'user', 'manager', 'coursecreator', 'frontpage')"); foreach ($noenrolroles as $role) { $DB->delete_records('role_capabilities', array('roleid' => $role->id, 'capability' => 'moodle/course:participate')); } upgrade_main_savepoint(true, 2010033102.05); } if ($oldversion < 2010033102.06) { // make sure there is nothing weird in default user role if (!empty($CFG->defaultuserroleid)) { if ($role = $DB->get_record('role', array('id' => $CFG->defaultuserroleid))) { if ($role->archetype !== '' and $role->archetype !== 'user') { upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default authenticated user role (defaultuserroleid) value is invalid, setting cleared.'); unset_config('defaultuserroleid'); } } else { unset_config('defaultuserroleid'); } } upgrade_main_savepoint(true, 2010033102.06); } if ($oldversion < 2010033102.07) { if (!empty($CFG->displayloginfailures) and $CFG->displayloginfailures === 'teacher') { upgrade_log(UPGRADE_LOG_NOTICE, null, 'Displaying of login failuters to teachers is not supported any more.'); unset_config('displayloginfailures'); } upgrade_main_savepoint(true, 2010033102.07); } if ($oldversion < 2010033102.08) { // make sure there are no problems in default guest role settings if (!empty($CFG->guestroleid)) { if ($role = $DB->get_record('role', array('id' => $CFG->guestroleid))) { if ($role->archetype !== '' and $role->archetype !== 'guest') { upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default guest role (guestroleid) value is invalid, setting cleared.'); unset_config('guestroleid'); } } else { upgrade_log(UPGRADE_LOG_NOTICE, null, 'Role specified in Default guest role (guestroleid) does not exist, setting cleared.'); unset_config('guestroleid'); } } // remove all roles of the guest account - the only way to change it is to override the guest role, sorry // the guest account gets all the role assignments on the fly which works fine in has_capability(), $DB->delete_records_select('role_assignments', "userid IN (SELECT id FROM {user} WHERE username = '******')"); upgrade_main_savepoint(true, 2010033102.08); } /// New table for storing which roles can be assigned in which contexts. if ($oldversion < 2010033102.09) { /// Define table role_context_levels to be created $table = new xmldb_table('role_context_levels'); /// Adding fields to table role_context_levels $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table role_context_levels $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid')); $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); /// Conditionally launch create table for role_context_levels if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2010033102.09); } if ($oldversion < 2010033102.1) { // Now populate the role_context_levels table with the default values // NOTE: do not use accesslib methods here $rolecontextlevels = array(); $defaults = array('manager' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE), 'coursecreator' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT), 'editingteacher' => array(CONTEXT_COURSE, CONTEXT_MODULE), 'teacher' => array(CONTEXT_COURSE, CONTEXT_MODULE), 'student' => array(CONTEXT_COURSE, CONTEXT_MODULE), 'guest' => array(), 'user' => array(), 'frontpage' => array()); $roles = $DB->get_records('role', array(), '', 'id, archetype'); foreach ($roles as $role) { if (isset($defaults[$role->archetype])) { $rolecontextlevels[$role->id] = $defaults[$role->archetype]; } } // add roles without archetypes, it may contain weird things, but we can not fix them list($narsql, $params) = $DB->get_in_or_equal(array_keys($defaults), SQL_PARAMS_NAMED, 'ar', false); $sql = "SELECT DISTINCT ra.roleid, con.contextlevel\n FROM {role_assignments} ra\n JOIN {context} con ON ra.contextid = con.id\n JOIN {role} r ON r.id = ra.roleid\n WHERE r.archetype {$narsql}"; $existingrolecontextlevels = $DB->get_recordset_sql($sql, $params); foreach ($existingrolecontextlevels as $rcl) { if (!isset($rolecontextlevels[$rcl->roleid])) { $rolecontextlevels[$rcl->roleid] = array(); } $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel; } $existingrolecontextlevels->close(); // Put the data into the database. $rcl = new stdClass(); foreach ($rolecontextlevels as $roleid => $contextlevels) { $rcl->roleid = $roleid; foreach ($contextlevels as $level) { $rcl->contextlevel = $level; $DB->insert_record('role_context_levels', $rcl, false); } } // release memory!! unset($roles); unset($defaults); unset($rcl); unset($existingrolecontextlevels); unset($rolecontextlevels); // Main savepoint reached upgrade_main_savepoint(true, 2010033102.1); } if ($oldversion < 2010040700) { // migrate old groupings --> groupmembersonly setting if (isset($CFG->enablegroupings)) { set_config('enablegroupmembersonly', $CFG->enablegroupings); unset_config('enablegroupings'); } // Main savepoint reached upgrade_main_savepoint(true, 2010040700); } if ($oldversion < 2010040900) { // Changing the default of field lang on table user to good old "en" $table = new xmldb_table('user'); $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'en', 'country'); // Launch change of default for field lang $dbman->change_field_default($table, $field); // update main site lang if (strpos($CFG->lang, '_utf8') !== false) { $lang = str_replace('_utf8', '', $CFG->lang); set_config('lang', $lang); } // tweak langlist if (!empty($CFG->langlist)) { $langs = explode(',', $CFG->langlist); foreach ($langs as $key => $lang) { $lang = str_replace('_utf8', '', $lang); $langs[$key] = $lang; } set_config('langlist', implode(',', $langs)); } // Main savepoint reached upgrade_main_savepoint(true, 2010040900); } if ($oldversion < 2010040901) { // Remove "_utf8" suffix from all langs in user table $langs = $DB->get_records_sql("SELECT DISTINCT lang FROM {user} WHERE lang LIKE ?", array('%_utf8')); foreach ($langs as $lang => $unused) { $newlang = str_replace('_utf8', '', $lang); $sql = "UPDATE {user} SET lang = :newlang WHERE lang = :lang"; $DB->execute($sql, array('newlang' => $newlang, 'lang' => $lang)); } // Main savepoint reached upgrade_main_savepoint(true, 2010040901); } if ($oldversion < 2010041301) { $sql = "UPDATE {block} SET name=? WHERE name=?"; $DB->execute($sql, array('navigation', 'global_navigation_tree')); $DB->execute($sql, array('settings', 'settings_navigation_tree')); $sql = "UPDATE {block_instances} SET blockname=? WHERE blockname=?"; $DB->execute($sql, array('navigation', 'global_navigation_tree')); $DB->execute($sql, array('settings', 'settings_navigation_tree')); upgrade_main_savepoint(true, 2010041301); } if ($oldversion < 2010042100) { /// Define table backup_controllers to be created $table = new xmldb_table('backup_controllers'); /// Adding fields to table backup_controllers $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('type', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null); $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('format', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); $table->add_field('interactive', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('purpose', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('status', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('execution', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('executiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('checksum', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('controller', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null); /// Adding keys to table backup_controllers $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('backupid_uk', XMLDB_KEY_UNIQUE, array('backupid')); $table->add_key('userid_fk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Adding indexes to table backup_controllers $table->add_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid')); /// Conditionally launch create table for backup_controllers if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table backup_ids_template to be created $table = new xmldb_table('backup_ids_template'); /// Adding fields to table backup_ids_template $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('itemname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null); $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('parentitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); /// Adding keys to table backup_ids_template $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('backupid_itemname_itemid_uk', XMLDB_KEY_UNIQUE, array('backupid', 'itemname', 'itemid')); /// Adding indexes to table backup_ids_template $table->add_index('backupid_parentitemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'itemname', 'parentitemid')); /// Conditionally launch create table for backup_controllers if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2010042100); } if ($oldversion < 2010042301) { $table = new xmldb_table('course_sections'); $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'section'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_main_savepoint(true, 2010042301); } if ($oldversion < 2010042302) { // Define table cohort to be created $table = new xmldb_table('cohort'); // Adding fields to table cohort $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '254', null, XMLDB_NOTNULL, null, null); $table->add_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); // Adding keys to table cohort $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('context', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); // Conditionally launch create table for cohort if (!$dbman->table_exists($table)) { $dbman->create_table($table); } upgrade_main_savepoint(true, 2010042302); } if ($oldversion < 2010042303) { // Define table cohort_members to be created $table = new xmldb_table('cohort_members'); // Adding fields to table cohort_members $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timeadded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); // Adding keys to table cohort_members $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('cohortid', XMLDB_KEY_FOREIGN, array('cohortid'), 'cohort', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); // Adding indexes to table cohort_members $table->add_index('cohortid-userid', XMLDB_INDEX_UNIQUE, array('cohortid', 'userid')); // Conditionally launch create table for cohort_members if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Main savepoint reached upgrade_main_savepoint(true, 2010042303); } if ($oldversion < 2010042800) { //drop the previously created ratings table $table = new xmldb_table('ratings'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } //create the rating table (replaces module specific rating implementations) $table = new xmldb_table('rating'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Adding fields to table rating $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('scaleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('rating', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table rating $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); /// Adding indexes to table rating $table->add_index('itemid', XMLDB_INDEX_NOTUNIQUE, array('itemid')); /// Create table for ratings if (!$dbman->table_exists($table)) { $dbman->create_table($table); } upgrade_main_savepoint(true, 2010042800); } if ($oldversion < 2010042801) { // migrating old comments block content $DB->execute("UPDATE {comments}\n SET contextid = (SELECT parentcontextid\n FROM {block_instances}\n WHERE id = {comments}.itemid AND blockname = 'comments'),\n commentarea = 'page_comments',\n itemid = 0\n WHERE commentarea = 'block_comments'\n AND itemid != 0\n AND EXISTS (SELECT 'x'\n FROM {block_instances}\n WHERE id = {comments}.itemid\n AND blockname = 'comments')"); // remove all orphaned record $DB->delete_records('comments', array('commentarea' => 'block_comments')); upgrade_main_savepoint(true, 2010042801); } if ($oldversion < 2010042802) { // Change backup_controllers->type to varchar10 (recreate dep. index) /// Define index typeitem_ix (not unique) to be dropped form backup_controllers $table = new xmldb_table('backup_controllers'); $index = new xmldb_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid')); /// Conditionally launch drop index typeitem_ix if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } /// Changing precision of field type on table backup_controllers to (10) $table = new xmldb_table('backup_controllers'); $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'backupid'); /// Launch change of precision for field type $dbman->change_field_precision($table, $field); /// Define index typeitem_ix (not unique) to be added to backup_controllers $table = new xmldb_table('backup_controllers'); $index = new xmldb_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid')); /// Conditionally launch add index typeitem_ix if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Main savepoint reached upgrade_main_savepoint(true, 2010042802); } if ($oldversion < 2010043000) { // Adding new course completion feature /// Add course completion tables /// Define table course_completion_aggr_methd to be created $table = new xmldb_table('course_completion_aggr_methd'); /// Adding fields to table course_completion_aggr_methd $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('criteriatype', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null); $table->add_field('method', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('value', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); /// Adding keys to table course_completion_aggr_methd $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table course_completion_aggr_methd $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); $table->add_index('criteriatype', XMLDB_INDEX_NOTUNIQUE, array('criteriatype')); /// Conditionally launch create table for course_completion_aggr_methd if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table course_completion_criteria to be created $table = new xmldb_table('course_completion_criteria'); /// Adding fields to table course_completion_criteria $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('criteriatype', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('module', XMLDB_TYPE_CHAR, '100', null, null, null, null); $table->add_field('moduleinstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('courseinstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('enrolperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timeend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); $table->add_field('role', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); /// Adding keys to table course_completion_criteria $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table course_completion_criteria $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); /// Conditionally launch create table for course_completion_criteria if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table course_completion_crit_compl to be created $table = new xmldb_table('course_completion_crit_compl'); /// Adding fields to table course_completion_crit_compl $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('criteriaid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('gradefinal', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); $table->add_field('unenroled', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('deleted', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); $table->add_field('timecompleted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); /// Adding keys to table course_completion_crit_compl $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table course_completion_crit_compl $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); $table->add_index('criteriaid', XMLDB_INDEX_NOTUNIQUE, array('criteriaid')); $table->add_index('timecompleted', XMLDB_INDEX_NOTUNIQUE, array('timecompleted')); /// Conditionally launch create table for course_completion_crit_compl if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table course_completion_notify to be created $table = new xmldb_table('course_completion_notify'); /// Adding fields to table course_completion_notify $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('role', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('message', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('timesent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table course_completion_notify $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table course_completion_notify $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); /// Conditionally launch create table for course_completion_notify if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Define table course_completions to be created $table = new xmldb_table('course_completions'); /// Adding fields to table course_completions $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('deleted', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); $table->add_field('timenotified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('timeenrolled', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timestarted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timecompleted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('reaggregate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table course_completions $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table course_completions $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); $table->add_index('timecompleted', XMLDB_INDEX_NOTUNIQUE, array('timecompleted')); /// Conditionally launch create table for course_completions if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Add cols to course table /// Define field enablecompletion to be added to course $table = new xmldb_table('course'); $field = new xmldb_field('enablecompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole'); /// Conditionally launch add field enablecompletion if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field completionstartonenrol to be added to course $field = new xmldb_field('completionstartonenrol', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'enablecompletion'); /// Conditionally launch add field completionstartonenrol if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field completionnotify to be added to course $field = new xmldb_field('completionnotify', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'enablecompletion'); /// Conditionally launch add field completionnotify if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_main_savepoint(true, 2010043000); } if ($oldversion < 2010043001) { /// Define table registration_hubs to be created $table = new xmldb_table('registration_hubs'); /// Adding fields to table registration_hubs $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('token', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); $table->add_field('hubname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('huburl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('confirmed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table registration_hubs $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for registration_hubs if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2010043001); } if ($oldversion < 2010050200) { /// Define table backup_logs to be created $table = new xmldb_table('backup_logs'); /// Adding fields to table backup_logs $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('loglevel', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('message', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table backup_logs $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('backupid', XMLDB_KEY_FOREIGN, array('backupid'), 'backup_controllers', array('backupid')); /// Adding indexes to table backup_logs $table->add_index('backupid-id', XMLDB_INDEX_UNIQUE, array('backupid', 'id')); /// Conditionally launch create table for backup_logs if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Drop some old backup tables, not used anymore /// Define table backup_files to be dropped $table = new xmldb_table('backup_files'); /// Conditionally launch drop table for backup_files if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Define table backup_ids to be dropped $table = new xmldb_table('backup_ids'); /// Conditionally launch drop table for backup_ids if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2010050200); } if ($oldversion < 2010050403) { // my_pages for My Moodle and Public Profile pages /// Define table my_pages to be created $table = new xmldb_table('my_pages'); /// Adding fields to table my_pages $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, 0); $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); $table->add_field('private', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '6', null, XMLDB_NOTNULL, null, '0'); /// Adding keys to table my_pages $table->add_key('id', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table my_pages $table->add_index('useridprivate', XMLDB_INDEX_NOTUNIQUE, array('userid', 'private')); /// Conditionally launch create table for my_pages if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Add two lines of data into this new table. These are the default pages. $mypage = new stdClass(); $mypage->userid = NULL; $mypage->name = '__default'; $mypage->private = 0; $mypage->sortorder = 0; if (!$DB->record_exists('my_pages', array('userid' => NULL, 'private' => 0))) { $DB->insert_record('my_pages', $mypage); } $mypage->private = 1; if (!$DB->record_exists('my_pages', array('userid' => NULL, 'private' => 1))) { $DB->insert_record('my_pages', $mypage); } /// This bit is a "illegal" hack, unfortunately, but there is not a better way to install default /// blocks right now, since the upgrade function need to be called after core AND plugins upgrade, /// and there is no such hook yet. Sigh. if ($mypage = $DB->get_record('my_pages', array('userid' => NULL, 'private' => 1))) { if (!$DB->record_exists('block_instances', array('pagetypepattern' => 'my-index', 'parentcontextid' => SITEID, 'subpagepattern' => $mypage->id))) { // No default exist there yet, let's put a few into My Moodle so it's useful. $blockinstance = new stdClass(); $blockinstance->parentcontextid = SYSCONTEXTID; $blockinstance->showinsubcontexts = 0; $blockinstance->pagetypepattern = 'my-index'; $blockinstance->subpagepattern = $mypage->id; $blockinstance->configdata = ''; $blockinstance->blockname = 'private_files'; $blockinstance->defaultregion = 'side-post'; $blockinstance->defaultweight = 0; $blockinstanceid = $DB->insert_record('block_instances', $blockinstance); get_context_instance(CONTEXT_BLOCK, $blockinstanceid); $blockinstance->blockname = 'online_users'; $blockinstance->defaultregion = 'side-post'; $blockinstance->defaultweight = 1; $blockinstanceid = $DB->insert_record('block_instances', $blockinstance); get_context_instance(CONTEXT_BLOCK, $blockinstanceid); $blockinstance->blockname = 'course_overview'; $blockinstance->defaultregion = 'content'; $blockinstance->defaultweight = 0; $blockinstanceid = $DB->insert_record('block_instances', $blockinstance); get_context_instance(CONTEXT_BLOCK, $blockinstanceid); } } /// Main savepoint reached upgrade_main_savepoint(true, 2010050403); } if ($oldversion < 2010051500) { /// Fix a bad table name that existed for a few days in HEAD $table = new xmldb_table('published_courses'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } /// Define table course_published to be created $table = new xmldb_table('course_published'); /// Adding fields to table course_published $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('hubid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timepublished', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('enrollable', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table->add_field('hubcourseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table course_published $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Conditionally launch create table for course_published if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /// Main savepoint reached upgrade_main_savepoint(true, 2010051500); } if ($oldversion < 2010051600) { /// Delete the blocks completely. All the contexts, instances etc were cleaned up above in 2009082800 $DB->delete_records('block', array('name' => 'admin')); $DB->delete_records('block', array('name' => 'admin_tree')); /// Main savepoint reached upgrade_main_savepoint(true, 2010051600); } if ($oldversion < 2010051800) { // switching to userid in config settings because user names are not unique and reliable enough if (!empty($CFG->courserequestnotify) and $CFG->courserequestnotify !== '$@NONE@$' and $CFG->courserequestnotify !== '$@ALL@$') { list($where, $params) = $DB->get_in_or_equal(explode(',', $CFG->courserequestnotify)); $params[] = $CFG->mnet_localhost_id; $users = $DB->get_fieldset_select('user', 'id', "username {$where} AND mnethostid = ?", $params); if ($users) { set_config('courserequestnotify', implode(',', $users)); } else { set_config('courserequestnotify', '$@NONE@$'); } } upgrade_main_savepoint(true, 2010051800); } if ($oldversion < 2010051801) { // Update the notifyloginfailures setting. if ($CFG->notifyloginfailures == 'mainadmin') { if ($admins = explode(',', $CFG->siteadmins)) { $adminid = reset($admins); set_config('notifyloginfailures', $adminid); } else { unset_config('notifyloginfailures'); // let them choose } unset($admins); } else { if ($CFG->notifyloginfailures == 'alladmins') { set_config('notifyloginfailures', '$@ALL@$'); } else { set_config('notifyloginfailures', '$@NONE@$'); } } upgrade_main_savepoint(true, 2010051801); } if ($oldversion < 2010052100) { // Switch to html purifier as default cleaning engine - KSES is really very bad if (empty($CFG->enablehtmlpurifier)) { unset_config('enablehtmlpurifier'); } upgrade_main_savepoint(true, 2010052100); } if ($oldversion < 2010052200) { // Define field legacyfiles to be added to course - just in case we are upgrading from PR1 $table = new xmldb_table('course'); $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes'); // Conditionally launch add field legacyfiles if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); // enable legacy files in all courses $DB->execute("UPDATE {course} SET legacyfiles = 2"); } // Main savepoint reached upgrade_main_savepoint(true, 2010052200); } if ($oldversion < 2010052401) { /// Define field status to be added to course_published $table = new xmldb_table('course_published'); $field = new xmldb_field('status', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', 'hubcourseid'); /// Conditionally launch add field status if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field timechecked to be added to course_published $table = new xmldb_table('course_published'); $field = new xmldb_field('timechecked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'status'); /// Conditionally launch add field timechecked if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010052401); } if ($oldversion < 2010052700) { /// Define field summaryformat to be added to course sections table $table = new xmldb_table('course_sections'); $field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'summary'); /// Conditionally launch add field summaryformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $DB->set_field('course_sections', 'summaryformat', 1, array()); // originally treated as HTML /// Main savepoint reached upgrade_main_savepoint(true, 2010052700); } if ($oldversion < 2010052800) { /// Changes to modinfo mean we need to rebuild course cache require_once $CFG->dirroot . '/course/lib.php'; rebuild_course_cache(0, true); upgrade_main_savepoint(true, 2010052800); } if ($oldversion < 2010052801) { /// Define field sortorder to be added to files $table = new xmldb_table('files'); $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified'); /// Conditionally launch add field sortorder if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010052801); } if ($oldversion < 2010061900.01) { // Define table enrol to be created $table = new xmldb_table('enrol'); // Adding fields to table enrol $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('enrol', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('enrolperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('enrolstartdate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('enrolenddate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('expirynotify', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('expirythreshold', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('notifyall', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('password', XMLDB_TYPE_CHAR, '50', null, null, null, null); $table->add_field('cost', XMLDB_TYPE_CHAR, '20', null, null, null, null); $table->add_field('currency', XMLDB_TYPE_CHAR, '3', null, null, null, null); $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('customint1', XMLDB_TYPE_INTEGER, '10', null, null, null, null); $table->add_field('customint2', XMLDB_TYPE_INTEGER, '10', null, null, null, null); $table->add_field('customint3', XMLDB_TYPE_INTEGER, '10', null, null, null, null); $table->add_field('customint4', XMLDB_TYPE_INTEGER, '10', null, null, null, null); $table->add_field('customchar1', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('customchar2', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('customdec1', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); $table->add_field('customdec2', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); $table->add_field('customtext1', XMLDB_TYPE_TEXT, 'big', null, null, null, null); $table->add_field('customtext2', XMLDB_TYPE_TEXT, 'big', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); // Adding keys to table enrol $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); // Adding indexes to table enrol $table->add_index('enrol', XMLDB_INDEX_NOTUNIQUE, array('enrol')); // launch create table for enrol $dbman->create_table($table); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.01); } if ($oldversion < 2010061900.02) { // Define table course_participant to be created $table = new xmldb_table('user_enrolments'); // Adding fields to table course_participant $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('enrolid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timeend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '2147483647'); $table->add_field('modifierid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); // Adding keys to table course_participant $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('enrolid', XMLDB_KEY_FOREIGN, array('enrolid'), 'enrol', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $table->add_key('modifierid', XMLDB_KEY_FOREIGN, array('modifierid'), 'user', array('id')); // Adding indexes to table user_enrolments $table->add_index('enrolid-userid', XMLDB_INDEX_UNIQUE, array('enrolid', 'userid')); // Launch create table for course_participant $dbman->create_table($table); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.02); } if ($oldversion < 2010061900.03) { // Define field itemid to be added to role_assignments $table = new xmldb_table('role_assignments'); $field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'enrol'); // Launch add field itemid $dbman->add_field($table, $field); // The new enrol plugins may assign one role several times in one context, // if we did not allow it we would have big problems with roles when unenrolling $table = new xmldb_table('role_assignments'); $index = new xmldb_index('contextid-roleid-userid', XMLDB_INDEX_UNIQUE, array('contextid', 'roleid', 'userid')); // Conditionally launch drop index contextid-roleid-userid if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010061900.03); } if ($oldversion < 2010061900.04) { // there is no default course role any more, each enrol plugin has to handle it separately if (!empty($CFG->defaultcourseroleid)) { $sql = "UPDATE {course} SET defaultrole = :defaultrole WHERE defaultrole = 0"; $params = array('defaultrole' => $CFG->defaultcourseroleid); $DB->execute($sql, $params); } unset_config('defaultcourseroleid'); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.04); } if ($oldversion < 2010061900.05) { // make sure enrol settings make actually sense and tweak defaults a bit $sqlempty = $DB->sql_empty(); // set course->enrol to default value so that other upgrade code is simpler $defaultenrol = empty($CFG->enrol) ? 'manual' : $CFG->enrol; $sql = "UPDATE {course} SET enrol = ? WHERE enrol = '{$sqlempty}'"; $DB->execute($sql, array($defaultenrol)); unset_config('enrol'); if (!isset($CFG->enrol_plugins_enabled) or empty($CFG->enrol_plugins_enabled)) { set_config('enrol_plugins_enabled', 'manual'); } else { $enabledplugins = explode(',', $CFG->enrol_plugins_enabled); $enabledplugins = array_unique($enabledplugins); set_config('enrol_plugins_enabled', implode(',', $enabledplugins)); } // Main savepoint reached upgrade_main_savepoint(true, 2010061900.05); } if ($oldversion < 2010061900.06) { $sqlempty = $DB->sql_empty(); $params = array('siteid' => SITEID); // enable manual in all courses $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, enrolperiod, expirynotify, expirythreshold, notifyall, roleid, timecreated, timemodified)\n SELECT 'manual', 0, id, 0, enrolperiod, expirynotify, expirythreshold, notifystudents, defaultrole, timecreated, timemodified\n FROM {course}\n WHERE id <> :siteid"; $DB->execute($sql, $params); // enable self enrol only when course enrollable $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, enrolperiod, enrolstartdate, enrolenddate, expirynotify, expirythreshold,\n notifyall, password, roleid, timecreated, timemodified)\n SELECT 'self', 0, id, 1, enrolperiod, enrolstartdate, enrolenddate, expirynotify, expirythreshold,\n notifystudents, password, defaultrole, timecreated, timemodified\n FROM {course}\n WHERE enrollable = 1 AND id <> :siteid"; $DB->execute($sql, $params); // enable guest access if previously allowed - separately with or without password $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, timecreated, timemodified)\n SELECT 'guest', 0, id, 2, timecreated, timemodified\n FROM {course}\n WHERE guest = 1 AND id <> :siteid"; $DB->execute($sql, $params); $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, password, timecreated, timemodified)\n SELECT 'guest', 0, id, 2, password, timecreated, timemodified\n FROM {course}\n WHERE guest = 2 and password <> '{$sqlempty}' AND id <> :siteid"; $DB->execute($sql, $params); upgrade_main_savepoint(true, 2010061900.06); } if ($oldversion < 2010061900.07) { // now migrate old style "interactive" enrol plugins - we know them by looking into course.enrol $params = array('siteid' => SITEID); $enabledplugins = explode(',', $CFG->enrol_plugins_enabled); $usedplugins = $DB->get_fieldset_sql("SELECT DISTINCT enrol FROM {course}"); foreach ($usedplugins as $plugin) { if ($plugin === 'manual') { continue; } $enabled = in_array($plugin, $enabledplugins) ? 0 : 1; // 0 means active, 1 disabled $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, enrolperiod, enrolstartdate, enrolenddate, expirynotify, expirythreshold,\n notifyall, password, cost, currency, roleid, timecreated, timemodified)\n SELECT enrol, {$enabled}, id, 4, enrolperiod, enrolstartdate, enrolenddate, expirynotify, expirythreshold,\n notifystudents, password, cost, currency, defaultrole, timecreated, timemodified\n FROM {course}\n WHERE enrol = :plugin AND id <> :siteid"; $params['plugin'] = $plugin; $DB->execute($sql, $params); } upgrade_main_savepoint(true, 2010061900.07); } if ($oldversion < 2010061900.08) { // now migrate the rest - these plugins are not in course.enrol, instead we just look for suspicious role assignments, // unfortunately old enrol plugins were doing sometimes weird role assignments :-( // enabled $enabledplugins = explode(',', $CFG->enrol_plugins_enabled); list($sqlenabled, $params) = $DB->get_in_or_equal($enabledplugins, SQL_PARAMS_NAMED, 'ena'); $params['siteid'] = SITEID; $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, enrolperiod, enrolstartdate, enrolenddate, expirynotify, expirythreshold,\n notifyall, password, cost, currency, roleid, timecreated, timemodified)\n SELECT DISTINCT ra.enrol, 0, c.id, 5, c.enrolperiod, c.enrolstartdate, c.enrolenddate, c.expirynotify, c.expirythreshold,\n c.notifystudents, c.password, c.cost, c.currency, c.defaultrole, c.timecreated, c.timemodified\n FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = 50)\n JOIN {role_assignments} ra ON (ra.contextid = ctx.id)\n WHERE c.id <> :siteid AND ra.enrol {$sqlenabled}"; $processed = $DB->get_fieldset_sql("SELECT DISTINCT enrol FROM {enrol}"); if ($processed) { list($sqlnotprocessed, $params2) = $DB->get_in_or_equal($processed, SQL_PARAMS_NAMED, 'np', false); $params = array_merge($params, $params2); $sql = "{$sql} AND ra.enrol {$sqlnotprocessed}"; } $DB->execute($sql, $params); // disabled $params = array('siteid' => SITEID); $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, enrolperiod, enrolstartdate, enrolenddate, expirynotify, expirythreshold,\n notifyall, password, cost, currency, roleid, timecreated, timemodified)\n SELECT DISTINCT ra.enrol, 1, c.id, 5, c.enrolperiod, c.enrolstartdate, c.enrolenddate, c.expirynotify, c.expirythreshold,\n c.notifystudents, c.password, c.cost, c.currency, c.defaultrole, c.timecreated, c.timemodified\n FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = 50)\n JOIN {role_assignments} ra ON (ra.contextid = ctx.id)\n WHERE c.id <> :siteid"; $processed = $DB->get_fieldset_sql("SELECT DISTINCT enrol FROM {enrol}"); if ($processed) { list($sqlnotprocessed, $params2) = $DB->get_in_or_equal($processed, SQL_PARAMS_NAMED, 'np', false); $params = array_merge($params, $params2); $sql = "{$sql} AND ra.enrol {$sqlnotprocessed}"; } $DB->execute($sql, $params); upgrade_main_savepoint(true, 2010061900.08); } if ($oldversion < 2010061900.09) { // unfortunately there may be still some leftovers // after reconfigured, uninstalled or borked enrol plugins, // unfortunately this may be a bit slow - but there should not be many of these upgrade_set_timeout(); $sqlempty = $DB->sql_empty(); $sql = "SELECT DISTINCT c.id AS courseid, ra.enrol, c.timecreated, c.timemodified\n FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = 50)\n JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.enrol <> '{$sqlempty}')\n LEFT JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = ra.enrol)\n WHERE c.id <> :siteid AND e.id IS NULL"; $params = array('siteid' => SITEID); $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $enrol) { upgrade_set_timeout(); $enrol->status = 1; // better disable them $DB->insert_record('enrol', $enrol); } $rs->close(); upgrade_main_savepoint(true, 2010061900.09); } if ($oldversion < 2010061900.1) { // migrate existing setup of meta courses, ignore records referencing invalid courses $sql = "INSERT INTO {enrol} (enrol, status, courseid, sortorder, customint1)\n SELECT 'meta', 0, cm.parent_course, 5, cm.child_course\n FROM {course_meta} cm\n JOIN {course} p ON p.id = cm.parent_course\n JOIN {course} c ON c.id = cm.child_course"; $DB->execute($sql); upgrade_main_savepoint(true, 2010061900.1); } if ($oldversion < 2010061900.11) { // nuke any old role assignments+enrolments in previous meta courses, we have to start from scratch $select = "SELECT ctx.id\n FROM {context} ctx\n JOIN {course} c ON (c.id = ctx.instanceid AND ctx.contextlevel = 50 AND c.metacourse = 1)"; $DB->delete_records_select('role_assignments', "contextid IN ({$select}) AND enrol = 'manual'"); // course_meta to be dropped - we use enrol_meta plugin instead now $table = new xmldb_table('course_meta'); // Launch drop table for course_meta $dbman->drop_table($table); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.11); } if ($oldversion < 2010061900.12) { // finally remove all obsolete fields from the course table - yay! // all the information was migrated to the enrol table // Define field guest to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('guest'); // Conditionally launch drop field guest if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field password to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('password'); // Conditionally launch drop field password if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field enrolperiod to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('enrolperiod'); // Conditionally launch drop field enrolperiod if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field cost to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('cost'); // Conditionally launch drop field cost if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field currency to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('currency'); // Conditionally launch drop field currency if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field metacourse to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('metacourse'); // Conditionally launch drop field metacourse if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field expirynotify to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('expirynotify'); // Conditionally launch drop field expirynotify if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field expirythreshold to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('expirythreshold'); // Conditionally launch drop field expirythreshold if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field notifystudents to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('notifystudents'); // Conditionally launch drop field notifystudents if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field enrollable to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('enrollable'); // Conditionally launch drop field enrollable if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field enrolstartdate to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('enrolstartdate'); // Conditionally launch drop field enrolstartdate if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field enrolenddate to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('enrolenddate'); // Conditionally launch drop field enrolenddate if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field enrol to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('enrol'); // Conditionally launch drop field enrol if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field defaultrole to be dropped from course $table = new xmldb_table('course'); $field = new xmldb_field('defaultrole'); // Conditionally launch drop field defaultrole if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } upgrade_main_savepoint(true, 2010061900.12); } if ($oldversion < 2010061900.13) { // Define field visibleold to be added to course_categories $table = new xmldb_table('course_categories'); $field = new xmldb_field('visibleold', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'visible'); // Launch add field visibleold $dbman->add_field($table, $field); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.13); } if ($oldversion < 2010061900.14) { // keep previous visible state $DB->execute("UPDATE {course_categories} SET visibleold = visible"); // make sure all subcategories of hidden categories are hidden too, do not rely on category path yet $sql = "SELECT c.id\n FROM {course_categories} c\n JOIN {course_categories} pc ON (pc.id = c.parent AND pc.visible = 0)\n WHERE c.visible = 1"; while ($categories = $DB->get_records_sql($sql)) { foreach ($categories as $cat) { upgrade_set_timeout(); $DB->set_field('course_categories', 'visible', 0, array('id' => $cat->id)); } } upgrade_main_savepoint(true, 2010061900.14); } if ($oldversion < 2010061900.15) { // Define field visibleold to be added to course $table = new xmldb_table('course'); $field = new xmldb_field('visibleold', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'visible'); // Launch add field visibleold $dbman->add_field($table, $field); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.15); } if ($oldversion < 2010061900.16) { // keep previous visible state $DB->execute("UPDATE {course} SET visibleold = visible"); // make sure all courses in hidden categories are hidden $DB->execute("UPDATE {course} SET visible = 0 WHERE category IN (SELECT id FROM {course_categories} WHERE visible = 0)"); upgrade_main_savepoint(true, 2010061900.16); } if ($oldversion < 2010061900.2) { // now set up the enrolments - look for roles with course:participate only at course context - the category enrolments are synchronised later by archetype and new capability $syscontext = get_context_instance(CONTEXT_SYSTEM); $params = array('syscontext' => $syscontext->id, 'participate' => 'moodle/course:participate'); $roles = $DB->get_fieldset_sql("SELECT DISTINCT roleid FROM {role_capabilities} WHERE contextid = :syscontext AND capability = :participate AND permission = 1", $params); if ($roles) { list($sqlroles, $params) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED, 'r'); $sql = "INSERT INTO {user_enrolments} (status, enrolid, userid, timestart, timeend, modifierid, timecreated, timemodified)\n\n SELECT 0, e.id, ra.userid, MIN(ra.timestart), MIN(ra.timeend), 0, MIN(ra.timemodified), MAX(ra.timemodified)\n FROM {role_assignments} ra\n JOIN {context} c ON (c.id = ra.contextid AND c.contextlevel = 50)\n JOIN {enrol} e ON (e.enrol = ra.enrol AND e.courseid = c.instanceid)\n JOIN {user} u ON u.id = ra.userid\n WHERE u.deleted = 0 AND ra.roleid {$sqlroles}\n GROUP BY e.id, ra.userid"; $DB->execute($sql, $params); } upgrade_main_savepoint(true, 2010061900.2); } if ($oldversion < 2010061900.21) { // hidden is completely removed, timestart+timeend are now in the user_enrolments table // Define field hidden to be dropped from role_assignments $table = new xmldb_table('role_assignments'); $field = new xmldb_field('hidden'); // Conditionally launch drop field hidden if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field timestart to be dropped from role_assignments $table = new xmldb_table('role_assignments'); $field = new xmldb_field('timestart'); // Conditionally launch drop field timestart if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Define field timeend to be dropped from role_assignments $table = new xmldb_table('role_assignments'); $field = new xmldb_field('timeend'); // Conditionally launch drop field timeend if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2010061900.21); } if ($oldversion < 2010061900.22) { // Rename field enrol on table role_assignments to component and update content $table = new xmldb_table('role_assignments'); $field = new xmldb_field('enrol', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'modifierid'); // Launch rename field enrol $dbman->rename_field($table, $field, 'component'); // Changing precision of field component on table role_assignments to (100) $table = new xmldb_table('role_assignments'); $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'modifierid'); // Launch change of precision for field component $dbman->change_field_precision($table, $field); // Manual is a special case - we use empty string instead now $params = array('empty' => $DB->sql_empty(), 'manual' => 'manual'); $sql = "UPDATE {role_assignments}\n SET component = :empty\n WHERE component = :manual"; $DB->execute($sql, $params); // Now migrate to real enrol component names $params = array('empty' => $DB->sql_empty()); $concat = $DB->sql_concat("'enrol_'", 'component'); $sql = "UPDATE {role_assignments}\n SET component = {$concat}\n WHERE component <> :empty\n AND contextid IN (\n SELECT id\n FROM {context}\n WHERE contextlevel >= 50)"; $DB->execute($sql, $params); // Now migrate to real auth component names $params = array('empty' => $DB->sql_empty()); $concat = $DB->sql_concat("'auth_'", 'component'); $sql = "UPDATE {role_assignments}\n SET component = {$concat}\n WHERE component <> :empty\n AND contextid IN (\n SELECT id\n FROM {context}\n WHERE contextlevel < 50)"; $DB->execute($sql, $params); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.22); } if ($oldversion < 2010061900.23) { // add proper itemid to role assignments that were added by enrolment plugins $sql = "UPDATE {role_assignments}\n SET itemid = (SELECT MIN({enrol}.id)\n FROM {enrol}\n JOIN {context} ON ({context}.contextlevel = 50 AND {context}.instanceid = {enrol}.courseid)\n WHERE {role_assignments}.component = " . $DB->sql_concat("'enrol_'", "{enrol}.enrol") . " AND {context}.id = {role_assignments}.contextid)\n WHERE component <> 'enrol_manual' AND component LIKE 'enrol_%'"; $DB->execute($sql); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.23); } if ($oldversion < 2010061900.3) { // make new list of active enrol plugins - order is important, meta should be always last, manual first $enabledplugins = explode(',', $CFG->enrol_plugins_enabled); $enabledplugins = array_merge(array('manual', 'guest', 'self', 'cohort'), $enabledplugins); if ($DB->record_exists('enrol', array('enrol' => 'meta'))) { $enabledplugins[] = 'meta'; } $enabledplugins = array_unique($enabledplugins); set_config('enrol_plugins_enabled', implode(',', $enabledplugins)); // Main savepoint reached upgrade_main_savepoint(true, 2010061900.3); } if ($oldversion < 2010061900.31) { // finalise all new enrol settings and cleanup old settings // legacy allowunenrol was deprecated in 1.9 already unset_config('allwunenroll'); // obsolete course presets unset_config('metacourse', 'moodlecourse'); unset_config('enrol', 'moodlecourse'); unset_config('enrollable', 'moodlecourse'); unset_config('enrolperiod', 'moodlecourse'); unset_config('expirynotify', 'moodlecourse'); unset_config('notifystudents', 'moodlecourse'); unset_config('expirythreshold', 'moodlecourse'); unset_config('enrolpassword', 'moodlecourse'); unset_config('guest', 'moodlecourse'); unset_config('backup_sche_metacourse', 'backup'); unset_config('lastexpirynotify'); // hidden course categories now prevent only browsing, courses are accessible if you know the URL and course is visible unset_config('allowvisiblecoursesinhiddencategories'); if (isset($CFG->coursemanager)) { set_config('coursecontact', $CFG->coursemanager); unset_config('coursemanager'); } // migrate plugin settings - the problem here is we are splitting manual into three different plugins if (isset($CFG->enrol_manual_usepasswordpolicy)) { set_config('usepasswordpolicy', $CFG->enrol_manual_usepasswordpolicy, 'enrol_guest'); set_config('usepasswordpolicy', $CFG->enrol_manual_usepasswordpolicy, 'enrol_self'); set_config('groupenrolmentkeypolicy', $CFG->enrol_manual_usepasswordpolicy); unset_config('enrol_manual_usepasswordpolicy'); } if (isset($CFG->enrol_manual_requirekey)) { set_config('requirepassword', $CFG->enrol_manual_requirekey, 'enrol_guest'); set_config('requirepassword', $CFG->enrol_manual_requirekey, 'enrol_self'); unset_config('enrol_manual_requirekey'); } if (isset($CFG->enrol_manual_showhint)) { set_config('showhint', $CFG->enrol_manual_showhint, 'enrol_guest'); set_config('showhint', $CFG->enrol_manual_showhint, 'enrol_self'); unset_config('enrol_manual_showhint'); } upgrade_main_savepoint(true, 2010061900.31); } if ($oldversion < 2010061900.32) { // MDL-22797 course completion has to be updated to use new enrol framework, it will not be enabled in final 2.0 set_config('enableavailability', 0); set_config('enablecompletion', 0); upgrade_main_savepoint(true, 2010061900.32); } if ($oldversion < 2010062101) { /// Define field huburl to be dropped from course_published $table = new xmldb_table('course_published'); $field = new xmldb_field('hubid'); /// Conditionally launch drop field huburl if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } /// Define field huburl to be added to course_published $table = new xmldb_table('course_published'); $field = new xmldb_field('huburl', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'id'); /// Conditionally launch add field huburl if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010062101); } if ($oldversion < 2010070300) { //TODO: this is a temporary hack for upgrade from PR3, to be removed later // Define field component to be added to files $table = new xmldb_table('files'); $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'contextid'); // Conditionally upgrade from PR3 if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); $index = new xmldb_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid')); $dbman->drop_index($table, $index); $index = new xmldb_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid')); $dbman->add_index($table, $index); // Rename areas as add proper component $areas = $DB->get_fieldset_sql("SELECT DISTINCT filearea FROM {files}"); if ($areas) { // fix incorrect itemids $DB->execute("UPDATE {files} SET itemid = 0 WHERE filearea = 'category_description'"); // context identifies instances $DB->execute("UPDATE {files} SET itemid = 0 WHERE filearea = 'user_profile'"); // context identifies instances $DB->execute("UPDATE {files} SET itemid = 0 WHERE filearea = 'block_html'"); // context identifies instances foreach ($areas as $area) { // rename areas if ($area === 'course_backup') { $area = 'backup_course'; } else { if ($area === 'section_backup') { $area = 'backup_section'; } else { if ($area === 'activity_backup') { $area = 'backup_activity'; } else { if ($area === 'category_description') { $area = 'coursecat_description'; } } } } if ($area === 'block_html') { $component = 'block_html'; $filearea = 'content'; } else { list($component, $filearea) = explode('_', $area, 2); // note this is just a hack which guesses plugin from old PRE3 files code, the whole point of adding component is to get rid of this guessing if (file_exists("{$CFG->dirroot}/mod/{$component}/lib.php")) { $component = 'mod_' . $component; } } $DB->execute("UPDATE {files} SET component = :component, filearea = :filearea WHERE filearea = :area", array('component' => $component, 'filearea' => $filearea, 'area' => $area)); } // Update all hashes $rs = $DB->get_recordset('files', array()); foreach ($rs as $file) { upgrade_set_timeout(); $pathnamehash = sha1("/{$file->contextid}/{$file->component}/{$file->filearea}/{$file->itemid}" . $file->filepath . $file->filename); $DB->set_field('files', 'pathnamehash', $pathnamehash, array('id' => $file->id)); } $rs->close(); } } // Main savepoint reached upgrade_main_savepoint(true, 2010070300); } if ($oldversion < 2010070500) { /// Define field operation to be added to backup_controllers $table = new xmldb_table('backup_controllers'); $field = new xmldb_field('operation', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'backup', 'backupid'); /// Conditionally launch add field operation if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010070500); } if ($oldversion < 2010070501) { /// Define field suspended to be added to user $table = new xmldb_table('user'); $field = new xmldb_field('suspended', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'deleted'); /// Conditionally launch add field suspended if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010070501); } if ($oldversion < 2010070502) { /// Define field newitemid to be added to backup_ids_template $table = new xmldb_table('backup_ids_template'); $field = new xmldb_field('newitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'itemid'); /// Conditionally launch add field newitemid if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field info to be added to backup_ids_template $table = new xmldb_table('backup_ids_template'); $field = new xmldb_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'parentitemid'); /// Conditionally launch add field info if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010070502); } if ($oldversion < 2010070601) { // delete loan calc if not used - it was moved to contrib if (!file_exists("{$CFG->dirroot}/blocks/loancalc/version.php")) { if (!$DB->record_exists('block_instances', array('blockname' => 'loancalc'))) { $DB->delete_records('block', array('name' => 'loancalc')); } } upgrade_main_savepoint(true, 2010070601); } if ($oldversion < 2010070602) { // delete exercise if not used and not installed - now in contrib (do not use adminlib uninstall functions, they may change) if (!file_exists("{$CFG->dirroot}/mod/exercise/version.php")) { if ($module = $DB->get_record('modules', array('name' => 'exercise'))) { if (!$DB->record_exists('course_modules', array('module' => $module->id))) { //purge capabilities $DB->delete_records_select('capabilities', "name LIKE ?", array('mod/exercise:%')); $DB->delete_records_select('role_capabilities', "capability LIKE ?", array('mod/exercise:%')); $tables = array('exercise', 'exercise_submissions', 'exercise_assessments', 'exercise_elements', 'exercise_rubrics', 'exercise_grades'); foreach ($tables as $tname) { $table = new xmldb_table($tname); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } } $DB->delete_records('event', array('modulename' => 'exercise')); $DB->delete_records('log', array('module' => 'exercise')); $DB->delete_records('modules', array('name' => 'exercise')); } } } upgrade_main_savepoint(true, 2010070602); } if ($oldversion < 2010070603) { // delete journal if not used and not installed - now in contrib (do not use adminlib uninstall functions, they may change) if (!file_exists("{$CFG->dirroot}/mod/journal/version.php")) { if ($module = $DB->get_record('modules', array('name' => 'journal'))) { if (!$DB->record_exists('course_modules', array('module' => $module->id))) { //purge capabilities $DB->delete_records_select('capabilities', "name LIKE ?", array('mod/journal:%')); $DB->delete_records_select('role_capabilities', "capability LIKE ?", array('mod/journal:%')); $tables = array('journal', 'journal_entries'); foreach ($tables as $tname) { $table = new xmldb_table($tname); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } } $DB->delete_records('event', array('modulename' => 'journal')); $DB->delete_records('log', array('module' => 'journal')); $DB->delete_records('modules', array('name' => 'journal')); unset_config('journal_initialdisable'); } } } upgrade_main_savepoint(true, 2010070603); } if ($oldversion < 2010070604) { // delete lams if not used and not installed - now in contrib (do not use adminlib uninstall functions, they may change) if (!file_exists("{$CFG->dirroot}/mod/lams/version.php")) { if ($module = $DB->get_record('modules', array('name' => 'lams'))) { if (!$DB->record_exists('course_modules', array('module' => $module->id))) { //purge capabilities $DB->delete_records_select('capabilities', "name LIKE ?", array('mod/lams:%')); $DB->delete_records_select('role_capabilities', "capability LIKE ?", array('mod/lams:%')); $tables = array('lams', ''); foreach ($tables as $tname) { $table = new xmldb_table($tname); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } } $DB->delete_records('event', array('modulename' => 'lams')); $DB->delete_records('log', array('module' => 'lams')); $DB->delete_records('modules', array('name' => 'lams')); unset_config('lams_initialdisable'); } } } upgrade_main_savepoint(true, 2010070604); } if ($oldversion < 2010070801) { /// Before changing the field, drop dependent indexes /// Define index shortname (not unique) to be dropped form course_request $table = new xmldb_table('user'); $index = new xmldb_index('city', XMLDB_INDEX_NOTUNIQUE, array('city')); /// Conditionally launch drop index shortname if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } /// Changing precision of field city on table user to (120) $field = new xmldb_field('city', XMLDB_TYPE_CHAR, '120', null, XMLDB_NOTNULL, null, null, 'address'); /// Launch change of precision for field city $dbman->change_field_precision($table, $field); /// Conditionally launch add index typeitem_ix if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } /// Main savepoint reached upgrade_main_savepoint(true, 2010070801); } if ($oldversion < 2010071000) { //purge unused editor settings unset_config('editorbackgroundcolor'); unset_config('editorfontfamily'); unset_config('editorfontsize'); unset_config('editorkillword'); unset_config('editorhidebuttons'); unset_config('editorfontlist'); upgrade_main_savepoint(true, 2010071000); } if ($oldversion < 2010071001) { // purge obsolete stats settings unset_config('statscatdepth'); upgrade_main_savepoint(true, 2010071001); } if ($oldversion < 2010071100) { // move user icons to file storage pool upgrade_migrate_user_icons(); upgrade_main_savepoint(true, 2010071100); } if ($oldversion < 2010071101) { // move user icons to file storage pool upgrade_migrate_group_icons(); upgrade_main_savepoint(true, 2010071101); } if ($oldversion < 2010071300) { // Define field timecreated to be added to user_enrolments $table = new xmldb_table('user_enrolments'); $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'modifierid'); // Launch add field timecreated if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // now try to guess the time created $sql = "UPDATE {user_enrolments} SET timecreated = timemodified WHERE timecreated = 0"; $DB->execute($sql); $sql = "UPDATE {user_enrolments} SET timecreated = timestart WHERE timestart <> 0 AND timestart < timemodified"; $DB->execute($sql); upgrade_main_savepoint(true, 2010071300); } if ($oldversion < 2010071700) { // Make itemname bigger (160cc) to store component+filearea $table = new xmldb_table('backup_ids_template'); // Define key backupid_itemname_itemid_uk (unique) to be dropped form backup_ids_template $key = new xmldb_key('backupid_itemname_itemid_uk', XMLDB_KEY_UNIQUE, array('backupid', 'itemname', 'itemid')); // Define index backupid_parentitemid_ix (not unique) to be dropped form backup_ids_template $index = new xmldb_index('backupid_parentitemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'itemname', 'parentitemid')); // Define field itemname to be 160cc $field = new xmldb_field('itemname', XMLDB_TYPE_CHAR, '160', null, XMLDB_NOTNULL, null, null, 'backupid'); // Launch drop key backupid_itemname_itemid_uk $dbman->drop_key($table, $key); // Conditionally launch drop index backupid_parentitemid_ix if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Changing precision of field itemname on table backup_ids_template to (160) $dbman->change_field_precision($table, $field); // Launch add key backupid_itemname_itemid_uk $dbman->add_key($table, $key); // Conditionally launch add index backupid_parentitemid_ix if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010071700); } if ($oldversion < 2010071701) { // Drop legacy core tables that now belongs to mnetservice_enrol plugin // Upgrade procedure not needed as the tables are used for caching purposes only $tables = array('mnet_enrol_course', 'mnet_enrol_assignments'); foreach ($tables as $tname) { $table = new xmldb_table($tname); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } } upgrade_main_savepoint(true, 2010071701); } if ($oldversion < 2010071800) { // Define table backup_files_template to be created $table = new xmldb_table('backup_files_template'); // Adding fields to table backup_files_template $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); // Adding keys to table backup_files_template $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table backup_files_template $table->add_index('backupid_contextid_component_filearea_itemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'contextid', 'component', 'filearea', 'itemid')); // Conditionally launch create table for backup_files_template if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Main savepoint reached upgrade_main_savepoint(true, 2010071800); } if ($oldversion < 2010072300) { // Define field capabilities to be added to external_functions $table = new xmldb_table('external_functions'); $field = new xmldb_field('capabilities', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'component'); // Conditionally launch add field capabilities if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2010072300); } if ($oldversion < 2010072700) { // Define index backupid_itemname_newitemid_ix (not unique) to be added to backup_ids_template $table = new xmldb_table('backup_ids_template'); $index = new xmldb_index('backupid_itemname_newitemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'itemname', 'newitemid')); // Conditionally launch add index backupid_itemname_newitemid_ix if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010072700); } if ($oldversion < 2010080303) { $rs = $DB->get_recordset_sql('SELECT i.id, i.name, r.type FROM {repository_instances} i, {repository} r WHERE i.typeid = r.id'); foreach ($rs as $record) { upgrade_set_timeout(); if ($record->name == $record->type) { // repository_instances was saving type name as in name field // which should be empty, the repository api will try to find // instance name from language files $DB->set_field('repository_instances', 'name', ''); } } $rs->close(); upgrade_main_savepoint(true, 2010080303); } if ($oldversion < 2010080305) { // first drop all log display actions, we will recreate them automatically later $DB->delete_records('log_display', array()); // Define field component to be added to log_display $table = new xmldb_table('log_display'); $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'field'); // Launch add field component if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2010080305); } if ($oldversion < 2010080900) { /// Define field generalfeedbackformat to be added to question $table = new xmldb_table('question'); $field = new xmldb_field('generalfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'generalfeedback'); /// Conditionally launch add field generalfeedbackformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Upgrading the text formats in some question types depends on the /// questiontextformat field, but the question type upgrade only runs /// after the code below has messed around with the questiontextformat /// value. Therefore, we need to create a new column to store the old value. /// The column should be dropped in Moodle 2.1. /// Define field oldquestiontextformat to be added to question $field = new xmldb_field('oldquestiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'generalfeedback'); /// Conditionally launch add field oldquestiontextformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field infoformat to be added to question_categories $table = new xmldb_table('question_categories'); $field = new xmldb_field('infoformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'info'); /// Conditionally launch add field infoformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field answerformat to be added to question_answers $table = new xmldb_table('question_answers'); $field = new xmldb_field('answerformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'answer'); /// Conditionally launch add field answerformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field feedbackformat to be added to question_answers $field = new xmldb_field('feedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'feedback'); /// Conditionally launch add field feedbackformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field manualcommentformat to be added to question_sessions $table = new xmldb_table('question_sessions'); $field = new xmldb_field('manualcommentformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment'); /// Conditionally launch add field manualcommentformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Main savepoint reached upgrade_main_savepoint(true, 2010080900); } /// updating question image if ($oldversion < 2010080901) { $fs = get_file_storage(); // Define field image to be dropped from question $table = new xmldb_table('question'); $field = new xmldb_field('image'); // Conditionally launch drop field image if ($dbman->field_exists($table, $field)) { $rs = $DB->get_recordset('question'); $textlib = textlib_get_instance(); foreach ($rs as $question) { // may take awhile upgrade_set_timeout(); if (empty($question->image)) { continue; } if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) { continue; } $categorycontext = get_context_instance_by_id($category->contextid); // question files are stored in course level // so we have to find course context switch ($categorycontext->contextlevel) { case CONTEXT_COURSE: $context = $categorycontext; break; case CONTEXT_MODULE: $courseid = $DB->get_field('course_modules', 'course', array('id' => $categorycontext->instanceid)); $context = get_context_instance(CONTEXT_COURSE, $courseid); break; case CONTEXT_COURSECAT: case CONTEXT_SYSTEM: $context = get_system_context(); break; default: continue; } if ($textlib->substr($textlib->strtolower($question->image), 0, 7) == 'http://') { // it is a link, appending to existing question text $question->questiontext .= ' <img src="' . $question->image . '" />'; $question->image = ''; // update question record $DB->update_record('question', $question); } else { $filename = basename($question->image); $filepath = dirname($question->image); if (empty($filepath) or $filepath == '.' or $filepath == '/') { $filepath = '/'; } else { // append / $filepath = '/' . trim($filepath, './@#$ ') . '/'; } // course files already moved to file pool by previous upgrade block // so we just create copy from course_legacy area if ($image = $fs->get_file($context->id, 'course', 'legacy', 0, $filepath, $filename)) { // move files to file pool $file_record = array('contextid' => $category->contextid, 'component' => 'question', 'filearea' => 'questiontext', 'itemid' => $question->id); $fs->create_file_from_storedfile($file_record, $image); $question->questiontext .= ' <img src="@@PLUGINFILE@@' . $filepath . $filename . '" />'; $question->image = ''; // update question record $DB->update_record('question', $question); } } } $rs->close(); $dbman->drop_field($table, $field); } // Update question_answers. // In question_answers.feedback was previously always treated as // FORMAT_HTML in calculated, multianswer, multichoice, numerical, // shortanswer and truefalse; and // FORMAT_MOODLE in essay (despite being edited using the HTML editor) // So essay feedback needs to be converted to HTML unless $CFG->texteditors == 'textarea'. // For all question types except multichoice, // question_answers.answer is FORMAT_PLAIN and does not need to be changed. // For multichoice, question_answers.answer is FORMAT_MOODLE, and should // stay that way, at least for now. $rs = $DB->get_recordset_sql(' SELECT qa.*, q.qtype FROM {question_answers} qa JOIN {question} q ON qa.question = q.id'); foreach ($rs as $record) { // may take awhile upgrade_set_timeout(); // Convert question_answers.answer if ($record->qtype !== 'multichoice') { $record->answerformat = FORMAT_PLAIN; } else { $record->answerformat = FORMAT_MOODLE; } // Convert question_answers.feedback if ($CFG->texteditors !== 'textarea') { if ($record->qtype == 'essay') { $record->feedback = text_to_html($record->feedback, false, false, true); } $record->feedbackformat = FORMAT_HTML; } else { $record->feedbackformat = FORMAT_MOODLE; } $DB->update_record('question_answers', $record); } $rs->close(); // In the question table, the code previously used questiontextformat // for both question text and general feedback. We need to copy the // values into the new column. // Then we need to convert FORMAT_MOODLE to FORMAT_HTML (depending on // $CFG->texteditors). $DB->execute(' UPDATE {question} SET generalfeedbackformat = questiontextformat'); // Also save the old questiontextformat, so that plugins that need it // can access it. $DB->execute(' UPDATE {question} SET oldquestiontextformat = questiontextformat'); // Now covert FORMAT_MOODLE content, if necssary. if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('question', array('questiontextformat' => FORMAT_MOODLE)); foreach ($rs as $record) { // may take awhile upgrade_set_timeout(); $record->questiontext = text_to_html($record->questiontext, false, false, true); $record->questiontextformat = FORMAT_HTML; $record->generalfeedback = text_to_html($record->generalfeedback, false, false, true); $record->generalfeedbackformat = FORMAT_HTML; $DB->update_record('question', $record); } $rs->close(); } // In the past, question_sessions.manualcommentformat was always treated // as FORMAT_HTML. $DB->set_field('question_sessions', 'manualcommentformat', FORMAT_HTML); // Main savepoint reached upgrade_main_savepoint(true, 2010080901); } if ($oldversion < 2010082502) { // migrate file pool xx/xx/xx directory structure to xx/xx in older 2.0dev installs upgrade_simplify_overkill_pool_structure(); upgrade_main_savepoint(true, 2010082502); } if ($oldversion < 2010091303) { // drop all test tables from old xmldb test suite $table = new xmldb_table('testtable'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } $table = new xmldb_table('anothertest'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } $table = new xmldb_table('newnameforthetable'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } upgrade_main_savepoint(true, 2010091303); } if ($oldversion < 2010091500) { // Changing precision of field token on table registration_hubs to (255) $table = new xmldb_table('registration_hubs'); $field = new xmldb_field('token', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); // Launch change of precision for field token $dbman->change_field_precision($table, $field); // Main savepoint reached upgrade_main_savepoint(true, 2010091500); } if ($oldversion < 2010091501) { // This index used to exist in Moodle 1.9 and was never dropped in the upgrade above. // Drop it now, or it breaks the following alter column. // Define index pagetypepattern (not unique) to be dropped form block_instances $table = new xmldb_table('block_instances'); $index = new xmldb_index('pagetypepattern', XMLDB_INDEX_NOTUNIQUE, array('pagetypepattern')); // Conditionally launch drop index pagetypepattern if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010091501); } if ($oldversion < 2010091502) { // Need to drop the index before we can alter the column precision in the next step. // Define index parentcontextid-showinsubcontexts-pagetypepattern-subpagepattern (not unique) to be dropped form block_instances $table = new xmldb_table('block_instances'); $index = new xmldb_index('parentcontextid-showinsubcontexts-pagetypepattern-subpagepattern', XMLDB_INDEX_NOTUNIQUE, array('parentcontextid', 'showinsubcontexts', 'pagetypepattern', 'subpagepattern')); // Conditionally launch drop index parentcontextid-showinsubcontexts-pagetypepattern-subpagepattern if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010091502); } if ($oldversion < 2010091503) { // Changing precision of field pagetypepattern on table block_instances to (64) $table = new xmldb_table('block_instances'); $field = new xmldb_field('pagetypepattern', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, 'showinsubcontexts'); // Launch change of precision for field pagetypepattern $dbman->change_field_precision($table, $field); // Main savepoint reached upgrade_main_savepoint(true, 2010091503); } if ($oldversion < 2010091504) { // Now add the index back. // Define index parentcontextid-showinsubcontexts-pagetypepattern-subpagepattern (not unique) to be added to block_instances $table = new xmldb_table('block_instances'); $index = new xmldb_index('parentcontextid-showinsubcontexts-pagetypepattern-subpagepattern', XMLDB_INDEX_NOTUNIQUE, array('parentcontextid', 'showinsubcontexts', 'pagetypepattern', 'subpagepattern')); // Conditionally launch add index parentcontextid-showinsubcontexts-pagetypepattern-subpagepattern if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010091504); } if ($oldversion < 2010091505) { // drop all events queued from 1.9, unfortunately we can not process them because the serialisation of data changed // also the events format was changed.... $DB->delete_records('events_queue_handlers', array()); $DB->delete_records('events_queue', array()); //reset all status fields too $DB->set_field('events_handlers', 'status', 0, array()); upgrade_main_savepoint(true, 2010091505); } if ($oldversion < 2010091506) { // change component string in events_handlers records to new "_" format if ($handlers = $DB->get_records('events_handlers')) { foreach ($handlers as $handler) { $handler->handlermodule = str_replace('/', '_', $handler->handlermodule); $DB->update_record('events_handlers', $handler); } } unset($handlers); upgrade_main_savepoint(true, 2010091506); } if ($oldversion < 2010091507) { // Define index eventname-handlermodule (unique) to be dropped form events_handlers $table = new xmldb_table('events_handlers'); $index = new xmldb_index('eventname-handlermodule', XMLDB_INDEX_UNIQUE, array('eventname', 'handlermodule')); // Conditionally launch drop index eventname-handlermodule if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010091507); } if ($oldversion < 2010091508) { // Rename field handlermodule on table events_handlers to component $table = new xmldb_table('events_handlers'); $field = new xmldb_field('handlermodule', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, 'eventname'); // Launch rename field handlermodule $dbman->rename_field($table, $field, 'component'); // Main savepoint reached upgrade_main_savepoint(true, 2010091508); } if ($oldversion < 2010091509) { // Define index eventname-component (unique) to be added to events_handlers $table = new xmldb_table('events_handlers'); $index = new xmldb_index('eventname-component', XMLDB_INDEX_UNIQUE, array('eventname', 'component')); // Conditionally launch add index eventname-component if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010091509); } if ($oldversion < 2010091510) { // Define field internal to be added to events_handlers $table = new xmldb_table('events_handlers'); $field = new xmldb_field('internal', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'status'); // Conditionally launch add field internal if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2010091510); } if ($oldversion < 2010091700) { // Fix MNet sso_jump_url for Moodle application $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle', 'sso_jump_url' => '/auth/mnet/land.php')); upgrade_main_savepoint(true, 2010091700); } if ($oldversion < 2010092000) { // drop multiple field again because it was still in install.xml in 2.0dev // Define field multiple to be dropped from block $table = new xmldb_table('block'); $field = new xmldb_field('multiple'); // Conditionally launch drop field multiple if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2010092000); } if ($oldversion < 2010101300) { // Fix MDL-24641 : the registered language should not be empty otherwise cron will fail $registeredhubs = $DB->get_records('registration_hubs', array('confirmed' => 1)); if (!empty($registeredhubs)) { foreach ($registeredhubs as $hub) { $cleanhuburl = clean_param($hub->huburl, PARAM_ALPHANUMEXT); $sitelanguage = get_config('hub', 'site_language_' . $cleanhuburl); if (empty($sitelanguage)) { set_config('site_language_' . $cleanhuburl, current_language(), 'hub'); } } } upgrade_main_savepoint(true, 2010101300); } //MDL-24721 -add hidden column to grade_categories. This was done previously but it wasn't included in //install.xml so there are 2.0 sites that are missing it. if ($oldversion < 2010101900) { $table = new xmldb_table('grade_categories'); $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'timemodified'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_main_savepoint(true, 2010101900); } // new format of the emoticons setting if ($oldversion < 2010102300) { unset($CFG->emoticons); $DB->delete_records('config', array('name' => 'emoticons')); $DB->delete_records('cache_text'); // changed md5 hash calculation upgrade_main_savepoint(true, 2010102300); } //MDL-24771 if ($oldversion < 2010102601) { $fieldnotification = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, 0, 'smallmessage'); $fieldcontexturl = new xmldb_field('contexturl', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'notification'); $fieldcontexturlname = new xmldb_field('contexturlname', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'contexturl'); $fieldstoadd = array($fieldnotification, $fieldcontexturl, $fieldcontexturlname); $tablestomodify = array(new xmldb_table('message'), new xmldb_table('message_read')); foreach ($tablestomodify as $table) { foreach ($fieldstoadd as $field) { if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } } } upgrade_main_savepoint(true, 2010102601); } // MDL-24694 needs increasing size of user_preferences.name(varchar[50]) field due to // long preferences names for messaging which need components parts within the name // eg: 'message_provider_mod_assignment_assignments_loggedin' if ($oldversion < 2010102602) { // Define index userid-name (unique) to be dropped form user_preferences $table = new xmldb_table('user_preferences'); $index = new xmldb_index('userid-name', XMLDB_INDEX_UNIQUE, array('userid', 'name')); // Conditionally launch drop index userid-name if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Changing precision of field name on table user_preferences to (255) $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'userid'); // Launch change of precision for field name $dbman->change_field_precision($table, $field); // Conditionally launch add index userid-name if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2010102602); } if ($oldversion < 2010102700) { $table = new xmldb_table('post'); $field = new xmldb_field('uniquehash', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, 'content'); // Launch change of precision for field name $dbman->change_field_precision($table, $field); // Main savepoint reached upgrade_main_savepoint(true, 2010102700); } if ($oldversion < 2010110200) { // fix tags itemtype for wiki $sql = "UPDATE {tag_instance}\n SET itemtype = 'wiki_pages'\n WHERE itemtype = 'wiki_page'"; $DB->execute($sql); echo $OUTPUT->notification('Updating tags itemtype', 'notifysuccess'); // Main savepoint reached upgrade_main_savepoint(true, 2010110200); } //remove forum_logblocked from config. No longer required after user->emailstop was removed if ($oldversion < 2010110500) { unset_config('forum_logblocked'); upgrade_main_savepoint(true, 2010110500); } if ($oldversion < 2010110800) { // convert $CFG->disablecourseajax to $CFG->enablecourseajax $disabledcourseajax = get_config('disablecourseajax', 0); if ($disabledcourseajax) { set_config('enablecourseajax', 0); } else { set_config('enablecourseajax', 1); } unset_config('disablecourseajax'); upgrade_main_savepoint(true, 2010110800); } if ($oldversion < 2010111000) { // Clean up the old scheduled backup settings that are no longer relevant update_fix_automated_backup_config(); upgrade_main_savepoint(true, 2010111000); } if ($oldversion < 2010111702) { // Clean up the old experimental split restore no loger used unset_config('experimentalsplitrestore'); upgrade_main_savepoint(true, 2010111702); } if ($oldversion < 2010121401) { // Define table profiling to be created $table = new xmldb_table('profiling'); // Adding fields to table profiling $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('runid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('url', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null); $table->add_field('totalexecutiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('totalcputime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('totalcalls', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('totalmemory', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('runreference', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('runcomment', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); // Adding keys to table profiling $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('runid_uk', XMLDB_KEY_UNIQUE, array('runid')); // Adding indexes to table profiling $table->add_index('url_runreference_ix', XMLDB_INDEX_NOTUNIQUE, array('url', 'runreference')); $table->add_index('timecreated_runreference_ix', XMLDB_INDEX_NOTUNIQUE, array('timecreated', 'runreference')); // Conditionally launch create table for profiling if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Main savepoint reached upgrade_main_savepoint(true, 2010121401); } if ($oldversion < 2011011401) { $columns = $DB->get_columns('block_instances'); // Check if we need to fix the default weight column if (array_key_exists('defaultweight', $columns) && $columns['defaultweight']->max_length != 10) { // Fix discrepancies in the block_instances table after upgrade from 1.9 $table = new xmldb_table('block_instances'); // defaultweight is smallint(3) after upgrade should be bigint 10 // Also fixed in earlier upgrade code $field = new xmldb_field('defaultweight', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, 'defaultregion'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } // add missing key `blocinst_par_ix` (`parentcontextid`) $index = new xmldb_index('parentcontextid', XMLDB_INDEX_NOTUNIQUE, array('parentcontextid')); if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } } // Main savepoint reached upgrade_main_savepoint(true, 2011011401); } if ($oldversion < 2011011402) { // Fix discrepancies in the block_positions table after upgrade from 1.9 $table = new xmldb_table('block_positions'); $columns = $DB->get_columns('block_positions'); // Check if we need to fix the blockinstanceid field if (array_key_exists('blockinstanceid', $columns) && empty($columns['blockinstanceid']->unsigned)) { // Fix blockinstanceid // First remove the indexs on the field $indexone = new xmldb_index('blockinstanceid', XMLDB_INDEX_NOTUNIQUE, array('blockinstanceid')); $indexall = new xmldb_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage')); if ($dbman->index_exists($table, $indexone)) { $dbman->drop_index($table, $indexone); } if ($dbman->index_exists($table, $indexall)) { $dbman->drop_index($table, $indexall); } // blockinstanceid should be unsigned // Also fixed in earlier upgrade code $field = new xmldb_field('blockinstanceid', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'id'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_unsigned($table, $field); } // Add the indexs back in $dbman->add_index($table, $indexone); $dbman->add_index($table, $indexall); } // Check if the visible field needs fixing. if (array_key_exists('visible', $columns) && !empty($columns['visible']->has_default)) { // visible shouldn't have a default // Also fixed in earlier upgrade code $field = new xmldb_field('visible', XMLDB_TYPE_INTEGER, 4, null, XMLDB_NOTNULL, null, null, 'subpage'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } // Main savepoint reached upgrade_main_savepoint(true, 2011011402); } if ($oldversion < 2011011403) { $columns = $DB->get_columns('grade_categories'); // Check if we need to fix the hidden field if (array_key_exists('hidden', $columns) && $columns['hidden']->max_length != 1) { // Fix discrepancies in the grade_categories table after upgrade from 1.9 $table = new xmldb_table('grade_categories'); // hidden should be tinyint(1) // Also fixed in earlier upgrade code $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'timemodified'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_precision($table, $field); } } // Main savepoint reached upgrade_main_savepoint(true, 2011011403); } if ($oldversion < 2011011404) { // Fix discrepancies in the message table after upgrade from 1.9 $columns = $DB->get_columns('message'); $table = new xmldb_table('message'); // Check if we need to fix the useridfrom field if (array_key_exists('useridfrom', $columns) && empty($columns['useridfrom']->unsigned)) { // useridfrom should be unsigned $field = new xmldb_field('useridfrom', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'id'); $index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom')); if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } if ($dbman->field_exists($table, $field)) { $dbman->change_field_unsigned($table, $field); } $dbman->add_index($table, $index); } // Check if we need to fix the useridto field if (array_key_exists('useridto', $columns) && empty($columns['useridto']->unsigned)) { // useridto should be unsigned $field = new xmldb_field('useridto', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'useridfrom'); $index = new xmldb_index('useridto', XMLDB_INDEX_NOTUNIQUE, array('useridto')); if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } if ($dbman->field_exists($table, $field)) { $dbman->change_field_unsigned($table, $field); } $dbman->add_index($table, $index); } // Check if we need to fix the notification field if (array_key_exists('notification', $columns) && !empty($columns['notification']->not_null)) { // notification should allow null // Fixed in earlier upgrade code $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, null, null, 0, 'smallmessage'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } } // Check if we need to fix the contexturl field if (array_key_exists('contexturl', $columns) && strpos($columns['contexturl']->type, 'text') === false) { // contexturl should be text // Fixed in earlier upgrade code $field = new xmldb_field('contexturl', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'notification'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } } // Check if we need to fix the contexturl field if (array_key_exists('contexturlname', $columns) && strpos($columns['contexturlname']->type, 'text') === false) { // contexturlname should be text // Fixed in earlier upgrade code $field = new xmldb_field('contexturlname', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'contexturl'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } } // Main savepoint reached upgrade_main_savepoint(true, 2011011404); } if ($oldversion < 2011011405) { // Fix discrepancies in the message_read table after upgrade from 1.9 $columns = $DB->get_columns('message_read'); $table = new xmldb_table('message_read'); // Check if we need to fix the useridfrom field if (array_key_exists('useridfrom', $columns) && empty($columns['useridfrom']->unsigned)) { // useridfrom should be unsigned $field = new xmldb_field('useridfrom', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'id'); $index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom')); if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } if ($dbman->field_exists($table, $field)) { $dbman->change_field_unsigned($table, $field); } $dbman->add_index($table, $index); } // Check if we need to fix the useridto field if (array_key_exists('useridto', $columns) && empty($columns['useridto']->unsigned)) { // useridto should be unsigned $field = new xmldb_field('useridto', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'useridfrom'); $index = new xmldb_index('useridto', XMLDB_INDEX_NOTUNIQUE, array('useridto')); if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } if ($dbman->field_exists($table, $field)) { $dbman->change_field_unsigned($table, $field); } $dbman->add_index($table, $index); } // Check if we need to fix the notification field if (array_key_exists('notification', $columns) && !empty($columns['notification']->not_null)) { // notification should allow null // Fixed in earlier upgrade code $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, null, null, 0, 'smallmessage'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } } // Check if we need to fix the contexturl field if (array_key_exists('contexturl', $columns) && strpos($columns['contexturl']->type, 'text') === false) { // contexturl should be text // Fixed in earlier upgrade code $field = new xmldb_field('contexturl', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'notification'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } } // Check if we need to fix the contexturl field if (array_key_exists('contexturlname', $columns) && strpos($columns['contexturlname']->type, 'text') === false) { // contexturlname should be text // Fixed in earlier upgrade code $field = new xmldb_field('contexturlname', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'contexturl'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_type($table, $field); } } // Main savepoint reached upgrade_main_savepoint(true, 2011011405); } if ($oldversion < 2011011406) { // Fix discrepancies in the my_pages table after upgrade from 1.9 $columns = $DB->get_columns('my_pages'); $table = new xmldb_table('my_pages'); // Check if we need to fix the private column if (array_key_exists('private', $columns) && $columns['private']->default_value != '1') { // private should be default 1 // Fixed in earlier upgrade code $field = new xmldb_field('private', XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 1, 'name'); $index = new xmldb_index('user_idx', XMLDB_INDEX_NOTUNIQUE, array('userid', 'private')); if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } $dbman->add_index($table, $index); } // Check if we need to fix the sortorder field if (array_key_exists('sortorder', $columns) && !empty($columns['sortorder']->unsigned)) { // Sortorder should not be unsigned // Fixed in earlier upgrade code $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, 6, null, XMLDB_NOTNULL, null, 0, 'private'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } } upgrade_main_savepoint(true, 2011011406); } if ($oldversion < 2011011407) { // Check if we need to fix post.uniquehash $columns = $DB->get_columns('my_pages'); if (array_key_exists('uniquehash', $columns) && $columns['uniquehash']->max_length != 128) { // Fix discrepancies in the post table after upgrade from 1.9 $table = new xmldb_table('post'); // Uniquehash should be 128 chars // Fixed in earlier upgrade code $field = new xmldb_field('uniquehash', XMLDB_TYPE_CHAR, 128, null, XMLDB_NOTNULL, null, null, 'content'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_precision($table, $field); } } upgrade_main_savepoint(true, 2011011407); } if ($oldversion < 2011011408) { // Fix question in the post table after upgrade from 1.9 $columns = $DB->get_columns('question'); $table = new xmldb_table('question'); // Check if we need to fix default grade if (array_key_exists('defaultgrade', $columns) && (empty($columns['defaultgrade']->unsigned) || empty($columns['defaultgrade']->not_null) || $columns['defaultgrade']->default_value !== '1.0000000')) { // defaultgrade should be unsigned NOT NULL DEFAULT '1.0000000' // Fixed in earlier upgrade code $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1.0000000', 'generalfeedbackformat'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } // Check if we need to fix penalty if (array_key_exists('penalty', $columns) && (empty($columns['penalty']->not_null) || $columns['penalty']->default_value !== '0.1000000')) { // penalty should be NOT NULL DEFAULT '0.1000000' // Fixed in earlier upgrade code $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0.1000000', 'defaultgrade'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_main_savepoint(true, 2011011408); } if ($oldversion < 2011011409) { // Fix question_answers in the post table after upgrade from 1.9 $columns = $DB->get_columns('question_answers'); $table = new xmldb_table('question_answers'); if (array_key_exists('fraction', $columns) && empty($columns['fraction']->not_null)) { // fraction should be NOT NULL DEFAULT '0.0000000', // Fixed in earlier upgrade code $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'feedback'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_main_savepoint(true, 2011011409); } if ($oldversion < 2011011410) { // Fix question_sessions in the post table after upgrade from 1.9 $columns = $DB->get_columns('question_sessions'); $table = new xmldb_table('question_sessions'); // Check if we need to fix sumpenalty if (array_key_exists('sumpenalty', $columns) && empty($columns['sumpenalty']->not_null)) { // sumpenalty should be NOT NULL DEFAULT '0.0000000', // Fixed in earlier upgrade code $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'newgraded'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_main_savepoint(true, 2011011410); } if ($oldversion < 2011011411) { // Fix question_states in the post table after upgrade from 1.9 $columns = $DB->get_columns('question_states'); $table = new xmldb_table('question_states'); // Check if we need to fix grade if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) { // grade should be NOT NULL DEFAULT '0.0000000', // Fixed in earlier upgrade code $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'event'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } // Check if we need to fix raw_grade if (array_key_exists('raw_grade', $columns) && empty($columns['raw_grade']->not_null)) { // raw_grade should be NOT NULL DEFAULT '0.0000000', // Fixed in earlier upgrade code $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'grade'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } // Check if we need to fix raw_grade if (array_key_exists('penalty', $columns) && empty($columns['penalty']->not_null)) { // penalty should be NOT NULL DEFAULT '0.0000000', // Fixed in earlier upgrade code $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'raw_grade'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } } upgrade_main_savepoint(true, 2011011411); } if ($oldversion < 2011011412) { // Fix tag_instance in the post table after upgrade from 1.9 $columns = $DB->get_columns('tag_instance'); $table = new xmldb_table('tag_instance'); // Check if we need to fix tiuserid if (array_key_exists('tiuserid', $columns) && !empty($columns['tiuserid']->has_default)) { // tiuserid should have no default // Fixed in earlier upgrade code $field = new xmldb_field('tiuserid', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid'); $index = new xmldb_index('itemtype-itemid-tagid-tiuserid', XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } $dbman->add_index($table, $index); } upgrade_main_savepoint(true, 2011011412); } if ($oldversion < 2011011413) { // Fix user_info_field in the post table after upgrade from 1.9 $table = new xmldb_table('user_info_field'); // Missing field descriptionformat // Fixed in earlier upgrade code $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, 2, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'description'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_main_savepoint(true, 2011011413); } if ($oldversion < 2011011414) { // Drop the adodb_logsql table if it exists... it was never actually used anyway. $table = new xmldb_table('adodb_logsql'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } upgrade_main_savepoint(true, 2011011414); } if ($oldversion < 2011011415) { //create the rating table indexes if required $table = new xmldb_table('rating'); $index = new xmldb_index('itemid', XMLDB_INDEX_NOTUNIQUE, array('itemid')); if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); $key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); $dbman->add_key($table, $key); $key = new xmldb_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $dbman->add_key($table, $key); } upgrade_main_savepoint(true, 2011011415); } if ($oldversion < 2011012400) { // Clean up the old progress tracked roles setting, no longer used (replaced by enrolment) unset_config('progresstrackedroles'); upgrade_main_savepoint(true, 2011012400); } if ($oldversion < 2011012500) { $columns = $DB->get_columns('tag_instance'); $table = new xmldb_table('tag_instance'); // Drop and recreate index if tiuserid doesn't have default value if (array_key_exists('tiuserid', $columns) && empty($columns['tiuserid']->has_default)) { // Define index itemtype-itemid-tagid-tiuserid (unique) to be dropped form tag_instance $index = new xmldb_index('itemtype-itemid-tagid-tiuserid', XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); // Conditionally launch drop index itemtype-itemid-tagid-tiuserid if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Changing the default of field tiuserid on table tag_instance to 0 $field = new xmldb_field('tiuserid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'itemid'); // Launch change of default for field tiuserid $dbman->change_field_default($table, $field); $index = new xmldb_index('itemtype-itemid-tagid-tiuserid', XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); // Conditionally launch add index itemtype-itemid-tagid-tiuserid if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } } // Main savepoint reached upgrade_main_savepoint(true, 2011012500); } if ($oldversion < 2011012501) { //add the index userfieldidx (not unique) to user_info_data $table = new xmldb_table('user_info_data'); $index = new xmldb_index('userfieldidx', XMLDB_INDEX_NOTUNIQUE, array('userid', 'fieldid')); if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } upgrade_main_savepoint(true, 2011012501); } if ($oldversion < 2011020200.01) { // Define field targetversion to be added to upgrade_log $table = new xmldb_table('upgrade_log'); $field = new xmldb_field('targetversion', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'version'); // Conditionally launch add field targetversion if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2011020200.01); } if ($oldversion < 2011020900.07) { $DB->delete_records('course_display', array('display' => 0)); upgrade_main_savepoint(true, 2011020900.07); } if ($oldversion < 2011020900.08) { // Define field secret to be added to registration_hubs $table = new xmldb_table('registration_hubs'); $field = new xmldb_field('secret', XMLDB_TYPE_CHAR, '255', null, null, null, $CFG->siteidentifier, 'confirmed'); // Conditionally launch add field secret if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2011020900.08); } if ($oldversion < 2011022100.01) { // hack alert: inject missing version of manual auth_plugin, // we need to do it so that we may use upgrade.php there set_config('version', 2011022100, 'auth_manual'); upgrade_main_savepoint(true, 2011022100.01); } if ($oldversion < 2011052300.0) { $table = new xmldb_table('rating'); // Add the component field to the ratings table upgrade_set_timeout(60 * 20); $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, 'unknown', 'contextid'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Add the ratingarea field to the ratings table upgrade_set_timeout(60 * 20); $field = new xmldb_field('ratingarea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, 'unknown', 'component'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_main_savepoint(true, 2011052300.0); } if ($oldversion < 2011052300.01) { // Define index uniqueuserrating (unique) to be added to rating $table = new xmldb_table('rating'); $index = new xmldb_index('uniqueuserrating', XMLDB_INDEX_NOTUNIQUE, array('component', 'ratingarea', 'contextid', 'itemid')); // Conditionally launch add index uniqueuserrating if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2011052300.01); } if ($oldversion < 2011052300.02) { // Define index itemid (not unique) to be dropped form rating $table = new xmldb_table('rating'); $index = new xmldb_index('itemid', XMLDB_INDEX_NOTUNIQUE, array('itemid')); // Conditionally launch drop index itemid if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2011052300.02); } // Question engine 2 changes (14) start here if ($oldversion < 2011060300) { // Changing the default of field penalty on table question to 0.3333333 $table = new xmldb_table('question'); $field = new xmldb_field('penalty'); $field->set_attributes(XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0.3333333'); // Launch change of default for field penalty $dbman->change_field_default($table, $field); // quiz savepoint reached upgrade_main_savepoint(true, 2011060300); } if ($oldversion < 2011060301) { // Rename field defaultgrade on table question to defaultmark $table = new xmldb_table('question'); $field = new xmldb_field('defaultgrade'); $field->set_attributes(XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '1'); // Launch rename field defaultmark if ($dbman->field_exists($table, $field)) { $dbman->rename_field($table, $field, 'defaultmark'); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060301); } if ($oldversion < 2011060302) { // Rename the question_attempts table to question_usages. $table = new xmldb_table('question_attempts'); if (!$dbman->table_exists('question_usages')) { $dbman->rename_table($table, 'question_usages'); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060302); } if ($oldversion < 2011060303) { // Rename the modulename field to component ... $table = new xmldb_table('question_usages'); $field = new xmldb_field('modulename'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'contextid'); if ($dbman->field_exists($table, $field)) { $dbman->rename_field($table, $field, 'component'); } // ... and update its contents. $DB->set_field('question_usages', 'component', 'mod_quiz', array('component' => 'quiz')); // Add the contextid field. $field = new xmldb_field('contextid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'id'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); // And populate it. $quizmoduleid = $DB->get_field('modules', 'id', array('name' => 'quiz')); $DB->execute("\n UPDATE {question_usages} SET contextid = (\n SELECT ctx.id\n FROM {context} ctx\n JOIN {course_modules} cm ON cm.id = ctx.instanceid AND cm.module = {$quizmoduleid}\n JOIN {quiz_attempts} quiza ON quiza.quiz = cm.instance\n WHERE ctx.contextlevel = " . CONTEXT_MODULE . "\n AND quiza.uniqueid = {question_usages}.id\n )\n "); // It seems that it is possible, in old versions of Moodle, for a // quiz_attempt to be deleted while the question_attempt remains. // In that situation we still get NULLs left in the table, which // causes the upgrade to break at the next step. To avoid breakage, // without risking dataloss, we just replace all NULLs with 0 here. $DB->set_field_select('question_usages', 'contextid', 0, 'contextid IS NULL'); // Then make it NOT NULL. $field = new xmldb_field('contextid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'id'); $dbman->change_field_notnull($table, $field); } // Add the preferredbehaviour column. Populate it with a dummy value // for now. We will fill in the appropriate behaviour name when // updating all the rest of the attempt data. $field = new xmldb_field('preferredbehaviour'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, 'to_be_set_later', 'component'); $dbman->add_field($table, $field); // Then remove the default value, now the column is populated. $field = new xmldb_field('preferredbehaviour'); $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'component'); $dbman->change_field_default($table, $field); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060303); } if ($oldversion < 2011060304) { // Define key contextid (foreign) to be added to question_usages $table = new xmldb_table('question_usages'); $key = new XMLDBKey('contextid'); $key->set_attributes(XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); // Launch add key contextid $dbman->add_key($table, $key); // quiz savepoint reached upgrade_main_savepoint(true, 2011060304); } if ($oldversion < 2011060305) { // Changing precision of field component on table question_usages to (255) // This was missed during the upgrade from old versions. $table = new xmldb_table('question_usages'); $field = new xmldb_field('component'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'contextid'); // Launch change of precision for field component $dbman->change_field_precision($table, $field); // quiz savepoint reached upgrade_main_savepoint(true, 2011060305); } if ($oldversion < 2011060306) { // Define table question_attempts to be created $table = new xmldb_table('question_attempts'); if (!$dbman->table_exists($table)) { // Adding fields to table question_attempts $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('questionusageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('slot', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('behaviour', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, null); $table->add_field('minfraction', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, null); $table->add_field('flagged', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('questionsummary', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('rightanswer', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('responsesummary', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); // Adding keys to table question_attempts $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id')); $table->add_key('questionusageid', XMLDB_KEY_FOREIGN, array('questionusageid'), 'question_usages', array('id')); // Adding indexes to table question_attempts $table->add_index('questionusageid-slot', XMLDB_INDEX_UNIQUE, array('questionusageid', 'slot')); // Launch create table for question_attempts $dbman->create_table($table); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060306); } if ($oldversion < 2011060307) { // Define table question_attempt_steps to be created $table = new xmldb_table('question_attempt_steps'); if (!$dbman->table_exists($table)) { // Adding fields to table question_attempt_steps $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('questionattemptid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('sequencenumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('state', XMLDB_TYPE_CHAR, '13', null, XMLDB_NOTNULL, null, null); $table->add_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); // Adding keys to table question_attempt_steps $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('questionattemptid', XMLDB_KEY_FOREIGN, array('questionattemptid'), 'question_attempts_new', array('id')); $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); // Adding indexes to table question_attempt_steps $table->add_index('questionattemptid-sequencenumber', XMLDB_INDEX_UNIQUE, array('questionattemptid', 'sequencenumber')); // Launch create table for question_attempt_steps $dbman->create_table($table); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060307); } if ($oldversion < 2011060308) { // Define table question_attempt_step_data to be created $table = new xmldb_table('question_attempt_step_data'); if (!$dbman->table_exists($table)) { // Adding fields to table question_attempt_step_data $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('attemptstepid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); // Adding keys to table question_attempt_step_data $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('attemptstepid', XMLDB_KEY_FOREIGN, array('attemptstepid'), 'question_attempt_steps', array('id')); // Adding indexes to table question_attempt_step_data $table->add_index('attemptstepid-name', XMLDB_INDEX_UNIQUE, array('attemptstepid', 'name')); // Launch create table for question_attempt_step_data $dbman->create_table($table); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060308); } if ($oldversion < 2011060309) { // Define table question_hints to be created $table = new xmldb_table('question_hints'); // Adding fields to table question_hints $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('hint', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); $table->add_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('shownumcorrect', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); $table->add_field('clearwrong', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); $table->add_field('options', XMLDB_TYPE_CHAR, '255', null, null, null, null); // Adding keys to table question_hints $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id')); // Conditionally launch create table for question_hints if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060309); } if ($oldversion < 2011060310) { // In the past, question_answer fractions were stored with rather // sloppy rounding. Now update them to the new standard of 7 d.p. $changes = array('-0.66666' => '-0.6666667', '-0.33333' => '-0.3333333', '-0.16666' => '-0.1666667', '-0.142857' => '-0.1428571', '0.11111' => '0.1111111', '0.142857' => '0.1428571', '0.16666' => '0.1666667', '0.33333' => '0.3333333', '0.333333' => '0.3333333', '0.66666' => '0.6666667'); foreach ($changes as $from => $to) { $DB->set_field('question_answers', 'fraction', $to, array('fraction' => $from)); } // quiz savepoint reached upgrade_main_savepoint(true, 2011060310); } if ($oldversion < 2011060311) { // In the past, question penalties were stored with rather // sloppy rounding. Now update them to the new standard of 7 d.p. $DB->set_field('question', 'penalty', 0.3333333, array('penalty' => 33.3)); $DB->set_field_select('question', 'penalty', 0.3333333, 'penalty >= 0.33 AND penalty <= 0.34'); $DB->set_field_select('question', 'penalty', 0.6666666999999999, 'penalty >= 0.66 AND penalty <= 0.67'); $DB->set_field_select('question', 'penalty', 1, 'penalty > 1'); // quiz savepoint reached upgrade_main_savepoint(true, 2011060311); } if ($oldversion < 2011060312) { // Define field hintformat to be added to question_hints table. $table = new xmldb_table('question_hints'); $field = new xmldb_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); // Conditionally launch add field partiallycorrectfeedbackformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_main_savepoint(true, 2011060312); } if ($oldversion < 2011060313) { // Define field variant to be added to question_attempts $table = new xmldb_table('question_attempts'); $field = new xmldb_field('variant', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 1, 'questionid'); // Launch add field component if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2011060313); } // Question engine 2 changes (14) end here if ($oldversion < 2011060500) { // Define index uniqueuserrating (not unique) to be dropped from rating $table = new xmldb_table('rating'); $index = new xmldb_index('uniqueuserrating', XMLDB_INDEX_NOTUNIQUE, array('component', 'ratingarea', 'contextid', 'itemid')); // Drop dependent index before changing fields specs if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Changing the default of field component on table rating to drop it $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'contextid'); // Launch change of default for field component $dbman->change_field_default($table, $field); // Changing the default of field ratingarea on table rating to drop it $field = new xmldb_field('ratingarea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'component'); // Launch change of default for field ratingarea $dbman->change_field_default($table, $field); // Add dependent index back if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Main savepoint reached upgrade_main_savepoint(true, 2011060500); } if ($oldversion < 2011060800) { // Add enabled field to message_processors $table = new xmldb_table('message_processors'); $field = new xmldb_field('enabled'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'name'); // Launch add field addition if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Populate default messaging settings upgrade_populate_default_messaging_prefs(); upgrade_main_savepoint(true, 2011060800); } if ($oldversion < 2011060800.01) { //TODO: put the right latest version // Define field shortname to be added to external_services $table = new xmldb_table('external_services'); $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'timemodified'); // Conditionally launch add field shortname if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Main savepoint reached upgrade_main_savepoint(true, 2011060800.01); } if ($oldversion < 2011062000.01) { // Changing sign of field minfraction on table question_attempts to signed $table = new xmldb_table('question_attempts'); $field = new xmldb_field('minfraction', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, null, 'maxmark'); // Launch change of sign for field minfraction $dbman->change_field_unsigned($table, $field); // Main savepoint reached upgrade_main_savepoint(true, 2011062000.01); } // Signed fixes - MDL-28032 if ($oldversion < 2011062400.02) { // Changing sign of field defaultmark on table question to unsigned $table = new xmldb_table('question'); $field = new xmldb_field('defaultmark', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '1', 'generalfeedbackformat'); // Launch change of sign for field defaultmark $dbman->change_field_unsigned($table, $field); // Main savepoint reached upgrade_main_savepoint(true, 2011062400.02); } if ($oldversion < 2011062400.03) { // Completion system has issue in which possible duplicate rows are // added to the course_modules_completion table. This change deletes // the older version of duplicate rows and replaces an index with a // unique one so it won't happen again. // This would have been a single query but because MySQL is a PoS // and can't do subqueries in DELETE, I have made it into two. The // system is unlikely to run out of memory as only IDs are stored in // the array. // Find all rows cmc1 where there is another row cmc2 with the // same user id and the same coursemoduleid, but a higher id (=> newer, // meaning that cmc1 is an older row). $rs = $DB->get_recordset_sql("\nSELECT DISTINCT\n cmc1.id\nFROM\n {course_modules_completion} cmc1\n JOIN {course_modules_completion} cmc2\n ON cmc2.userid = cmc1.userid\n AND cmc2.coursemoduleid = cmc1.coursemoduleid\n AND cmc2.id > cmc1.id"); $deleteids = array(); foreach ($rs as $row) { $deleteids[] = $row->id; } $rs->close(); // Note: SELECT part performance tested on table with ~7m // rows of which ~15k match, only took 30 seconds so probably okay. // Delete all those rows $DB->delete_records_list('course_modules_completion', 'id', $deleteids); // Define index userid (not unique) to be dropped form course_modules_completion $table = new xmldb_table('course_modules_completion'); $index = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); // Conditionally launch drop index userid if ($dbman->index_exists($table, $index)) { $dbman->drop_index($table, $index); } // Define index userid-coursemoduleid (unique) to be added to course_modules_completion $index = new xmldb_index('userid-coursemoduleid', XMLDB_INDEX_UNIQUE, array('userid', 'coursemoduleid')); // Conditionally launch add index userid-coursemoduleid if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } upgrade_main_savepoint(true, 2011062400.03); } // Moodle v2.1.0 release upgrade line // Put any upgrade step following this return true; }
/** * This file keeps track of upgrades to the certificate module * * @package mod_certificate * @copyright Mark Nelson <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_certificate_upgrade($oldversion = 0) { global $CFG, $THEME, $DB; $dbman = $DB->get_manager(); // ===== 1.9.0 or older upgrade line ======// if ($oldversion < 2007061300) { // Add new fields to certificate table $table = new xmldb_table('certificate'); $field = new xmldb_field('emailothers'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'emailteachers'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('certificate'); $field = new xmldb_field('printhours'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'gradefmt'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('certificate'); $field = new xmldb_field('lockgrade'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'printhours'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('certificate'); $field = new xmldb_field('requiredgrade'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'lockgrade'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Rename field save to savecert $field = new xmldb_field('save'); if ($dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'emailothers'); // Launch rename field savecert $dbman->rename_field($table, $field, 'savecert'); } else { $field = new xmldb_field('savecert'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'emailothers'); $dbman->add_field($table, $field); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2007061300, 'certificate'); } if ($oldversion < 2007061301) { $table = new xmldb_table('certificate_linked_modules'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); $table->add_field('certificate_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); $table->add_field('linkid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'certificate_id'); $table->add_field('linkgrade', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'linkid'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'linkgrade'); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null); $table->add_index('certificate_id', XMLDB_INDEX_NOTUNIQUE, array('certificate_id')); $table->add_index('linkid', XMLDB_INDEX_NOTUNIQUE, array('linkid')); if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2007061301, 'certificate'); } if ($oldversion < 2007102800) { // Add new fields to certificate table $table = new xmldb_table('certificate'); $field = new xmldb_field('reportcert'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'savecert'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('certificate_issues'); $field = new xmldb_field('reportgrade'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, null, null, null, 'certdate'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2007102800, 'certificate'); } if ($oldversion < 2007102806) { // Add new fields to certificate table $table = new xmldb_table('certificate'); $field = new xmldb_field('printoutcome'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'gradefmt'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2007102806, 'certificate'); } if ($oldversion < 2008080904) { // Add new fields to certificate table if they dont already exist $table = new xmldb_table('certificate'); $field = new xmldb_field('intro'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'name'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2008080904, 'certificate'); } //===== 2.0 or older upgrade line ======// // Note, fresh 1.9 installs add the version 2009080900, so they miss this when upgrading from 1.9 -> 2.0. if ($oldversion < 2009062900) { // Add new field to certificate table $table = new xmldb_table('certificate'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('orientation', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, ' ', 'certificatetype'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('reissuecert', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'reportcert'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Set default orientation accordingly $DB->set_field('certificate', 'orientation', 'P', array('certificatetype' => 'portrait')); $DB->set_field('certificate', 'orientation', 'P', array('certificatetype' => 'letter_portrait')); $DB->set_field('certificate', 'orientation', 'P', array('certificatetype' => 'unicode_portrait')); $DB->set_field('certificate', 'orientation', 'L', array('certificatetype' => 'landscape')); $DB->set_field('certificate', 'orientation', 'L', array('certificatetype' => 'letter_landscape')); $DB->set_field('certificate', 'orientation', 'L', array('certificatetype' => 'unicode_landscape')); // Update all the certificate types $DB->set_field('certificate', 'certificatetype', 'A4_non_embedded', array('certificatetype' => 'landscape')); $DB->set_field('certificate', 'certificatetype', 'A4_non_embedded', array('certificatetype' => 'portrait')); $DB->set_field('certificate', 'certificatetype', 'A4_embedded', array('certificatetype' => 'unicode_landscape')); $DB->set_field('certificate', 'certificatetype', 'A4_embedded', array('certificatetype' => 'unicode_portrait')); $DB->set_field('certificate', 'certificatetype', 'letter_non_embedded', array('certificatetype' => 'letter_landscape')); $DB->set_field('certificate', 'certificatetype', 'letter_non_embedded', array('certificatetype' => 'letter_portrait')); // savepoint reached upgrade_mod_savepoint(true, 2009062900, 'certificate'); } if ($oldversion < 2011030105) { // Define field id to be added to certificate $table = new xmldb_table('certificate'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 0, 'intro'); // Conditionally launch add field id if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2011030105, 'certificate'); } // The Moodle 2.0 CVS certificate version sets it to 2011110101, if the user performed an upgrade // then this upgrade will take care of several issues, if it's a fresh install then nothing is done. if ($oldversion < 2011110102) { require_once $CFG->libdir . '/conditionlib.php'; $table = new xmldb_table('certificate'); // It is possible for these fields not to be added, ever, it is included in the upgrade // process but fresh certificate 1.9 install from CVS MOODLE_19_STABLE set the Moodle version // to 2009080900, which means it missed all the earlier code written for upgrading to 2.0. $reissuefield = new xmldb_field('reissuecert', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'reportcert'); $orientationfield = new xmldb_field('orientation', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, ' ', 'certificatetype'); // Have to check, may be added during earlier upgrade, or may be missing due to not being included in install.xml if (!$dbman->field_exists($table, $reissuefield)) { $dbman->add_field($table, $reissuefield); } if (!$dbman->field_exists($table, $orientationfield)) { $dbman->add_field($table, $orientationfield); } // Fresh 2.0 installs won't have this table, but upgrades from 1.9 will if ($dbman->table_exists('certificate_linked_modules')) { // No longer need lock grade, or required grade, but first need to // convert so that the restrictions are still in place for Moodle 2.0 if ($certs = $DB->get_records('certificate')) { foreach ($certs as $cert) { if ($cert->lockgrade == 0) { // Can skip this certificate, no course grade required continue; } if (!($cm = get_coursemodule_from_instance('certificate', $cert->id))) { // Not valid skip it continue; } if (!($gradeitem = $DB->get_record('grade_items', array('courseid' => $cm->course, 'itemtype' => 'course')))) { // Not valid skip it continue; } $condition_info = new condition_info($cm, CONDITION_MISSING_EVERYTHING); $condition_info->add_grade_condition($gradeitem->id, $cert->requiredgrade, '110'); } } // Fresh installs won't have this table, but upgrades will // Lock grade and required grade field are not needed anymore if ($dbman->field_exists($table, 'lockgrade')) { $field = new xmldb_field('lockgrade'); $dbman->drop_field($table, $field); } if ($dbman->field_exists($table, 'requiredgrade')) { $field = new xmldb_field('requiredgrade'); $dbman->drop_field($table, $field); } // Now we need to loop through the restrictions in the certificate_linked_modules // table and convert it into the new Moodle 2.0 restrictions if ($certlinks = $DB->get_records('certificate_linked_modules')) { foreach ($certlinks as $link) { // If the link id is '-1' then the setting applies to the time spent in the course and is not // related to a module, meaning we can skip it for this section if ($link->linkid == '-1') { continue; } // Get the course module if (!($cm = get_coursemodule_from_instance('certificate', $link->certificate_id))) { // Not valid skip it continue; } // Get grade item for module specified - is there an API function for this ?? $sql = "SELECT gi.id\n FROM {course_modules} cm\n INNER JOIN {modules} m\n ON cm.module = m.id\n INNER JOIN {grade_items} gi\n ON m.name = gi.itemmodule\n WHERE cm.id = :cmid\n AND cm.course = :courseid\n AND cm.instance = gi.iteminstance"; if (!($gradeitem = $DB->get_record_sql($sql, array('cmid' => $link->linkid, 'courseid' => $cm->course)))) { // Not valid skip it continue; } $condition_info = new condition_info($cm, CONDITION_MISSING_EVERYTHING); $condition_info->add_grade_condition($gradeitem->id, $link->linkgrade, '110', true); } } } // Certificate savepoint reached upgrade_mod_savepoint(true, 2011110102, 'certificate'); } // Note - the date has not changed as it has been set in the future, so I am incrementing // last digits. Actual date - 15/09/11 if ($oldversion < 2011110103) { // New orientation field needs a value in order to view the cert, otherwise you get // an issue with FPDF and invalid orientation. This should be done during the upgrade, // but due to version number issues it is possible it was not executed, so do it now. $DB->set_field('certificate', 'orientation', 'P', array('certificatetype' => 'portrait')); $DB->set_field('certificate', 'orientation', 'P', array('certificatetype' => 'letter_portrait')); $DB->set_field('certificate', 'orientation', 'P', array('certificatetype' => 'unicode_portrait')); $DB->set_field('certificate', 'orientation', 'L', array('certificatetype' => 'landscape')); $DB->set_field('certificate', 'orientation', 'L', array('certificatetype' => 'letter_landscape')); $DB->set_field('certificate', 'orientation', 'L', array('certificatetype' => 'unicode_landscape')); // If the certificate type does not match any of the orientations in the above then set to 'L' $sql = "UPDATE {certificate}\n SET orientation = 'L'\n WHERE orientation = ''"; $DB->execute($sql); // Update all the certificate types $DB->set_field('certificate', 'certificatetype', 'A4_non_embedded', array('certificatetype' => 'landscape')); $DB->set_field('certificate', 'certificatetype', 'A4_non_embedded', array('certificatetype' => 'portrait')); $DB->set_field('certificate', 'certificatetype', 'A4_embedded', array('certificatetype' => 'unicode_landscape')); $DB->set_field('certificate', 'certificatetype', 'A4_embedded', array('certificatetype' => 'unicode_portrait')); $DB->set_field('certificate', 'certificatetype', 'letter_non_embedded', array('certificatetype' => 'letter_landscape')); $DB->set_field('certificate', 'certificatetype', 'letter_non_embedded', array('certificatetype' => 'letter_portrait')); // Certificate savepoint reached upgrade_mod_savepoint(true, 2011110103, 'certificate'); } if ($oldversion < 2012022001) { // CONTRIB-3470 - certdate remaining 0 on issued certificates, need to update $sql = "UPDATE {certificate_issues}\n SET certdate = timecreated\n WHERE certdate = 0"; $DB->execute($sql); // Certificate savepoint reached upgrade_mod_savepoint(true, 2012022001, 'certificate'); } if ($oldversion < 2012060901) { // Editing this table $table = new xmldb_table('certificate'); // Get rid of the reissue cert column, this was a hack introduced later // in 1.9 when the bug was brought up that grades were not refreshing // since they were being stored in the issues table. // The certificate will now always return the current grade, student name // and course name. $field = new xmldb_field('reissuecert'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // The poor certificate_issues table is going to have a lot of // duplicates, we don't need that now, just keep the latest one $sql = "SELECT MAX(id) id1, MAX(id) as id2\n FROM {certificate_issues}\n GROUP BY certificateid, userid"; if ($arrids = $DB->get_records_sql_menu($sql)) { $idstokeep = implode(",", $arrids); $sql = "DELETE\n FROM {certificate_issues}\n WHERE id NOT IN ({$idstokeep})"; $DB->execute($sql); } // Going to be editing this table $table = new xmldb_table('certificate_issues'); // Conditionally remove columns no longer needed $field = new xmldb_field('studentname'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } $field = new xmldb_field('classname'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } $field = new xmldb_field('certdate'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } $field = new xmldb_field('reportgrade'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } $field = new xmldb_field('mailed'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2012060901, 'certificate'); } if ($oldversion < 2012072501) { // Add a column to store the required grade $table = new xmldb_table('certificate'); $requiredtimefield = new xmldb_field('requiredtime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'delivery'); if (!$dbman->field_exists($table, $requiredtimefield)) { $dbman->add_field($table, $requiredtimefield); } // If this table still exists, then the install was from a 1.9 version if ($dbman->table_exists('certificate_linked_modules')) { // Now we need to loop through the restrictions in the certificate_linked_modules // table and check if there were any required time conditions if ($certlinks = $DB->get_records('certificate_linked_modules')) { foreach ($certlinks as $link) { // If the link id is '-1' then the setting applies to the time spent in the course if ($link->linkid == '-1') { // Make sure the certificate exists if ($certificate = $DB->get_record('certificate', array('id' => $link->certificate_id))) { $certificate->requiredtime = $link->linkgrade; $DB->update_record('certificate', $certificate); } } } } // We can now get rid of this table $table = new xmldb_table('certificate_linked_modules'); $dbman->drop_table($table); } // Certificate savepoint reached upgrade_mod_savepoint(true, 2012072501, 'certificate'); } if ($oldversion < 2012082401) { $table = new xmldb_table('certificate'); // Change length of the fields that store images, so longer image names can be stored $field = new xmldb_field('borderstyle', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0); $dbman->change_field_precision($table, $field); $field = new xmldb_field('printwmark', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0); $dbman->change_field_precision($table, $field); $field = new xmldb_field('printsignature', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0); $dbman->change_field_precision($table, $field); $field = new xmldb_field('printseal', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0); $dbman->change_field_precision($table, $field); // Change length of fields that are unnecessarily large $field = new xmldb_field('printnumber', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0); $dbman->change_field_precision($table, $field); $field = new xmldb_field('printhours', XMLDB_TYPE_CHAR, '255', null, false, 0, 0); $dbman->change_field_precision($table, $field); $field = new xmldb_field('emailteachers', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0); $dbman->change_field_precision($table, $field); $field = new xmldb_field('savecert', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0); $dbman->change_field_precision($table, $field); $field = new xmldb_field('reportcert', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, 0, 0); $dbman->change_field_precision($table, $field); // Certificate savepoint reached upgrade_mod_savepoint(true, 2012082401, 'certificate'); } if ($oldversion < 2012090901) { $table = new xmldb_table('certificate'); $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, 0, 0, 'printseal'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Set the time created to the time modified $sql = "UPDATE {certificate}\n SET timecreated = timemodified"; $DB->execute($sql); // Certificate savepoint reached upgrade_mod_savepoint(true, 2012090901, 'certificate'); } if ($oldversion < 2014041802) { // Fix previous upgrades. $table = new xmldb_table('certificate'); $field = new xmldb_field('borderstyle', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0'); $dbman->change_field_default($table, $field); $field = new xmldb_field('printwmark', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0'); $dbman->change_field_default($table, $field); $field = new xmldb_field('printhours', XMLDB_TYPE_CHAR, '255', null, false, 0, null); $dbman->change_field_default($table, $field); $field = new xmldb_field('printsignature', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0'); $dbman->change_field_default($table, $field); $field = new xmldb_field('printseal', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, 0, '0'); $dbman->change_field_default($table, $field); // Certificate savepoint reached. upgrade_mod_savepoint(true, 2014041802, 'certificate'); } return true; }
function xmldb_feedback_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); $result = true; if ($result && $oldversion < 2007012310) { //create a new table feedback_completedtmp and the field-definition $table = new xmldb_table('feedback_completedtmp'); $field = new xmldb_field('id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null); $table->addField($field); $field = new xmldb_field('feedback'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('userid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('guestid'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, '', null); $table->addField($field); $field = new xmldb_field('timemodified'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $key = new xmldb_key('PRIMARY'); $key->set_attributes(XMLDB_KEY_PRIMARY, array('id')); $table->addKey($key); $key = new xmldb_key('feedback'); $key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id'); $table->addKey($key); $dbman->create_table($table); //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //create a new table feedback_valuetmp and the field-definition $table = new xmldb_table('feedback_valuetmp'); $field = new xmldb_field('id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null); $table->addField($field); $field = new xmldb_field('course_id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('item'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('completed'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('tmp_completed'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('value'); $field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, '', null); $table->addField($field); $key = new xmldb_key('PRIMARY'); $key->set_attributes(XMLDB_KEY_PRIMARY, array('id')); $table->addKey($key); $key = new xmldb_key('feedback'); $key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id'); $table->addKey($key); $dbman->create_table($table); //////////////////////////////////////////////////////////// upgrade_mod_savepoint($result, 2007012310, 'feedback'); } if ($result && $oldversion < 2007050504) { /// Define field random_response to be added to feedback_completed $table = new xmldb_table('feedback_completed'); $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); /// Launch add field1 $dbman->add_field($table, $field); /// Define field anonymous_response to be added to feedback_completed $table = new xmldb_table('feedback_completed'); $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); /// Launch add field2 $dbman->add_field($table, $field); /// Define field random_response to be added to feedback_completed $table = new xmldb_table('feedback_completedtmp'); $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); /// Launch add field1 $dbman->add_field($table, $field); /// Define field anonymous_response to be added to feedback_completed $table = new xmldb_table('feedback_completedtmp'); $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); /// Launch add field2 $dbman->add_field($table, $field); //////////////////////////////////////////////////////////// upgrade_mod_savepoint($result, 2007050504, 'feedback'); } if ($result && $oldversion < 2007102600) { // public is a reserved word on Oracle $table = new xmldb_table('feedback_template'); $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint($result, 2007102600, 'feedback'); } if ($result && $oldversion < 2008042400) { //New version in version.php if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', 'anonymous', 2)) { $update_sql = 'UPDATE {feedback_completed} SET anonymous_response = 2 WHERE feedback = '; foreach ($all_nonanonymous_feedbacks as $fb) { $result = $result && $DB->execute($update_sql . $fb->id); } } upgrade_mod_savepoint($result, 2008042400, 'feedback'); } if ($result && $oldversion < 2008042401) { //New version in version.php if ($result) { $concat_radio = $DB->sql_concat("'r>>>>>'", 'presentation'); $concat_check = $DB->sql_concat("'c>>>>>'", 'presentation'); $concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation'); $update_sql1 = "UPDATE {feedback_item} SET presentation = " . $concat_radio . " WHERE typ IN('radio','radiorated')"; $update_sql2 = "UPDATE {feedback_item} SET presentation = " . $concat_dropdown . " WHERE typ IN('dropdown','dropdownrated')"; $update_sql3 = "UPDATE {feedback_item} SET presentation = " . $concat_check . " WHERE typ = 'check'"; $result = $result && $DB->execute($update_sql1); $result = $result && $DB->execute($update_sql2); $result = $result && $DB->execute($update_sql3); } if ($result) { $update_sql1 = "UPDATE {feedback_item} SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')"; $update_sql2 = "UPDATE {feedback_item} SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')"; $result = $result && $DB->execute($update_sql1); $result = $result && $DB->execute($update_sql2); } upgrade_mod_savepoint($result, 2008042401, 'feedback'); } if ($result && $oldversion < 2008042801) { $new_log_display = new object(); $new_log_display->module = 'feedback'; $new_log_display->action = 'startcomplete'; $new_log_display->mtable = 'feedback'; $new_log_display->field = 'name'; $result = $result && $DB->insert_record('log_display', $new_log_display); $new_log_display = clone $new_log_display; $new_log_display->action = 'submit'; $result = $result && $DB->insert_record('log_display', $new_log_display); $new_log_display = clone $new_log_display; $new_log_display->action = 'delete'; $result = $result && $DB->insert_record('log_display', $new_log_display); $new_log_display = clone $new_log_display; $new_log_display->action = 'view'; $result = $result && $DB->insert_record('log_display', $new_log_display); $new_log_display = clone $new_log_display; $new_log_display->action = 'view all'; $new_log_display->mtable = 'course'; $new_log_display->field = 'shortname'; $result = $result && $DB->insert_record('log_display', $new_log_display); upgrade_mod_savepoint($result, 2008042801, 'feedback'); } if ($result && $oldversion < 2008042900) { /// Define field autonumbering to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit'); /// Launch add field2 $dbman->add_field($table, $field); upgrade_mod_savepoint($result, 2008042900, 'feedback'); } if ($result && $oldversion < 2008050104) { /// Define field site_after_submit to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'autonumbering'); /// Launch add field2 $dbman->add_field($table, $field); upgrade_mod_savepoint($result, 2008050104, 'feedback'); } if ($result && $oldversion < 2008050105) { //field count is not more needed $table = new xmldb_table('feedback_tracking'); $field = new xmldb_field('count'); $dbman->drop_field($table, $field); upgrade_mod_savepoint($result, 2008050105, 'feedback'); } if ($result && $oldversion < 2008073002) { $update_sql = "UPDATE {feedback_item} SET presentation = '-|-' WHERE presentation = '0|0' AND typ = 'numeric'"; $result = $result && $DB->execute($update_sql); upgrade_mod_savepoint($result, 2008073002, 'feedback'); } if ($result && $oldversion < 2009031301) { /// Define field label to be added to feedback_item $table = new xmldb_table('feedback_item'); $field = new xmldb_field('label', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'name'); /// Launch add field2 $dbman->add_field($table, $field); upgrade_mod_savepoint($result, 2009031301, 'feedback'); } if ($result && $oldversion < 2009042000) { /// Rename field summary on table feedback to intro $table = new xmldb_table('feedback'); $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name'); /// Launch rename field summary $dbman->rename_field($table, $field, 'intro'); /// feedback savepoint reached upgrade_mod_savepoint($result, 2009042000, 'feedback'); } if ($result && $oldversion < 2009042001) { /// Define field introformat to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Launch add field introformat $dbman->add_field($table, $field); /// feedback savepoint reached upgrade_mod_savepoint($result, 2009042001, 'feedback'); } return $result; }
/** * * @global stdClass $CFG * @global moodle_database $DB * @global core_renderer $OUTPUT * @param int $oldversion * @return bool */ function xmldb_lesson_upgrade($oldversion) { global $CFG, $DB, $OUTPUT; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($oldversion < 2007072201) { $table = new xmldb_table('lesson'); $field = new xmldb_field('usegrademax'); $field2 = new xmldb_field('usemaxgrade'); /// Rename lesson->usegrademax to lesson->usemaxgrade. Some old sites can have it incorrect. MDL-13177 if ($dbman->field_exists($table, $field) && !$dbman->field_exists($table, $field2)) { /// Set field specs $field->set_attributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'ongoing'); /// Launch rename field usegrademax to usemaxgrade $dbman->rename_field($table, $field, 'usemaxgrade'); } upgrade_mod_savepoint(true, 2007072201, 'lesson'); } if ($oldversion < 2008112601) { //NOTE: this is a hack, we can not call module lib.php in the middle of upgrade, the necessary db structures/data may not exist yet! require_once($CFG->dirroot.'/mod/lesson/lib.php'); lesson_upgrade_grades(); upgrade_mod_savepoint(true, 2008112601, 'lesson'); } if ($oldversion < 2009111600) { /** * Change the grade field within lesson_answers to an unsigned int and increment * the length by one to ensure that no values are changed (reduced) */ $table = new xmldb_table('lesson_answers'); $field = new xmldb_field('grade'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', false, XMLDB_NOTNULL, null, '0', 'jumpto'); $dbman->change_field_type($table, $field); upgrade_mod_savepoint(true, 2009111600, 'lesson'); } if ($oldversion < 2009120800) { /** * Drop the lesson_default table, as of Moodle 2.0 it is no longer used * the module now has a settings.php instead */ $table = new xmldb_table('lesson_default'); $dbman->drop_table($table); upgrade_mod_savepoint(true, 2009120800, 'lesson'); } if ($oldversion < 2009120801) { /// Define field contentsformat to be added to lesson_pages $table = new xmldb_table('lesson_pages'); $field = new xmldb_field('contentsformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, FORMAT_MOODLE, 'contents'); /// Conditionally launch add field contentsformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in contents if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('lesson_pages', array('contentsformat'=>FORMAT_MOODLE), '', 'id,contents,contentsformat'); foreach ($rs as $lp) { $lp->contents = text_to_html($lp->contents, false, false, true); $lp->contentsformat = FORMAT_HTML; $DB->update_record('lesson_pages', $lp); upgrade_set_timeout(); } $rs->close(); } /// lesson savepoint reached upgrade_mod_savepoint(true, 2009120801, 'lesson'); } if ($oldversion < 2010072000) { // Define field answerformat to be added to lesson_answers $table = new xmldb_table('lesson_answers'); $field = new xmldb_field('answerformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'answer'); // Launch add field answerformat $dbman->add_field($table, $field); // lesson savepoint reached upgrade_mod_savepoint(true, 2010072000, 'lesson'); } if ($oldversion < 2010072001) { // Define field responseformat to be added to lesson_answers $table = new xmldb_table('lesson_answers'); $field = new xmldb_field('responseformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'response'); // Launch add field responseformat $dbman->add_field($table, $field); // lesson savepoint reached upgrade_mod_savepoint(true, 2010072001, 'lesson'); } if ($oldversion < 2010072003) { $rs = $DB->get_recordset('lesson_answers', array()); foreach ($rs as $answer) { $flags = intval($answer->flags); $update = false; if ($flags & 1) { $answer->answer = text_to_html($answer->answer, false, false, true); $answer->answerformat = FORMAT_HTML; $update = true; } if ($flags & 2) { $answer->response = text_to_html($answer->response, false, false, true); $answer->responseformat = FORMAT_HTML; $update = true; } if ($update) { $DB->update_record('lesson_answers', $answer); } } $rs->close(); upgrade_mod_savepoint(true, 2010072003, 'lesson'); } if ($oldversion < 2010081200) { require_once("$CFG->dirroot/mod/lesson/db/upgradelib.php"); $sqlfrom = "FROM {lesson} l JOIN {modules} m ON m.name = 'lesson' JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = l.id)"; $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); if ($count > 0) { $rs = $DB->get_recordset_sql("SELECT l.id, l.mediafile, l.course, cm.id AS cmid $sqlfrom ORDER BY l.course, l.id"); $pbar = new progress_bar('migratelessonfiles', 500, true); $fs = get_file_storage(); $i = 0; foreach ($rs as $lesson) { $i++; upgrade_set_timeout(120); // set up timeout, may also abort execution $pbar->update($i, $count, "Migrating lesson files - $i/$count."); // fix images incorrectly placed in moddata subfolders, // this was a really bad decision done by the ppt import developer if (file_exists("$CFG->dataroot/$lesson->course/moddata/lesson/")) { lesson_20_migrate_moddata_mixture($lesson->course, '/moddata/lesson/'); @rmdir("$CFG->dataroot/$lesson->course/moddata/lesson/"); // remove dir if empty @rmdir("$CFG->dataroot/$lesson->course/moddata/"); // remove dir if empty } // migrate media file only if local course file selected - this is not nice at all, // it should better be a real block, not a lesson specific hack if (strpos($lesson->mediafile, '://') !== false) { // some external URL } else if ($lesson->mediafile) { $context = get_context_instance(CONTEXT_MODULE, $lesson->cmid); $coursecontext = get_context_instance(CONTEXT_COURSE, $lesson->course); $filepathname = clean_param('/'.$lesson->mediafile, PARAM_PATH); $fullpath = "/$context->id/mod_lesson/mediafile/0$filepathname"; if ($file = $fs->get_file_by_hash(sha1($fullpath)) and !$file->is_directory()) { // already converted, just update filename $DB->set_field('lesson', 'mediafile', $filepathname, array('id'=>$lesson->id)); } else { // let's copy file from current course legacy files if possible $fullpath = "/$coursecontext->id/course/legacy/0$filepathname"; if ($file = $fs->get_file_by_hash(sha1($fullpath)) and !$file->is_directory()) { $file_record = array('contextid'=>$context->id, 'component'=>'mod_lesson', 'filearea'=>'mediafile', 'itemid'=>0, 'filepath'=>$file->get_filepath(), 'filename'=>$file->get_filename(), 'sortorder'=>1); $fs->create_file_from_storedfile($file_record, $file); $DB->set_field('lesson', 'mediafile', $filepathname, array('id'=>$lesson->id)); } else { // bad luck, no such file exists $DB->set_field('lesson', 'mediafile', '', array('id'=>$lesson->id)); } } } } $rs->close(); } upgrade_mod_savepoint(true, 2010081200, 'lesson'); } if ($oldversion < 2010121400) { // Fix matching question pages. // In Moodle 1.9 matching question pages stored the correct and incorrect // jumps on the third and forth answers, in Moodle 2.0 they are stored // in the first and second answers. // This upgrade block detects matching questions where this is the case // and fixed it by making firstjump = thirdjump && secondjump = forthjump. $pages = $DB->get_recordset('lesson_pages', array('qtype'=>'5')); foreach ($pages as $page) { $answers = $DB->get_records('lesson_answers', array('pageid'=>$page->id), 'id', 'id, jumpto', 0, 4); if (count($answers) < 4) { // If there are less then four answers the problem wont exist. // All Moodle 1.9 matching questions had a least 4 answers. continue; } $first = array_shift($answers); $second = array_shift($answers); $third = array_shift($answers); $forth = array_shift($answers); if ($first->jumpto !== '0' || $second->jumpto !== '0') { // If either are set to something other than the next page then // there is no problem. continue; } if ($third->jumpto !== '0') { $first->jumpto = $third->jumpto; $DB->update_record('lesson_answers', $first); $third->jumpto = '0'; $DB->update_record('lesson_answers', $third); } if ($forth->jumpto !== '0') { $second->jumpto = $forth->jumpto; $DB->update_record('lesson_answers', $second); $forth->jumpto = '0'; $DB->update_record('lesson_answers', $forth); } } // Close the record set $pages->close(); upgrade_mod_savepoint(true, 2010121400, 'lesson'); } // Moodle v2.1.0 release upgrade line // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this return true; }
function xmldb_block_helpmenow_upgrade($oldversion = 0) { global $CFG, $USER, $DB; $dbman = $DB->get_manager(); $result = true; if ($result && $oldversion < 2012082101) { /// Define field notify to be added to block_helpmenow_message $table = new xmldb_table('block_helpmenow_message'); $field = new xmldb_field('notify'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'message'); /// Launch add field notify $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2012082102) { /// system messages are no longer using get_admin()->id for userid, but instead null $result = $result && $DB->set_field('block_helpmenow_message', 'userid', null, array('userid' => get_admin()->id)); } if ($result && $oldversion < 2012082400) { /// Define field last_message to be added to block_helpmenow_session2user $table = new xmldb_table('block_helpmenow_session2user'); $field = new xmldb_field('last_message'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'last_refresh'); /// Launch add field last_message $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2012091200) { /// Define field last_message to be added to block_helpmenow_session $table = new xmldb_table('block_helpmenow_session'); $field = new xmldb_field('last_message'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'timecreated'); /// Launch add field last_message $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2012091400) { /// Changing the default of field last_message on table block_helpmenow_session2user to 0 $table = new xmldb_table('block_helpmenow_session2user'); $field = new xmldb_field('last_message'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, '0', 'last_refresh'); /// Launch change of default for field last_message $result = $result && $dbman->change_field_default($table, $field); /// Changing the default of field last_message on table block_helpmenow_session to 0 $table = new xmldb_table('block_helpmenow_session'); $field = new xmldb_field('last_message'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, '0', 'timecreated'); /// Launch change of default for field last_message $result = $result && $dbman->change_field_default($table, $field); } if ($result && $oldversion < 2012092100) { /// Define field lastaccess to be added to block_helpmenow_user $table = new xmldb_table('block_helpmenow_user'); $field = new xmldb_field('lastaccess'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'motd'); /// Launch add field lastaccess $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2012121900) { /// Define field optimistic_last_message to be added to block_helpmenow_session2user $table = new xmldb_table('block_helpmenow_session2user'); $field = new xmldb_field('optimistic_last_message'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'last_message'); /// Launch add field optimistic_last_message $result = $result && $dbman->add_field($table, $field); /// Define field cache to be added to block_helpmenow_session2user $table = new xmldb_table('block_helpmenow_session2user'); $field = new xmldb_field('cache'); $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'optimistic_last_message'); /// Launch add field cache $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2012122700) { /// Define table block_helpmenow_error_log to be created $table = new xmldb_table('block_helpmenow_error_log'); /// Adding fields to table block_helpmenow_error_log $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('error', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('details', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table block_helpmenow_error_log $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Launch create table for block_helpmenow_error_log $result = $result && $dbman->create_table($table); } if ($result && $oldversion < 2012123100) { /// Define field userid to be added to block_helpmenow_error_log $table = new xmldb_table('block_helpmenow_error_log'); $field = new xmldb_field('userid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'timecreated'); /// Launch add field userid $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2013011800) { /// Define table block_helpmenow_contact to be created $table = new xmldb_table('block_helpmenow_contact'); /// Adding fields to table block_helpmenow_contact $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('contact_userid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); /// Adding keys to table block_helpmenow_contact $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table block_helpmenow_contact $table->add_index('block_helpmenow_contact_userid_ix', XMLDB_INDEX_NOTUNIQUE, array('userid')); /// Launch create table for block_helpmenow_contact $result = $result && $dbman->create_table($table); } if ($result && $oldversion < 2013050200) { /// Define index block_helpmenow_log_u_ix (not unique) to be added to block_helpmenow_log $table = new xmldb_table('block_helpmenow_log'); $index = new xmldb_index('block_helpmenow_log_u_ix'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('userid')); /// Launch add index block_helpmenow_log_u_ix $result = $result && $dbman->add_index($table, $index); /// Define index block_helpmenow_log_ua_ix (not unique) to be added to block_helpmenow_log $table = new xmldb_table('block_helpmenow_log'); $index = new xmldb_index('block_helpmenow_log_ua_ix'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('userid', 'action')); /// Launch add index block_helpmenow_log_ua_ix $result = $result && $dbman->add_index($table, $index); } if ($result && $oldversion < 2013050700) { /// Define field last_read to be added to block_helpmenow_session2user $table = new xmldb_table('block_helpmenow_session2user'); $field = new xmldb_field('last_read'); $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, '0', 'cache'); /// Launch add field last_read $result = $result && $dbman->add_field($table, $field); } if ($result && $oldversion < 2014050401) { // Reminder: do not use core/lib function in upgrade script! $contextid = $DB->get_field('context', 'id', array('contextlevel' => CONTEXT_SYSTEM)); // Hardcode the capability as they must match the value at this upgrade time. $HELPMENOW_CAP_QUEUE_ANSWER = 'block/helpmenow:global_queue_answer'; $HELPMENOW_CAP_QUEUE_ASK = 'block/helpmenow:queue_ask'; $HELPMENOW_CAP_MANAGE = 'block/helpmenow:manage_queues'; // Add Help Me Now block manager system role. $role = new stdClass(); $role->name = 'Help Me Now Manager'; $role->shortname = 'helpmenowmanager'; $role->description = 'can assign a queue helper - can do anything on helpmenow.'; // Find free sortorder number. $role->sortorder = $DB->get_field('role', 'MAX(sortorder) + 1', array()); if (empty($role->sortorder)) { $role->sortorder = 1; } $roleid = $DB->insert_record('role', $role); // Set the role as system role. $rcl = new stdClass(); $rcl->roleid = $roleid; $rcl->contextlevel = CONTEXT_SYSTEM; $DB->insert_record('role_context_levels', $rcl, false, true); // Assign correct permission to Help Me Now block manager role. $cap = new stdClass(); $cap->contextid = $contextid; $cap->roleid = $roleid; $cap->capability = $HELPMENOW_CAP_MANAGE; $cap->permission = 1; $cap->timemodified = time(); $cap->modifierid = empty($USER->id) ? 0 : $USER->id; $DB->insert_record('role_capabilities', $cap); $cap->capability = $HELPMENOW_CAP_QUEUE_ANSWER; $DB->insert_record('role_capabilities', $cap); $cap->capability = $HELPMENOW_CAP_QUEUE_ASK; $DB->insert_record('role_capabilities', $cap); // Add Help Me Now block instructor system role. $role = new stdClass(); $role->name = 'Help Me Now instructor'; $role->shortname = 'helpmenowinstructor'; $role->description = 'can login in an office and answer questions.'; $role->sortorder = $DB->get_field('role', 'MAX(sortorder) + 1', array()); $roleid = $DB->insert_record('role', $role); $rcl = new stdClass(); $rcl->roleid = $roleid; $rcl->contextlevel = CONTEXT_SYSTEM; $DB->insert_record('role_context_levels', $rcl, false, true); $cap->roleid = $roleid; $cap->capability = $HELPMENOW_CAP_QUEUE_ASK; $DB->insert_record('role_capabilities', $cap); $cap->capability = $HELPMENOW_CAP_QUEUE_ANSWER; $DB->insert_record('role_capabilities', $cap); // Add Help Me Now block student system role. $role = new stdClass(); $role->name = 'Help Me Now student'; $role->shortname = 'helpmenowstudent'; $role->description = 'can ask questions to instructors and helpers.'; $role->sortorder = $DB->get_field('role', 'MAX(sortorder) + 1', array()); $roleid = $DB->insert_record('role', $role); $rcl = new stdClass(); $rcl->roleid = $roleid; $rcl->contextlevel = CONTEXT_SYSTEM; $DB->insert_record('role_context_levels', $rcl, false, true); $cap->roleid = $roleid; $cap->capability = $HELPMENOW_CAP_QUEUE_ASK; $DB->insert_record('role_capabilities', $cap); // Helpmenow savepoint reached. upgrade_block_savepoint(true, 2014050401, 'helpmenow'); } return $result; }
/** * Execute jclic upgrade from the given old version * * @param int $oldversion * @return bool */ function xmldb_jclic_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes if ($oldversion < 2011011900) { $table = new xmldb_table('jclic'); /// Define lang field format to be added to jclic $field = new xmldb_field('lang'); $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'ca', 'url'); $result = $result && $dbman->add_field($table, $field); /// Define exiturl field format to be added to jclic $field = new xmldb_field('exiturl'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'url'); $result = $result && $dbman->add_field($table, $field); } if ($oldversion < 2011122902) { /// Define field introformat to be added to jclic $table = new xmldb_table('jclic'); $field = new xmldb_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'name'); if ($dbman->field_exists($table, $field)) { $dbman->rename_field($table, $field, 'intro'); } $field = new xmldb_field('introformat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Launch add field introformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('jclic', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $f) { $f->intro = text_to_html($f->intro, false, false, true); $f->introformat = FORMAT_HTML; $DB->update_record('jclic', $f); upgrade_set_timeout(); } $rs->close(); } /// jclic savepoint reached upgrade_mod_savepoint(true, 2011122902, 'jclic'); } //===== 1.9.0 upgrade line ======// if ($oldversion < 2012042700) { require_once "{$CFG->dirroot}/mod/jclic/db/upgradelib.php"; // Add upgrading code from 1.9 (+ new file storage system) // @TODO: test it!!!! jclic_migrate_files(); // Add fields grade, timeavailable and timedue on table jclic $table = new xmldb_table('jclic'); $field = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'maxgrade'); $dbman->add_field($table, $field); // Update jclic.grade with the jclic.max_grade value if ($jclics = $DB->get_records('jclic')) { foreach ($jclics as $jclic) { if (empty($jclic->maxgrade)) { $jclic->maxgrade = 10; } $jclic->grade = $jclic->maxgrade; $DB->update_record("jclic", $jclic); } } $field = new xmldb_field('timeavailable', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', 'exiturl'); $dbman->add_field($table, $field); $field = new xmldb_field('timedue', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', 'timeavailable'); $dbman->add_field($table, $field); // jclic savepoint reached upgrade_mod_savepoint(true, 2012042700, 'jclic'); } if ($oldversion < 2012050703) { // Remove unique restriction for jclic_sessions.session_id field $table = new xmldb_table('jclic_sessions'); $key = new xmldb_index('session_id', XMLDB_INDEX_UNIQUE, array('session_id')); $dbman->drop_index($table, $key); // Copy jclic_sessions.id to jclic_sessions.session_id and update jclic_activities.session_id if ($sessions = $DB->get_records('jclic_sessions')) { foreach ($sessions as $session) { $sql = 'UPDATE {jclic_activities} SET session_id=? WHERE session_id=? '; $params = array($session->id, $session->session_id); $DB->execute($sql, $params); $session->session_id = $session->id; $DB->update_record("jclic_sessions", $session); } } // jclic savepoint reached upgrade_mod_savepoint(true, 2012050703, 'jclic'); } if ($oldversion < 2014040400) { if ($activities = $DB->get_records('jclic_activities', array(), '', 'id, total_time')) { foreach ($activities as $activity) { $activity->total_time = ceil($activity->total_time / 1000); $DB->update_record("jclic_activities", $activity); } } // jclic savepoint reached upgrade_mod_savepoint(true, 2014040400, 'jclic'); } if ($oldversion < 2015050600) { if (isset($CFG->jclic_jarbase) && !empty($CFG->jclic_jarbase)) { set_config('jarbase', $CFG->jclic_jarbase, 'jclic'); } unset_config('jclic_jarbase'); if (isset($CFG->jclic_lap) && !empty($CFG->jclic_lap)) { set_config('lap', $CFG->jclic_lap, 'jclic'); } unset_config('jclic_lap'); if (isset($CFG->jclic_pluginjs) && !empty($CFG->jclic_pluginjs)) { set_config('pluginjs', $CFG->jclic_pluginjs, 'jclic'); } unset_config('jclic_pluginjs'); upgrade_mod_savepoint(true, 2015050600, 'jclic'); } // Final return of upgrade result (true, all went good) to Moodle. return true; }
public function testRenameField() { $DB = $this->tdb; // do not use global $DB! $dbman = $this->tdb->get_manager(); $table = $this->create_deftable('test_table0'); $field = new xmldb_field('type'); $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course'); $dbman->rename_field($table, $field, 'newfieldname'); $columns = $DB->get_columns('test_table0'); $this->assertFalse(array_key_exists('type', $columns)); $this->assertTrue(array_key_exists('newfieldname', $columns)); }
function xmldb_ouwiki_upgrade($oldversion = 0) { global $CFG, $DB; $dbman = $DB->get_manager(); /// loads ddl manager and xmldb classes if ($oldversion < 2008100600) { /// Define field deletedat to be added to ouwiki_versions $table = new xmldb_table('ouwiki_versions'); $field = new xmldb_field('deletedat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'changeprevsize'); /// Launch add field deletedat (provided field does not already exist) if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2008100600, 'ouwiki'); } if ($oldversion < 2009120801) { /// Launch create table for ouwiki_annotations - if it does not already exist (extra precaution) $table = new xmldb_table('ouwiki_annotations'); if (!$dbman->table_exists($table)) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/mod/ouwiki/db/install.xml', 'ouwiki_annotations'); } /// Define field locked to be added to ouwiki_pages $table = new xmldb_table('ouwiki_pages'); $field = new xmldb_field('locked'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 0, 'currentversionid'); /// Launch add field locked - if it does not already exist (extra precaution) if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2009120801, 'ouwiki'); } if ($oldversion < 2010022300) { /// Define field locked to be added to ouwiki_pages $table = new xmldb_table('ouwiki'); $field = new xmldb_field('commenting'); $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, null, null, 'default', 'completionedits'); /// Launch add field locked - if it does not already exist (extra precaution) if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2010022300, 'ouwiki'); } if ($oldversion < 2010122001) { // Drop the old comments table $table = new xmldb_table('ouwiki_comments'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } // Drop the old commenting field in ouwiki $table2 = new xmldb_table('ouwiki'); $field = new xmldb_field('commenting'); if ($dbman->field_exists($table2, $field)) { // We need to know about any wikis which are currently // using annotation or both systems before the upgrade // we need these before we drop the commenting field $rs = $DB->get_records_sql("SELECT DISTINCT w.id " . "FROM {ouwiki} w " . "WHERE w.commenting = 'annotations' OR w.commenting = 'both'"); $dbman->drop_field($table2, $field); } // Define field annotation to be added to ouwiki $field2 = new xmldb_field('annotation'); $field2->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'completionedits'); if (!$dbman->field_exists($table2, $field2)) { $dbman->add_field($table2, $field2); } // update the existing wikis to have annotation turned on // where they did before or had the BOTH commenting option if (!empty($rs)) { $ids = array_keys($rs); list($usql, $params) = $DB->get_in_or_equal($ids); $update_sql = 'UPDATE {ouwiki} SET annotation = 1 WHERE id ' . $usql; $DB->execute($update_sql, $params); } // retrieve new summary field $field3 = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'template'); // Launch rename field summary if ($dbman->field_exists($table2, $field3)) { $dbman->rename_field($table2, $field3, 'intro'); } // Define field introformat to be added to ouwiki $field4 = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'annotation'); // Launch add field introformat if (!$dbman->field_exists($table2, $field4)) { $dbman->add_field($table2, $field4); } // Define field introformat to be added to ouwiki $table3 = new xmldb_table('ouwiki_versions'); $field5 = new xmldb_field('xhtmlformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'deletedat'); // Launch add field introformat if (!$dbman->field_exists($table3, $field5)) { $dbman->add_field($table3, $field5); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { // introformat $rs = $DB->get_recordset('ouwiki', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $r) { $r->intro = text_to_html($r->intro, false, false, true); $r->introformat = FORMAT_HTML; $DB->update_record('ouwiki', $r); upgrade_set_timeout(); } $rs->close(); // xhtmlformat $rs = $DB->get_recordset('ouwiki_versions', array('xhtmlformat' => FORMAT_MOODLE), '', 'id,xhtml,xhtmlformat'); foreach ($rs as $r) { $r->xhtml = text_to_html($r->xhtml, false, false, true); $r->xhtmlformat = FORMAT_MOODLE; $DB->update_record('ouwiki_versions', $r); upgrade_set_timeout(); } $rs->close(); } upgrade_mod_savepoint(true, 2010122001, 'ouwiki'); } if ($oldversion < 2011031800) { upgrade_mod_savepoint(true, 2011031800, 'ouwiki'); } if ($oldversion < 2011060100) { // Define field enablewordcount to be added to ouwiki $table = new xmldb_table('ouwiki'); $field = new xmldb_field('enablewordcount', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'introformat'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field wordcount to be added to ouwiki_versions $table = new xmldb_table('ouwiki_versions'); $field = new xmldb_field('wordcount', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'xhtmlformat'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // we need to update all ouwiki_versions wordcounts $count = $DB->count_records_sql('SELECT COUNT(*) FROM {ouwiki_versions}'); $rs = $DB->get_recordset_sql('SELECT id, xhtml FROM {ouwiki_versions} ORDER BY id'); if ($rs->valid()) { $pbar = new progress_bar('countwordsouwikiversionsxhtml', 500, true); $i = 0; foreach ($rs as $entry) { $i++; upgrade_set_timeout(60); // set up timeout, may also abort execution $pbar->update($i, $count, "Counting words of ouwiki version entries - {$i}/{$count}."); // retrieve wordcount require_once $CFG->dirroot . '/mod/ouwiki/locallib.php'; $wordcount = ouwiki_count_words($entry->xhtml); $entry->wordcount = $wordcount; $DB->update_record('ouwiki_versions', $entry); } } $rs->close(); upgrade_mod_savepoint(true, 2011060100, 'ouwiki'); } if ($oldversion < 2011071300) { // Define field grade to be added to ouwiki $table = new xmldb_table('ouwiki'); $field = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'enablewordcount'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // we need to update all ouwiki_versions scales $rs = $DB->get_recordset_sql('SELECT id FROM {ouwiki} ORDER BY id'); if ($rs->valid()) { foreach ($rs as $entry) { $entry->grade = 0; $DB->update_record('ouwiki', $entry); } } $rs->close(); upgrade_mod_savepoint(true, 2011071300, 'ouwiki'); } if ($oldversion < 2011072000) { // Define field firstversionid to be added to ouwiki_pages $table = new xmldb_table('ouwiki_pages'); $field = new xmldb_field('firstversionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', 'locked'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field previousversionid to be added to ouwiki_versions $table = new xmldb_table('ouwiki_versions'); $field = new xmldb_field('previousversionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', 'wordcount'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // update all ouwiki_versions previousversionids and ouwiki_pages firstversionids // firstversionid $sql = 'SELECT v.pageid, (SELECT MIN(id) FROM {ouwiki_versions} v3 WHERE v3.pageid = p.id AND v3.deletedat IS NULL) AS firstversionid FROM {ouwiki_pages} p JOIN {ouwiki_versions} v ON v.pageid = p.id GROUP BY v.pageid, p.id ORDER BY v.pageid'; $rs = $DB->get_recordset_sql($sql); if ($rs->valid()) { foreach ($rs as $entry) { if (isset($entry->firstversionid)) { $DB->set_field('ouwiki_pages', 'firstversionid', $entry->firstversionid, array('id' => $entry->pageid)); } } } $rs->close(); // previousversionid $count = $DB->count_records_sql('SELECT COUNT(*) FROM {ouwiki_versions}'); $sql = 'SELECT v.id AS versionid, (SELECT MAX(v2.id) FROM {ouwiki_versions} v2 WHERE v2.pageid = p.id AND v2.id < v.id) AS previousversionid FROM {ouwiki_pages} p JOIN {ouwiki_versions} v ON v.pageid = p.id'; $rs = $DB->get_recordset_sql($sql); if ($rs->valid()) { $pbar = new progress_bar('ouwikifirstandpreviousversions', 500, true); $i = 0; foreach ($rs as $entry) { $i++; upgrade_set_timeout(60); // set up timeout, may also abort execution $pbar->update($i, $count, "Updating wiki metadata - {$i}/{$count}."); if (isset($entry->previousversionid)) { $DB->set_field('ouwiki_versions', 'previousversionid', $entry->previousversionid, array('id' => $entry->versionid)); } } } $rs->close(); upgrade_mod_savepoint(true, 2011072000, 'ouwiki'); } if ($oldversion < 2011102802) { // Delete any duplicate null values (these aren't caught by index) // Done in two stages in case mysql is a piece of ****. $rs = $DB->get_recordset_sql("\nSELECT\n p.id\nFROM\n {ouwiki_pages} p\n LEFT JOIN {ouwiki_pages} p2 ON p2.subwikiid = p.subwikiid AND p2.title IS NULL\n AND p.title IS NULL AND p2.id < p.id\nWHERE\n p2.id IS NOT NULL"); $ids = array(); foreach ($rs as $rec) { $ids[] = $rec->id; } $rs->close(); if ($ids) { list($sql, $params) = $DB->get_in_or_equal($ids); $DB->execute("DELETE FROM {ouwiki_pages} WHERE id {$sql}", $params); } // Set all the null values to blank $DB->execute("UPDATE {ouwiki_pages} SET title='' WHERE title IS NULL"); // Also in ousearch table if installed $table = new xmldb_table('local_ousearch_documents'); if ($dbman->table_exists($table)) { $DB->execute("UPDATE {local_ousearch_documents} SET stringref='' WHERE stringref IS NULL AND plugin='mod_ouwiki'"); } // Changing nullability of field title on table ouwiki_pages to not null $table = new xmldb_table('ouwiki_pages'); $field = new xmldb_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'subwikiid'); // Launch change of nullability for field title $dbman->change_field_notnull($table, $field); // Define index subwikiid-title (unique) to be added to ouwiki_pages $index = new xmldb_index('subwikiid-title', XMLDB_INDEX_UNIQUE, array('subwikiid', 'title')); // Conditionally launch add index subwikiid-title if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // ouwiki savepoint reached upgrade_mod_savepoint(true, 2011102802, 'ouwiki'); } // Must always return true from these functions return true; }
/** * This file keeps track of upgrades to * the forum module * * Sometimes, changes between versions involve * alterations to database structures and other * major things that may break installations. * * The upgrade function in this file will attempt * to perform all the necessary actions to upgrade * your older installation to the current version. * * If there's something it cannot do itself, it * will tell you what you need to do. * * The commands in here will all be database-neutral, * using the methods of database_manager class * * Please do not forget to use upgrade_set_timeout() * before any action that may take longer time to finish. * * @package mod-forum * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_forum_upgrade($oldversion) { global $CFG, $DB, $OUTPUT; $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes //===== 1.9.0 upgrade line ======// if ($oldversion < 2007101511) { //MDL-13866 - send forum ratins to gradebook again require_once $CFG->dirroot . '/mod/forum/lib.php'; forum_upgrade_grades(); upgrade_mod_savepoint(true, 2007101511, 'forum'); } if ($oldversion < 2008072800) { /// Define field completiondiscussions to be added to forum $table = new xmldb_table('forum'); $field = new xmldb_field('completiondiscussions'); $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'blockperiod'); /// Launch add field completiondiscussions if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('completionreplies'); $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiondiscussions'); /// Launch add field completionreplies if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// Define field completionposts to be added to forum $field = new xmldb_field('completionposts'); $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionreplies'); /// Launch add field completionposts if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2008072800, 'forum'); } if ($oldversion < 2008081900) { ///////////////////////////////////// /// new file storage upgrade code /// ///////////////////////////////////// $fs = get_file_storage(); $empty = $DB->sql_empty(); // silly oracle empty string handling workaround $sqlfrom = "FROM {forum_posts} p\n JOIN {forum_discussions} d ON d.id = p.discussion\n JOIN {forum} f ON f.id = d.forum\n JOIN {modules} m ON m.name = 'forum'\n JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = f.id)\n WHERE p.attachment <> '{$empty}' AND p.attachment <> '1'"; $count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}"); $rs = $DB->get_recordset_sql("SELECT p.id, p.attachment, p.userid, d.forum, f.course, cm.id AS cmid {$sqlfrom} ORDER BY f.course, f.id, d.id"); if ($rs->valid()) { $pbar = new progress_bar('migrateforumfiles', 500, true); $i = 0; foreach ($rs as $post) { $i++; upgrade_set_timeout(60); // set up timeout, may also abort execution $pbar->update($i, $count, "Migrating forum posts - {$i}/{$count}."); $filepath = "{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum/{$post->forum}/{$post->id}/{$post->attachment}"; if (!is_readable($filepath)) { //file missing?? echo $OUTPUT->notification("File not readable, skipping: " . $filepath); $post->attachment = ''; $DB->update_record('forum_posts', $post); continue; } $context = get_context_instance(CONTEXT_MODULE, $post->cmid); $filearea = 'attachment'; $filename = clean_param($post->attachment, PARAM_FILE); if ($filename === '') { echo $OUTPUT->notification("Unsupported post filename, skipping: " . $filepath); $post->attachment = ''; $DB->update_record('forum_posts', $post); continue; } if (!$fs->file_exists($context->id, 'mod_forum', $filearea, $post->id, '/', $filename)) { $file_record = array('contextid' => $context->id, 'component' => 'mod_forum', 'filearea' => $filearea, 'itemid' => $post->id, 'filepath' => '/', 'filename' => $filename, 'userid' => $post->userid); if ($fs->create_file_from_pathname($file_record, $filepath)) { $post->attachment = '1'; $DB->update_record('forum_posts', $post); unlink($filepath); } } // remove dirs if empty @rmdir("{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum/{$post->forum}/{$post->id}"); @rmdir("{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum/{$post->forum}"); @rmdir("{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum"); } } $rs->close(); upgrade_mod_savepoint(true, 2008081900, 'forum'); } if ($oldversion < 2008090800) { /// Define field maxattachments to be added to forum $table = new xmldb_table('forum'); $field = new xmldb_field('maxattachments', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'maxbytes'); /// Conditionally launch add field maxattachments if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /// forum savepoint reached upgrade_mod_savepoint(true, 2008090800, 'forum'); } if ($oldversion < 2009042000) { /// Rename field format on table forum_posts to messageformat $table = new xmldb_table('forum_posts'); $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'message'); /// Launch rename field format $dbman->rename_field($table, $field, 'messageformat'); /// forum savepoint reached upgrade_mod_savepoint(true, 2009042000, 'forum'); } if ($oldversion < 2009042001) { /// Define field messagetrust to be added to forum_posts $table = new xmldb_table('forum_posts'); $field = new xmldb_field('messagetrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'messageformat'); /// Launch add field messagetrust $dbman->add_field($table, $field); /// forum savepoint reached upgrade_mod_savepoint(true, 2009042001, 'forum'); } if ($oldversion < 2009042002) { $trustmark = '#####TRUSTTEXT#####'; $rs = $DB->get_recordset_sql("SELECT * FROM {forum_posts} WHERE message LIKE ?", array($trustmark . '%')); foreach ($rs as $post) { if (strpos($post->message, $trustmark) !== 0) { // probably lowercase in some DBs? continue; } $post->message = str_replace($trustmark, '', $post->message); $post->messagetrust = 1; $DB->update_record('forum_posts', $post); } $rs->close(); /// forum savepoint reached upgrade_mod_savepoint(true, 2009042002, 'forum'); } if ($oldversion < 2009042003) { /// Define field introformat to be added to forum $table = new xmldb_table('forum'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Launch add field introformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('forum', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $f) { $f->intro = text_to_html($f->intro, false, false, true); $f->introformat = FORMAT_HTML; $DB->update_record('forum', $f); upgrade_set_timeout(); } $rs->close(); } /// forum savepoint reached upgrade_mod_savepoint(true, 2009042003, 'forum'); } /// Dropping all enums/check contraints from core. MDL-18577 if ($oldversion < 2009042700) { /// Changing list of values (enum) of field type on table forum to none $table = new xmldb_table('forum'); $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course'); /// Launch change of list of values for field type $dbman->drop_enum_from_field($table, $field); /// forum savepoint reached upgrade_mod_savepoint(true, 2009042700, 'forum'); } if ($oldversion < 2009050400) { /// Clean existing wrong rates. MDL-18227 $DB->delete_records('forum_ratings', array('post' => 0)); /// forum savepoint reached upgrade_mod_savepoint(true, 2009050400, 'forum'); } if ($oldversion < 2010042800) { //migrate forumratings to the central rating table $table = new xmldb_table('forum_ratings'); if ($dbman->table_exists($table)) { //forum ratings only have a single time column so use it for both time created and modified $sql = "INSERT INTO {rating} (contextid, scaleid, itemid, rating, userid, timecreated, timemodified)\n\n SELECT cxt.id, f.scale, r.post AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified\n FROM {forum_ratings} r\n JOIN {forum_posts} p ON p.id=r.post\n JOIN {forum_discussions} d ON d.id=p.discussion\n JOIN {forum} f ON f.id=d.forum\n JOIN {course_modules} cm ON cm.instance=f.id\n JOIN {context} cxt ON cxt.instanceid=cm.id\n JOIN {modules} m ON m.id=cm.module\n WHERE m.name = :modname AND cxt.contextlevel = :contextlevel"; $params['modname'] = 'forum'; $params['contextlevel'] = CONTEXT_MODULE; $DB->execute($sql, $params); //now drop forum_ratings $dbman->drop_table($table); } upgrade_mod_savepoint(true, 2010042800, 'forum'); } if ($oldversion < 2010070800) { // Remove the forum digests message provider MDL-23145 $DB->delete_records('message_providers', array('name' => 'digests', 'component' => 'mod_forum')); // forum savepoint reached upgrade_mod_savepoint(true, 2010070800, 'forum'); } if ($oldversion < 2010091900) { // rename files from borked upgrade in 2.0dev $fs = get_file_storage(); $rs = $DB->get_recordset('files', array('component' => 'mod_form')); foreach ($rs as $oldrecord) { $file = $fs->get_file_instance($oldrecord); $newrecord = array('component' => 'mod_forum'); if (!$fs->file_exists($oldrecord->contextid, 'mod_forum', $oldrecord->filearea, $oldrecord->itemid, $oldrecord->filepath, $oldrecord->filename)) { $fs->create_file_from_storedfile($newrecord, $file); } $file->delete(); } $rs->close(); upgrade_mod_savepoint(true, 2010091900, 'forum'); } return true; }
/** * Upgrade logic. * * @package mod_streamline * @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com) * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) * @copyright 2010-2014 Blindside Networks Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later */ function xmldb_streamline_upgrade($oldversion = 0) { global $CFG, $THEME, $DB; $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes $result = true; if ($result && $oldversion < 2012040200) { // Define field intro to be droped from streamline $table = new xmldb_table('streamline'); $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'name'); // Drop field intro if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field, $continue = true, $feedback = true); } // Define field introformat to be droped from streamline $table = new xmldb_table('streamline'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); // Drop field introformat if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field, $continue = true, $feedback = true); } // Once we reach this point, we can store the new version and consider the module // upgraded to the version 2012040200 so the next time this block is skipped upgrade_mod_savepoint(true, 2012040200, 'streamline'); } if ($result && $oldversion < 2012062705) { // Define table streamline_log to be created $table = new xmldb_table('streamline_log'); // Adding fields to table streamline_log $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('meetingid', XMLDB_TYPE_CHAR, '256', null, XMLDB_NOTNULL, null, null); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('streamlineid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('record', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('event', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); // Adding keys to table streamline_log $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for streamline_log if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // streamline savepoint reached upgrade_mod_savepoint(true, 2012062705, 'streamline'); } if ($result && $oldversion < 2012100100) { $table = new xmldb_table('streamline'); $field = new xmldb_field('welcome'); $field->set_attributes(XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, null, null, 'type'); $dbman->change_field_type($table, $field, $continue = true, $feedback = true); upgrade_mod_savepoint(true, 2012100100, 'streamline'); } if ($result && $oldversion < 2014050100) { $table = new xmldb_table('streamline'); $field = new xmldb_field('allmoderators'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field, $continue = true, $feedback = true); } upgrade_mod_savepoint(true, 2014050100, 'streamline'); } if ($result && $oldversion < 2014070420) { $table = new xmldb_table('streamline'); $field = new xmldb_field('participants', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field, $continue = true, $feedback = true); } upgrade_mod_savepoint(true, 2014070420, 'streamline'); } if ($result && $oldversion < 2014101004) { $table = new xmldb_table('streamline'); $field = new xmldb_field('participants'); $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null); $dbman->change_field_type($table, $field, $continue = true, $feedback = true); upgrade_mod_savepoint(true, 2014101004, 'streamline'); } if ($result && $oldversion < 2015062100) { $table = new xmldb_table('streamline'); $field = new xmldb_field('userlimit'); $field->set_attributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field, $continue = true, $feedback = true); } upgrade_mod_savepoint(true, 2015062100, 'streamline'); } return $result; }
function xmldb_offlinequiz_upgrade($oldversion = 0) { global $CFG, $THEME, $DB, $OUTPUT; $dbman = $DB->get_manager(); // And upgrade begins here. For each one, you'll need one // Block of code similar to the next one. Please, delete // This comment lines once this file start handling proper // Upgrade code. // ONLY UPGRADE FROM Moodle 1.9.x (module version 2009042100) is supported. if ($oldversion < 2009120700) { // Define field counter to be added to offlinequiz_i_log. $table = new xmldb_table('offlinequiz_i_log'); $field = new xmldb_field('counter'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'rawdata'); // Launch add field counter. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field corners to be added to offlinequiz_i_log. $field = new xmldb_field('corners'); $field->set_attributes(XMLDB_TYPE_CHAR, '50', null, null, null, null, 'counter'); // Launch add field corners. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field pdfintro to be added to offlinequiz. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('pdfintro'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'intro'); // Launch add field pdfintro. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2009120700, 'offlinequiz'); } if ($oldversion < 2010082900) { // Define table offlinequiz_p_list to be created. $table = new xmldb_table('offlinequiz_p_list'); // Adding fields to table offlinequiz_p_list. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('offlinequiz', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->add_field('list', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); // Adding keys to table offlinequiz_p_list. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Launch create table for offlinequiz_p_list. $dbman->create_table($table); // Define field position to be dropped from offlinequiz_participants. $table = new xmldb_table('offlinequiz_participants'); $field = new xmldb_field('position'); // Launch drop field position. $dbman->drop_field($table, $field); // Define field page to be dropped from offlinequiz_participants. $table = new xmldb_table('offlinequiz_participants'); $field = new xmldb_field('page'); // Launch drop field page. $dbman->drop_field($table, $field); // Define field list to be added to offlinequiz_participants. $table = new xmldb_table('offlinequiz_participants'); $field = new xmldb_field('list'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'userid'); // Launch add field list. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2010082900, 'offlinequiz'); } if ($oldversion < 2010090600) { // Define index offlinequiz (not unique) to be added to offlinequiz_p_list. $table = new xmldb_table('offlinequiz_p_list'); $index = new XMLDBIndex('offlinequiz'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('offlinequiz')); // Launch add index offlinequiz. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } $index = new XMLDBIndex('list'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('list')); // Launch add index list. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Define index offlinequiz (not unique) to be added to offlinequiz_participants. $table = new xmldb_table('offlinequiz_participants'); $index = new XMLDBIndex('offlinequiz'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('offlinequiz')); // Launch add index offlinequiz. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } $index = new XMLDBIndex('list'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('list')); // Launch add index list. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } $index = new XMLDBIndex('userid'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('userid')); // Launch add index list. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2010090600, 'offlinequiz'); } if ($oldversion < 2011021400) { // Define field fileformat to be added to offlinequiz. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('fileformat'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified'); // Launch add field fileformat. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2011021400, 'offlinequiz'); } if ($oldversion < 2011032900) { // Define field page to be added to offlinequiz_i_log. $table = new xmldb_table('offlinequiz_i_log'); $field = new xmldb_field('page'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'corners'); // Launch add field page. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field username to be added to offlinequiz_i_log. $field = new xmldb_field('username'); $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'page'); // Launch add field username. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define index username (not unique) to be added to offlinequiz_i_log. $index = new XMLDBIndex('username'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('username')); // Launch add index username. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Define field showgrades to be added to offlinequiz. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('showgrades'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'fileformat'); // Launch add field showgrades. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2011032900, 'offlinequiz'); } if ($oldversion < 2011081700) { // Define field showtutorial to be added to offlinequiz. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('showtutorial'); $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'showgrades'); // Launch add field showtutorial. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2011081700, 'offlinequiz'); } // ------------------------------------------------------ // UPGRADE for Moodle 2.0 module starts here. // ------------------------------------------------------ // First we do the changes to the main table 'offlinequiz'. // ------------------------------------------------------ if ($oldversion < 2012010100) { // Define field docscreated to be added to offlinequiz. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('docscreated', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'questionsperpage'); // Conditionally launch add field docscreated. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010100, 'offlinequiz'); } // Fill the new field docscreated. if ($oldversion < 2012010101) { $offlinequizzes = $DB->get_records('offlinequiz'); foreach ($offlinequizzes as $offlinequiz) { $dirname = $CFG->dataroot . '/' . $offlinequiz->course . '/moddata/offlinequiz/' . $offlinequiz->id . '/pdfs'; // If the answer pdf file for group 1 exists then we have created the documents. if (file_exists($dirname . '/answer-a.pdf')) { $DB->set_field('offlinequiz', 'docscreated', 1, array('id' => $offlinequiz->id)); } } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010101, 'offlinequiz'); } if ($oldversion < 2012010105) { // Define table offlinequiz_reports to be created. $table = new xmldb_table('offlinequiz_reports'); // Adding fields to table offlinequiz_reports. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null); // Adding keys to table offlinequiz_reports. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table offlinequiz_reports. // $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name'));. // Conditionally launch create table for offlinequiz_reports. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } if (!$DB->get_records_sql("SELECT * FROM {offlinequiz_reports} WHERE name = 'overview'", array())) { $record = new stdClass(); $record->name = 'overview'; $record->displayorder = '10000'; $DB->insert_record('offlinequiz_reports', $record); } if (!$DB->get_records_sql("SELECT * FROM {offlinequiz_reports} WHERE name = 'rimport'", array())) { $record = new stdClass(); $record->name = 'rimport'; $record->displayorder = '9000'; $DB->insert_record('offlinequiz_reports', $record); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010105, 'offlinequiz'); } // Now we create all the new tables. // Create table offlinequiz_groups. if ($oldversion < 2012010200) { echo $OUTPUT->notification('Creating new tables', 'notifysuccess'); // Define table offlinequiz_groups to be created. $table = new xmldb_table('offlinequiz_groups'); // Adding fields to table offlinequiz_groups. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('offlinequizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('number', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0'); $table->add_field('numberofpages', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('templateusageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); // Adding keys to table offlinequiz_groups. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table offlinequiz_groups. $table->add_index('offlinequizid', XMLDB_INDEX_NOTUNIQUE, array('offlinequizid')); // Conditionally launch create table for offlinequiz_groups. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010200, 'offlinequiz'); } // Create table offlinequiz_group_questions. if ($oldversion < 2012010300) { // Define table offlinequiz_group_questions to be created. $table = new xmldb_table('offlinequiz_group_questions'); // Adding fields to table offlinequiz_group_questions. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('offlinequizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('offlinegroupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('position', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table->add_field('pagenumber', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null); $table->add_field('usageslot', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null); // Adding keys to table offlinequiz_group_questions. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table offlinequiz_group_questions. $table->add_index('offlinequiz', XMLDB_INDEX_NOTUNIQUE, array('offlinequizid')); // Conditionally launch create table for offlinequiz_group_questions. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010300, 'offlinequiz'); } if ($oldversion < 2012010400) { // Define table offlinequiz_scanned_pages to be created. $table = new xmldb_table('offlinequiz_scanned_pages'); // Adding fields to table offlinequiz_scanned_pages. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('offlinequizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('resultid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('filename', XMLDB_TYPE_CHAR, '1000', null, null, null, null); $table->add_field('warningfilename', XMLDB_TYPE_CHAR, '1000', null, null, null, null); $table->add_field('groupnumber', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null); $table->add_field('userkey', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('pagenumber', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null); $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('status', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); $table->add_field('error', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); // Adding keys to table offlinequiz_scanned_pages. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table offlinequiz_scanned_pages. $table->add_index('offlinequizid', XMLDB_INDEX_NOTUNIQUE, array('offlinequizid')); // Conditionally launch create table for offlinequiz_scanned_pages. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010400, 'offlinequiz'); } if ($oldversion < 2012010500) { // Define table offlinequiz_choices to be created. $table = new xmldb_table('offlinequiz_choices'); // Adding fields to table offlinequiz_choices. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('scannedpageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('slotnumber', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('choicenumber', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('value', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null); // Adding keys to table offlinequiz_choices. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table offlinequiz_choices. $table->add_index('scannedpageid', XMLDB_INDEX_NOTUNIQUE, array('scannedpageid')); // Conditionally launch create table for offlinequiz_choices. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010500, 'offlinequiz'); } if ($oldversion < 2012010600) { // Define table offlinequiz_page_corners to be created. $table = new xmldb_table('offlinequiz_page_corners'); // Adding fields to table offlinequiz_page_corners. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('scannedpageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('x', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('y', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('position', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); // Adding keys to table offlinequiz_page_corners. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for offlinequiz_page_corners. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010600, 'offlinequiz'); } if ($oldversion < 2012010700) { // Define table offlinequiz_results to be created. $table = new xmldb_table('offlinequiz_results'); // Adding fields to table offlinequiz_results. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('offlinequizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('offlinegroupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); $table->add_field('usageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('teacherid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('attendant', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('status', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('timestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('timefinish', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0'); $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('preview', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0'); // Adding keys to table offlinequiz_results. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for offlinequiz_results. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010700, 'offlinequiz'); } if ($oldversion < 2012010800) { // Define table offlinequiz_scanned_p_pages to be created. $table = new xmldb_table('offlinequiz_scanned_p_pages'); // Adding fields to table offlinequiz_scanned_p_pages. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('offlinequizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('listnumber', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null); $table->add_field('filename', XMLDB_TYPE_CHAR, '1000', null, null, null, null); $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('status', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null); $table->add_field('error', XMLDB_TYPE_TEXT, 'small', null, null, null, null); // Adding keys to table offlinequiz_scanned_p_pages. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for offlinequiz_scanned_p_pages. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010800, 'offlinequiz'); } if ($oldversion < 2012010900) { // Define table offlinequiz_p_choices to be created. $table = new xmldb_table('offlinequiz_p_choices'); // Adding fields to table offlinequiz_p_choices. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('scannedppageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); $table->add_field('value', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); // Adding keys to table offlinequiz_p_choices. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for offlinequiz_p_choices. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012010900, 'offlinequiz'); } if ($oldversion < 2012011000) { // Define table offlinequiz_p_lists to be created. $table = new xmldb_table('offlinequiz_p_lists'); // Adding fields to table offlinequiz_p_lists. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('offlinequizid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('number', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); $table->add_field('filename', XMLDB_TYPE_CHAR, '1000', null, null, null, null); // Adding keys to table offlinequiz_p_lists. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table offlinequiz_p_lists. $table->add_index('offlinequizid', XMLDB_INDEX_NOTUNIQUE, array('offlinequizid')); // Conditionally launch create table for offlinequiz_p_lists. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012011000, 'offlinequiz'); } // ------------------------------------------------------ // New we rename fields in old tables. // ------------------------------------------------------ // Rename fields in offlinequiz_queue table. if ($oldversion < 2012020100) { echo $OUTPUT->notification('Renaming fields in old tables.', 'notifysuccess'); // Rename field offlinequiz on table offlinequiz_queue to NEWNAMEGOESHERE. $table = new xmldb_table('offlinequiz_queue'); $field = new xmldb_field('offlinequiz'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timefinish'); // Launch rename field offlinequiz. $dbman->rename_field($table, $field, 'offlinequizid'); $field = new xmldb_field('importadmin'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); // Launch rename field importadmin. $dbman->rename_field($table, $field, 'importuserid'); // New status field. $field = new xmldb_field('status', XMLDB_TYPE_TEXT, 'small', null, null, null, 'processed', 'timefinish'); // Conditionally launch add field status. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012020100, 'offlinequiz'); } // Add and rename fields in table offlinquiz_queue_data. if ($oldversion < 2012020200) { // Define field status to be added to offlinequiz_queue_data. $table = new xmldb_table('offlinequiz_queue_data'); $field = new xmldb_field('status', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, 'ok', 'filename'); // Conditionally launch add field status. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } else { $dbman->change_field_type($table, $field); $dbman->change_field_precision($table, $field); $dbman->change_field_notnull($table, $field); $dbman->change_field_unsigned($table, $field); } // Add new field 'error'. $field = new xmldb_field('error', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'status'); // Conditionally launch add field error. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Rename field queue to queueid. $field = new xmldb_field('queue', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); // Launch rename field queueid. $dbman->rename_field($table, $field, 'queueid'); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012020200, 'offlinequiz'); } // Rename field list on table offlinequiz_participants to listid. if ($oldversion < 2012020300) { // Rename field list on table offlinequiz_participants to listid. $table = new xmldb_table('offlinequiz_participants'); $field = new xmldb_field('list', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); // Launch rename field listid. $dbman->rename_field($table, $field, 'listid'); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012020300, 'offlinequiz'); } // Migrate the old lists of participants to the new table offlinequiz_p_lists (with 's'). if ($oldversion < 2012020400) { $oldplists = $DB->get_records('offlinequiz_p_list'); foreach ($oldplists as $oldplist) { $newplist = new StdClass(); $newplist->offlinequizid = $oldplist->offlinequiz; $newplist->name = $oldplist->name; $newplist->number = $oldplist->list; // NOTE. // We don't set filename because we can always recreate the PDF files if needed. $newplist->id = $DB->insert_record('offlinequiz_p_lists', $newplist); // Get all the participants linked to the old list and link them to the new list in offlinequiz_p_lists. if ($oldparts = $DB->get_records('offlinequiz_participants', array('listid' => $oldplist->id))) { foreach ($oldparts as $oldpart) { $oldpart->listid = $newplist->id; $DB->update_record('offlinequiz_participants', $oldpart); } } } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012020400, 'offlinequiz'); } // Check if there are inconsistencies in the DB, i.e. uniqueids used by both quizzes and offlinequizzes. if ($oldversion < 2012020410) { $sql = 'SELECT uniqueid FROM {offlinequiz_attempts} qa WHERE EXISTS (SELECT id from {quiz_attempts} where uniqueid = qa.uniqueid)'; $doubleids = $DB->get_fieldset_sql($sql, array()); // For each double uniqueid create a new uniqueid and change the fields in the tables. // Offlinequiz_attempts, question_sessions and question_states. echo $OUTPUT->notification('Fixing ' . count($doubleids) . ' question attempt uniqueids that are not unique', 'notifysuccess'); foreach ($doubleids as $doubleid) { echo $doubleid . ', '; if ($usage = $DB->get_record('question_usages', array('id' => $doubleid))) { $transaction = $DB->start_delegated_transaction(); unset($usage->id); $usage->id = $DB->insert_record('question_usages', $usage); $DB->set_field_select('offlinequiz_attempts', 'uniqueid', $usage->id, 'uniqueid = :oldid', array('oldid' => $doubleid)); $DB->set_field_select('question_states', 'attempt', $usage->id, 'attempt = :oldid', array('oldid' => $doubleid)); $DB->set_field_select('question_sessions', 'attemptid', $usage->id, 'attemptid = :oldid', array('oldid' => $doubleid)); $transaction->allow_commit(); } } upgrade_mod_savepoint(true, 2012020410, 'offlinequiz'); } // ----------------------------------------------------- // Update the contextid field in question_usages (compare lib/db/upgrade.php lines 6108 following). // ----------------------------------------------------- if ($oldversion < 2012020500) { echo $OUTPUT->notification('Fixing question usages context ID', 'notifysuccess'); // Update the component field if necessary. $DB->set_field('question_usages', 'component', 'mod_offlinequiz', array('component' => 'offlinequiz')); // Populate the contextid field. $offlinequizmoduleid = $DB->get_field('modules', 'id', array('name' => 'offlinequiz')); $DB->execute("\n UPDATE {question_usages} SET contextid = (\n SELECT ctx.id\n FROM {context} ctx\n JOIN {course_modules} cm ON cm.id = ctx.instanceid AND cm.module = {$offlinequizmoduleid}\n JOIN {offlinequiz_attempts} quiza ON quiza.offlinequiz = cm.instance\n WHERE ctx.contextlevel = " . CONTEXT_MODULE . "\n AND quiza.uniqueid = {question_usages}.id)\n WHERE (\n SELECT ctx.id\n FROM {context} ctx\n JOIN {course_modules} cm ON cm.id = ctx.instanceid AND cm.module = {$offlinequizmoduleid}\n JOIN {offlinequiz_attempts} quiza ON quiza.offlinequiz = cm.instance\n WHERE ctx.contextlevel = " . CONTEXT_MODULE . "\n AND quiza.uniqueid = {question_usages}.id) IS NOT NULL\n "); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012020500, 'offlinequiz'); } // ----------------------------------------------------- // Now we migrate data from the old to the new tables. // ----------------------------------------------------- // We have to delete redundant question instances from offlinequizzes because they are incompatible with the new code. if ($oldversion < 2012030100) { echo $OUTPUT->notification('Migrating old offline quizzes to new offline quizzes..', 'notifysuccess'); require_once $CFG->dirroot . '/mod/offlinequiz/db/upgradelib.php'; offlinequiz_remove_redundant_q_instances(); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012030100, 'offlinequiz'); } // Migrate all entries in the offlinequiz_group table to the new tables offlinequiz_groups and offlinequiz_group_questions. if ($oldversion < 2012030101) { echo $OUTPUT->notification('Creating new offlinequiz groups', 'notifysuccess'); $offlinequizzes = $DB->get_records('offlinequiz'); $counter = 0; foreach ($offlinequizzes as $offlinequiz) { if (!$DB->get_records('offlinequiz_groups', array('offlinequizid' => $offlinequiz->id))) { echo '.'; $counter++; flush(); ob_flush(); if ($counter % 100 == 0) { echo "<br/>\n"; echo $counter; } $transaction = $DB->start_delegated_transaction(); $oldgroups = $DB->get_records('offlinequiz_group', array('offlinequiz' => $offlinequiz->id), 'groupid ASC'); $newgroups = array(); foreach ($oldgroups as $oldgroup) { $newgroup = new StdClass(); $newgroup->offlinequizid = $offlinequiz->id; $newgroup->number = $oldgroup->groupid; $newgroup->sumgrades = $oldgroup->sumgrades; $newgroup->timecreated = time(); $newgroup->timemodified = time(); // First we need the ID of the new group. if (!($oldid = $DB->get_field('offlinequiz_groups', 'id', array('offlinequizid' => $offlinequiz->id, 'number' => $newgroup->number)))) { $newgroup->id = $DB->insert_record('offlinequiz_groups', $newgroup); } else { $newgroup->id = $oldid; } // Now create an entry in offlinquiz_group_questions for each question in the old group layout. $questions = explode(',', $oldgroup->questions); $position = 1; foreach ($questions as $question) { $groupquestion = new StdClass(); $groupquestion->offlinequizid = $offlinequiz->id; $groupquestion->offlinegroupid = $newgroup->id; $groupquestion->questionid = $question; $groupquestion->position = $position++; if (!$DB->get_record('offlinequiz_group_questions', array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $newgroup->id, 'questionid' => $question))) { $DB->insert_record('offlinequiz_group_questions', $groupquestion); } } $newgroups[] = $newgroup; } require_once $CFG->dirroot . '/mod/offlinequiz/evallib.php'; list($maxquestions, $maxanswers, $formtype, $questionsperpage) = offlinequiz_get_question_numbers($offlinequiz, $newgroups); foreach ($newgroups as $newgroup) { // Now we know the number of pages of the group. $newgroup->numberofpages = ceil($maxquestions / ($formtype * 24)); $DB->update_record('offlinequiz_groups', $newgroup); } $transaction->allow_commit(); } } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012030101, 'offlinequiz'); } // Migrate all entries in the offlinequiz_i_log table to the new tables offlinequiz_scanned_pages, offlinequiz_choices and. // Offlinequiz_page_corners. Also migrate the files to the new filesystem. // First we mark all offlinequizzes s.t. we upgrade them only once. Many things can go wrong here.. if ($oldversion < 2012030200) { // Define field needsilogupgrade to be added to offlinequiz_attempts. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('needsilogupgrade', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeopen'); // Launch add field needsilogupgrade. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $DB->set_field('offlinequiz', 'needsilogupgrade', 1); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012030200, 'offlinequiz'); } // Then we mark all offlinequiz_attempts to be upgraded. if ($oldversion < 2012030300) { // Define field needsupgradetonewqe to be added to offlinequiz_attempts. $table = new xmldb_table('offlinequiz_attempts'); $field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'sheet'); // Launch add field needsupgradetonewqe. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $DB->set_field('offlinequiz_attempts', 'needsupgradetonewqe', 1); // Quiz savepoint reached. upgrade_mod_savepoint(true, 2012030300, 'offlinequiz'); } // In a first step we upgrade the offlinequiz_attempts exactly like quiz_attempts (see mod/quiz/db/upgrade.php). if ($oldversion < 2012030400) { $table = new xmldb_table('question_states'); // Echo "upgrading attempts to new question engine <br/>\n";. if ($dbman->table_exists($table)) { // NOTE: We need all attemps, also the ones with sheet=1 because the are the groups' template attempts. // Now update all the old attempt data. $oldrcachesetting = $CFG->rcache; $CFG->rcache = false; require_once $CFG->dirroot . '/mod/offlinequiz/db/upgradelib.php'; $upgrader = new offlinequiz_attempt_upgrader(); $upgrader->convert_all_quiz_attempts(); $CFG->rcache = $oldrcachesetting; } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012030400, 'offlinequiz'); } // Then we mark all offlinequiz_attempts to be upgraded. if ($oldversion < 2012030500) { // Define field resultid to be added to offlinequiz_attempts for later reference. set_time_limit(3000); $table = new xmldb_table('offlinequiz_attempts'); $field = new xmldb_field('resultid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); // Launch add field resultid. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Quiz savepoint reached. upgrade_mod_savepoint(true, 2012030500, 'offlinequiz'); } // In a second step we convert all offlinequiz_attempts into offlinequiz_results and also upgrade the ilog table. if ($oldversion < 2012060101) { require_once $CFG->dirroot . '/mod/offlinequiz/db/upgradelib.php'; $oldrcachesetting = $CFG->rcache; $CFG->rcache = false; $upgrader = new offlinequiz_ilog_upgrader(); $upgrader->convert_all_offlinequiz_attempts(); $CFG->rcache = $oldrcachesetting; // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012060101, 'offlinequiz'); } if ($oldversion < 2012060105) { // Changing type of field grade on table offlinequiz_q_instances to number. $table = new xmldb_table('offlinequiz_q_instances'); $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question'); // Launch change of type for field grade. $dbman->change_field_type($table, $field); // Launch change of precision for field grade. $dbman->change_field_precision($table, $field); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012060105, 'offlinequiz'); } if ($oldversion < 2012121200) { // Define field introformat to be added to offlinequiz. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); // Conditionally launch add field introformat. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2012121200, 'offlinequiz'); } if ($oldversion < 2013012400) { // Define field info to be added to offlinequiz_queue. $table = new xmldb_table('offlinequiz_queue'); $field = new xmldb_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'status'); // Conditionally launch add field info. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013012400, 'offlinequiz'); } if ($oldversion < 2013012410) { // Define field info to be added to offlinequiz_queue_data. $table = new xmldb_table('offlinequiz_queue_data'); $field = new xmldb_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'error'); // Conditionally launch add field info. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013012410, 'offlinequiz'); } if ($oldversion < 2013012500) { // Changing type of field grade on table offlinequiz to int. $table = new xmldb_table('offlinequiz'); $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'time'); // Launch change for field grade. $dbman->change_field_type($table, $field); $dbman->change_field_precision($table, $field); $dbman->change_field_unsigned($table, $field); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013012500, 'offlinequiz'); } if ($oldversion < 2013041600) { // Rename field question on table offlinequiz_q_instances to questionid. $table = new xmldb_table('offlinequiz_q_instances'); $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'offlinequiz'); // Launch rename field question. $dbman->rename_field($table, $field, 'questionid'); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013041600, 'offlinequiz'); } if ($oldversion < 2013041601) { // Rename field offlinequiz on table offlinequiz_q_instances to offlinequizid. $table = new xmldb_table('offlinequiz_q_instances'); $field = new xmldb_field('offlinequiz', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); // Launch rename field offlinequiz. $dbman->rename_field($table, $field, 'offlinequizid'); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013041601, 'offlinequiz'); } if ($oldversion < 2013061300) { // Define table offlinequiz_hotspots to be created. $table = new xmldb_table('offlinequiz_hotspots'); // Adding fields to table offlinequiz_hotspots. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('scannedpageid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('x', XMLDB_TYPE_NUMBER, '10, 2', null, XMLDB_NOTNULL, null, null); $table->add_field('y', XMLDB_TYPE_NUMBER, '10, 2', null, XMLDB_NOTNULL, null, null); $table->add_field('blank', XMLDB_TYPE_INTEGER, '1', null, null, null, null); $table->add_field('time', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); // Adding keys to table offlinequiz_hotspots. $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Adding indexes to table offlinequiz_hotspots. $table->add_index('scannedpageididx', XMLDB_INDEX_NOTUNIQUE, array('scannedpageid')); // Conditionally launch create table for offlinequiz_hotspots. if (!$dbman->table_exists($table)) { $dbman->create_table($table); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013061300, 'offlinequiz'); } if ($oldversion < 2013110800) { // Define field timecreated to be added to offlinequiz_queue. $table = new xmldb_table('offlinequiz_queue'); $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'importuserid'); // Conditionally launch add field timecreated. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013110800, 'offlinequiz'); } if ($oldversion < 2013112500) { // Define index offlinequiz_userid_idx (not unique) to be added to offlinequiz_results. $table = new xmldb_table('offlinequiz_results'); $index = new xmldb_index('offlinequiz_userid_idx', XMLDB_INDEX_NOTUNIQUE, array('userid')); // Conditionally launch add index offlinequiz_userid_idx. if (!$dbman->index_exists($table, $index)) { $dbman->add_index($table, $index); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2013112500, 'offlinequiz'); } // Moodle v2.8.5+ release upgrade line. // Put any upgrade step following this. if ($oldversion < 2015060500) { // Rename field page on table offlinequiz_group_questions to NEWNAMEGOESHERE. $table = new xmldb_table('offlinequiz_group_questions'); $field = new xmldb_field('pagenumber', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'position'); // Launch rename field page. $dbman->rename_field($table, $field, 'page'); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2015060500, 'offlinequiz'); } if ($oldversion < 2015060501) { // Rename field page on table offlinequiz_group_questions to NEWNAMEGOESHERE. $table = new xmldb_table('offlinequiz_group_questions'); $field = new xmldb_field('usageslot', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'position'); // Launch rename field page. $dbman->rename_field($table, $field, 'slot'); // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2015060501, 'offlinequiz'); } if ($oldversion < 2015060502) { // Define field maxmark to be added to offlinequiz_group_questions. $table = new xmldb_table('offlinequiz_group_questions'); $field = new xmldb_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '1', 'slot'); // Conditionally launch add field maxmark. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2015060502, 'offlinequiz'); } if ($oldversion < 2015060902) { // This upgrade migrates old offlinequiz_q_instances grades (maxgrades) to new // maxmark field in offlinequiz_group_questions. // It also deletes group questions with questionid 0 (pagebreaks) and inserts the // correct page number instead. $numofflinequizzes = $DB->count_records('offlinequiz'); if ($numofflinequizzes > 0) { $pbar = new progress_bar('offlinequizquestionstoslots', 500, true); $pbar->create(); $pbar->update(0, $numofflinequizzes, "Upgrading offlinequiz group questions - {0}/{$numofflinequizzes}."); $numberdone = 0; $offlinequizzes = $DB->get_recordset('offlinequiz', null, 'id', 'id, numgroups'); foreach ($offlinequizzes as $offlinequiz) { $transaction = $DB->start_delegated_transaction(); $groups = $DB->get_records('offlinequiz_groups', array('offlinequizid' => $offlinequiz->id), 'number', '*'); $instancesraw = $DB->get_records('offlinequiz_q_instances', array('offlinequizid' => $offlinequiz->id)); $questioninstances = array(); foreach ($instancesraw as $instance) { if (!array_key_exists($instance->questionid, $questioninstances)) { $questioninstances[$instance->questionid] = $instance; } } foreach ($groups as $group) { $groupquestions = $DB->get_records('offlinequiz_group_questions', array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id), 'position'); // For every group we start on page 1. $currentpage = 1; $currentslot = 1; foreach ($groupquestions as $groupquestion) { $needsupdate = false; if ($groupquestion->questionid == 0) { // We remove the old pagebreaks with questionid==0. $DB->delete_records('offlinequiz_group_questions', array('id' => $groupquestion->id)); $currentpage++; continue; } // If the maxmarks in the question instances differs from the default maxmark (1) // of the offlinequiz_group_questions then change it. if (array_key_exists($groupquestion->questionid, $questioninstances) && ($maxmark = floatval($questioninstances[$groupquestion->questionid]->grade)) && abs(floatval($groupquestion->maxmark) - $maxmark) > 0.001) { $groupquestion->maxmark = $maxmark; $needsupdate = true; } // If the page number is not correct, then change it. if ($groupquestion->page != $currentpage) { $groupquestion->page = $currentpage; $needsupdate = true; } // If the slot is not set, then fill it. if (!$groupquestion->slot) { $groupquestion->slot = $currentslot; $needsupdate = true; } if ($needsupdate) { $DB->update_record('offlinequiz_group_questions', $groupquestion); } $currentslot++; } } // Done with this offlinequiz. Update progress bar. $numberdone++; $pbar->update($numberdone, $numofflinequizzes, "Upgrading offlinequiz group questions - {$numberdone}/{$numofflinequizzes}."); $transaction->allow_commit(); } } // Offlinequiz savepoint reached. upgrade_mod_savepoint(true, 2015060902, 'offlinequiz'); } // TODO migrate old offlinequiz_q_instances maxmarks to new maxmark field in offlinequiz_group_questions. // TODO migrate offlinequiz_group_questions to fill in page field correctly. For every group use the // position field to find new pages and insert them. // Adapt offlinequiz code to handle missing zeros as pagebreaks. return true; }
function xmldb_feedback_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); if ($oldversion < 2007012310) { //create a new table feedback_completedtmp and the field-definition $table = new xmldb_table('feedback_completedtmp'); $field = new xmldb_field('id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null); $table->addField($field); $field = new xmldb_field('feedback'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('userid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('guestid'); $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, '', null); $table->addField($field); $field = new xmldb_field('timemodified'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $key = new xmldb_key('PRIMARY'); $key->set_attributes(XMLDB_KEY_PRIMARY, array('id')); $table->addKey($key); $key = new xmldb_key('feedback'); $key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id'); $table->addKey($key); $dbman->create_table($table); //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //create a new table feedback_valuetmp and the field-definition $table = new xmldb_table('feedback_valuetmp'); $field = new xmldb_field('id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null); $table->addField($field); $field = new xmldb_field('course_id'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('item'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('completed'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('tmp_completed'); $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); $table->addField($field); $field = new xmldb_field('value'); $field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, '', null); $table->addField($field); $key = new xmldb_key('PRIMARY'); $key->set_attributes(XMLDB_KEY_PRIMARY, array('id')); $table->addKey($key); $key = new xmldb_key('feedback'); $key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id'); $table->addKey($key); $dbman->create_table($table); //////////////////////////////////////////////////////////// upgrade_mod_savepoint(true, 2007012310, 'feedback'); } if ($oldversion < 2007050504) { /// Define field random_response to be added to feedback_completed $table = new xmldb_table('feedback_completed'); $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); /// Launch add field1 $dbman->add_field($table, $field); /// Define field anonymous_response to be added to feedback_completed $table = new xmldb_table('feedback_completed'); $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); /// Launch add field2 $dbman->add_field($table, $field); /// Define field random_response to be added to feedback_completed $table = new xmldb_table('feedback_completedtmp'); $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null); /// Launch add field1 $dbman->add_field($table, $field); /// Define field anonymous_response to be added to feedback_completed $table = new xmldb_table('feedback_completedtmp'); $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); /// Launch add field2 $dbman->add_field($table, $field); //////////////////////////////////////////////////////////// upgrade_mod_savepoint(true, 2007050504, 'feedback'); } if ($oldversion < 2007102600) { // public is a reserved word on Oracle $table = new xmldb_table('feedback_template'); $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2007102600, 'feedback'); } if ($oldversion < 2008042400) { //New version in version.php if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', array('anonymous' => 2))) { $update_sql = 'UPDATE {feedback_completed} SET anonymous_response = 2 WHERE feedback = '; foreach ($all_nonanonymous_feedbacks as $fb) { $DB->execute($update_sql . $fb->id); } } upgrade_mod_savepoint(true, 2008042400, 'feedback'); } if ($oldversion < 2008042401) { //New version in version.php $concat_radio = $DB->sql_concat("'r>>>>>'", 'presentation'); $concat_check = $DB->sql_concat("'c>>>>>'", 'presentation'); $concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation'); $update_sql1 = "UPDATE {feedback_item}\n SET presentation = " . $concat_radio . "\n WHERE typ IN('radio','radiorated')"; $update_sql2 = "UPDATE {feedback_item}\n SET presentation = " . $concat_dropdown . "\n WHERE typ IN('dropdown','dropdownrated')"; $update_sql3 = "UPDATE {feedback_item}\n SET presentation = " . $concat_check . "\n WHERE typ = 'check'"; $DB->execute($update_sql1); $DB->execute($update_sql2); $DB->execute($update_sql3); $update_sql1 = "UPDATE {feedback_item}\n SET typ = 'multichoice'\n WHERE typ IN('radio','check','dropdown')"; $update_sql2 = "UPDATE {feedback_item}\n SET typ = 'multichoicerated'\n WHERE typ IN('radiorated','dropdownrated')"; $DB->execute($update_sql1); $DB->execute($update_sql2); upgrade_mod_savepoint(true, 2008042401, 'feedback'); } if ($oldversion < 2008042900) { /// Define field autonumbering to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit'); /// Launch add field2 $dbman->add_field($table, $field); upgrade_mod_savepoint(true, 2008042900, 'feedback'); } if ($oldversion < 2008050104) { /// Define field site_after_submit to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'autonumbering'); /// Launch add field2 $dbman->add_field($table, $field); upgrade_mod_savepoint(true, 2008050104, 'feedback'); } if ($oldversion < 2008050105) { //field count is not more needed $table = new xmldb_table('feedback_tracking'); $field = new xmldb_field('count'); $dbman->drop_field($table, $field); upgrade_mod_savepoint(true, 2008050105, 'feedback'); } if ($oldversion < 2008073002) { $update_sql = "UPDATE {feedback_item}\n SET presentation = '-|-'\n WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND\n typ = 'numeric'"; $DB->execute($update_sql); upgrade_mod_savepoint(true, 2008073002, 'feedback'); } if ($oldversion < 2009031301) { /// Define field label to be added to feedback_item $table = new xmldb_table('feedback_item'); $field = new xmldb_field('label', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'name'); /// Launch add field2 $dbman->add_field($table, $field); upgrade_mod_savepoint(true, 2009031301, 'feedback'); } if ($oldversion < 2009042000) { /// Rename field summary on table feedback to intro $table = new xmldb_table('feedback'); $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name'); /// Launch rename field summary $dbman->rename_field($table, $field, 'intro'); /// feedback savepoint reached upgrade_mod_savepoint(true, 2009042000, 'feedback'); } if ($oldversion < 2009042001) { /// Define field introformat to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Launch add field introformat $dbman->add_field($table, $field); /// feedback savepoint reached upgrade_mod_savepoint(true, 2009042001, 'feedback'); } if ($oldversion < 2009112000) { /// Define field page_after_submitformat to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit'); if (!$dbman->field_exists($table, $field)) { // Launch add field page_after_submitformat $dbman->add_field($table, $field); } // feedback savepoint reached upgrade_mod_savepoint(true, 2009112000, 'feedback'); } if ($oldversion < 2010051101) { /// Define field options to be added to feedback_item $table = new xmldb_table('feedback_item'); $field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'required'); /// Launch add field $dbman->add_field($table, $field); upgrade_mod_savepoint(true, 2010051101, 'feedback'); } if ($oldversion < 2010051600) { /// Define field options to be added to feedback_item $table = new xmldb_table('feedback_item'); $field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required'); /// Launch add field $dbman->add_field($table, $field); upgrade_mod_savepoint(true, 2010051600, 'feedback'); } if ($oldversion < 2010051601) { /// Define field options to be added to feedback_item $table = new xmldb_table('feedback_item'); $field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'dependitem'); /// Launch add field $dbman->add_field($table, $field); upgrade_mod_savepoint(true, 2010051601, 'feedback'); } if ($oldversion < 2010102300) { // Define field completionsubmit to be added to feedback $table = new xmldb_table('feedback'); $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'timemodified'); // Conditionally launch add field completionsubmit if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // feedback savepoint reached upgrade_mod_savepoint(true, 2010102300, 'feedback'); } // Moodle v2.1.0 release upgrade line // Put any upgrade step following this return true; }