From e8c82aac82d7bebb5d994338f7321d96073fd0f0 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 6 Feb 2016 12:33:09 +0100 Subject: [PATCH] MDL-51580 upgrade: clean < 2.7.0 upgrade steps This just deletes all the upgrade steps previous to 2.7.0. Some small adjustments, like adding missing MOODLE_INTERNAL or tweaking globals can also be applied when needed. Next commit will get rid of/deprecate all the upgradelib functions not used anymore in codebase. --- admin/tool/customlang/db/upgrade.php | 25 +- admin/tool/log/db/upgrade.php | 15 +- admin/tool/log/store/database/db/upgrade.php | 15 +- admin/tool/log/store/standard/db/upgrade.php | 93 +- auth/cas/db/upgrade.php | 31 +- auth/ldap/db/upgrade.php | 21 +- auth/manual/db/upgrade.php | 25 +- auth/mnet/db/upgrade.php | 25 +- blocks/community/db/upgrade.php | 23 +- blocks/completionstatus/db/upgrade.php | 30 +- blocks/course_summary/db/upgrade.php | 34 +- blocks/html/db/upgrade.php | 23 +- blocks/navigation/db/upgrade.php | 28 +- blocks/recent_activity/db/upgrade.php | 43 +- blocks/section_links/db/upgrade.php | 43 +- blocks/selfcompletion/db/upgrade.php | 34 +- blocks/settings/db/upgrade.php | 28 +- enrol/database/db/upgrade.php | 24 +- enrol/flatfile/db/upgrade.php | 23 +- enrol/guest/db/upgrade.php | 36 +- enrol/imsenterprise/db/upgrade.php | 19 +- enrol/manual/db/upgrade.php | 39 +- enrol/mnet/db/upgrade.php | 24 +- enrol/paypal/db/upgrade.php | 25 +- enrol/self/db/upgrade.php | 44 +- filter/mathjaxloader/db/upgrade.php | 5 +- filter/mediaplugin/db/upgrade.php | 46 +- filter/tex/db/upgrade.php | 42 +- grade/grading/form/rubric/db/upgrade.php | 25 +- lib/db/upgrade.php | 3555 +---------------- lib/editor/atto/db/upgrade.php | 19 - lib/editor/tinymce/db/upgrade.php | 131 - .../plugins/spellchecker/db/upgrade.php | 25 +- message/output/email/db/upgrade.php | 30 +- message/output/jabber/db/upgrade.php | 30 +- message/output/popup/db/upgrade.php | 30 +- mod/assign/db/upgrade.php | 458 +-- mod/assign/feedback/comments/db/upgrade.php | 18 +- mod/assign/feedback/editpdf/db/upgrade.php | 38 - mod/assign/feedback/file/db/upgrade.php | 18 +- mod/assign/submission/comments/db/upgrade.php | 19 +- mod/assign/submission/file/db/upgrade.php | 17 +- .../submission/onlinetext/db/upgrade.php | 19 +- mod/assignment/db/upgrade.php | 106 +- mod/book/db/upgrade.php | 170 - mod/chat/db/upgrade.php | 26 +- mod/choice/db/upgrade.php | 27 +- mod/data/db/upgrade.php | 114 +- mod/feedback/db/upgrade.php | 30 +- mod/folder/db/upgrade.php | 72 +- mod/forum/db/upgrade.php | 98 +- mod/glossary/db/upgrade.php | 42 +- mod/imscp/db/upgrade.php | 22 +- mod/label/db/upgrade.php | 44 +- mod/lesson/db/upgrade.php | 26 +- mod/lti/db/upgrade.php | 19 - mod/page/db/upgrade.php | 27 +- mod/quiz/db/upgrade.php | 742 ---- mod/quiz/report/overview/db/upgrade.php | 27 +- mod/quiz/report/statistics/db/upgrade.php | 109 +- mod/resource/db/upgrade.php | 27 +- mod/scorm/db/upgrade.php | 249 +- mod/survey/db/upgrade.php | 31 +- mod/url/db/upgrade.php | 27 +- mod/wiki/db/upgrade.php | 54 +- mod/workshop/db/upgrade.php | 129 +- mod/workshop/form/accumulative/db/upgrade.php | 29 +- mod/workshop/form/comments/db/upgrade.php | 29 +- mod/workshop/form/numerrors/db/upgrade.php | 29 +- mod/workshop/form/rubric/db/upgrade.php | 29 +- portfolio/boxnet/db/upgrade.php | 33 +- portfolio/googledocs/db/upgrade.php | 41 +- portfolio/picasa/db/upgrade.php | 41 +- .../behaviour/manualgraded/db/upgrade.php | 69 +- question/type/calculated/db/upgrade.php | 27 +- question/type/essay/db/upgrade.php | 174 +- question/type/match/db/upgrade.php | 178 +- question/type/multianswer/db/upgrade.php | 20 - question/type/multichoice/db/upgrade.php | 109 +- question/type/numerical/db/upgrade.php | 22 +- question/type/random/db/upgrade.php | 22 - question/type/randomsamatch/db/upgrade.php | 161 +- question/type/shortanswer/db/upgrade.php | 104 +- repository/alfresco/db/upgrade.php | 25 +- repository/boxnet/db/upgrade.php | 46 +- repository/dropbox/db/upgrade.php | 32 +- repository/googledocs/db/upgrade.php | 44 +- repository/picasa/db/upgrade.php | 44 +- theme/more/db/upgrade.php | 40 - 89 files changed, 192 insertions(+), 8669 deletions(-) diff --git a/admin/tool/customlang/db/upgrade.php b/admin/tool/customlang/db/upgrade.php index 01f87e95159fd..b3c5c035732aa 100644 --- a/admin/tool/customlang/db/upgrade.php +++ b/admin/tool/customlang/db/upgrade.php @@ -24,29 +24,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -function xmldb_tool_customlang_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - +defined('MOODLE_INTERNAL') || die(); - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_tool_customlang_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/admin/tool/log/db/upgrade.php b/admin/tool/log/db/upgrade.php index 2a4eab3c23bb6..ef219e04cf419 100644 --- a/admin/tool/log/db/upgrade.php +++ b/admin/tool/log/db/upgrade.php @@ -31,20 +31,7 @@ * @return bool always true */ function xmldb_tool_log_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - if ($oldversion < 2014040600) { - // Reset logging defaults in dev branches, - // in production upgrade the install.php is executed instead. - require_once(__DIR__ . '/install.php'); - xmldb_tool_log_install(); - upgrade_plugin_savepoint(true, 2014040600, 'tool', 'log'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/admin/tool/log/store/database/db/upgrade.php b/admin/tool/log/store/database/db/upgrade.php index 565efedde4ee3..dc9203592be85 100644 --- a/admin/tool/log/store/database/db/upgrade.php +++ b/admin/tool/log/store/database/db/upgrade.php @@ -22,19 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -function xmldb_logstore_database_upgrade($oldversion) { - - if ($oldversion < 2014041700) { - // Clean up old config. - unset_config('excludelevels', 'logstore_database'); - unset_config('excludeactions', 'logstore_database'); - - // Savepoint reached. - upgrade_plugin_savepoint(true, 2014041700, 'logstore', 'database'); - } +defined('MOODLE_INTERNAL') || die(); - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_logstore_database_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/admin/tool/log/store/standard/db/upgrade.php b/admin/tool/log/store/standard/db/upgrade.php index 9b4247b9a4a91..b844b6271c496 100644 --- a/admin/tool/log/store/standard/db/upgrade.php +++ b/admin/tool/log/store/standard/db/upgrade.php @@ -22,97 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -function xmldb_logstore_standard_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - if ($oldversion < 2014032000) { - - // Define field anonymous to be added to logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $field = new xmldb_field('anonymous', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'relateduserid'); - - // Conditionally launch add field anonymous. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Standard savepoint reached. - upgrade_plugin_savepoint(true, 2014032000, 'logstore', 'standard'); - } - - if ($oldversion < 2014041500) { - - // Define index contextid-component (not unique) to be dropped form logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $index = new xmldb_index('contextid-component', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'component')); - - // Conditionally launch drop index contextid-component. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Define index courseid (not unique) to be dropped form logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $index = new xmldb_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid')); - - // Conditionally launch drop index courseid. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Define index eventname (not unique) to be dropped form logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $index = new xmldb_index('eventname', XMLDB_INDEX_NOTUNIQUE, array('eventname')); +defined('MOODLE_INTERNAL') || die(); - // Conditionally launch drop index eventname. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Define index crud (not unique) to be dropped form logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $index = new xmldb_index('crud', XMLDB_INDEX_NOTUNIQUE, array('crud')); - - // Conditionally launch drop index crud. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Define index edulevel (not unique) to be dropped form logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $index = new xmldb_index('edulevel', XMLDB_INDEX_NOTUNIQUE, array('edulevel')); - - // Conditionally launch drop index edulevel. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Define index course-time (not unique) to be added to logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $index = new xmldb_index('course-time', XMLDB_INDEX_NOTUNIQUE, array('courseid', 'anonymous', 'timecreated')); - - // Conditionally launch add index course-time. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Define index user-module (not unique) to be added to logstore_standard_log. - $table = new xmldb_table('logstore_standard_log'); - $index = new xmldb_index('user-module', XMLDB_INDEX_NOTUNIQUE, array('userid', 'contextlevel', 'contextinstanceid', 'crud', 'edulevel', 'timecreated')); - - // Conditionally launch add index user-module. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Standard savepoint reached. - upgrade_plugin_savepoint(true, 2014041500, 'logstore', 'standard'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_logstore_standard_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/auth/cas/db/upgrade.php b/auth/cas/db/upgrade.php index bca88a4ff61c0..d4211854410f0 100644 --- a/auth/cas/db/upgrade.php +++ b/auth/cas/db/upgrade.php @@ -22,44 +22,19 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_auth_cas_upgrade($oldversion) { - - // Moodle v2.5.0 release upgrade line - // Put any upgrade step following this - - // MDL-39323 New setting in 2.5, make sure it's defined. - if ($oldversion < 2013052100) { - if (get_config('start_tls', 'auth/cas') === false) { - set_config('start_tls', 0, 'auth/cas'); - } - upgrade_plugin_savepoint(true, 2013052100, 'auth', 'cas'); - } - - if ($oldversion < 2013091700) { - // The value of the phpCAS language constants has changed from - // 'langname' to 'CAS_Languages_Langname'. - if ($cas_language = get_config('auth/cas', 'language')) { - set_config('language', 'CAS_Languages_'.ucfirst($cas_language), 'auth/cas'); - } - - upgrade_plugin_savepoint(true, 2013091700, 'auth', 'cas'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG, $DB; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. if ($oldversion < 2014111001) { - global $DB; // From now on the default LDAP objectClass setting for AD has been changed, from 'user' to '(samaccounttype=805306368)'. if (is_enabled_auth('cas') && ($DB->get_field('config_plugins', 'value', array('name' => 'user_type', 'plugin' => 'auth/cas')) === 'ad') diff --git a/auth/ldap/db/upgrade.php b/auth/ldap/db/upgrade.php index 3a320e3683679..762815cf1dbca 100644 --- a/auth/ldap/db/upgrade.php +++ b/auth/ldap/db/upgrade.php @@ -22,34 +22,19 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_auth_ldap_upgrade($oldversion) { - - // Moodle v2.5.0 release upgrade line - // Put any upgrade step following this - - // MDL-39323 New setting in 2.5, make sure it's defined. - if ($oldversion < 2013052100) { - if (get_config('start_tls', 'auth/ldap') === false) { - set_config('start_tls', 0, 'auth/ldap'); - } - upgrade_plugin_savepoint(true, 2013052100, 'auth', 'ldap'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG, $DB; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. if ($oldversion < 2014111001) { - global $DB; // From now on the default LDAP objectClass setting for AD has been changed, from 'user' to '(samaccounttype=805306368)'. if (is_enabled_auth('ldap') && ($DB->get_field('config_plugins', 'value', array('name' => 'user_type', 'plugin' => 'auth/ldap')) === 'ad') diff --git a/auth/manual/db/upgrade.php b/auth/manual/db/upgrade.php index 3039953d64985..3c0ae5557877c 100644 --- a/auth/manual/db/upgrade.php +++ b/auth/manual/db/upgrade.php @@ -22,33 +22,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_auth_manual_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/auth/mnet/db/upgrade.php b/auth/mnet/db/upgrade.php index 0090939edcdc7..bfdef15f2a94a 100644 --- a/auth/mnet/db/upgrade.php +++ b/auth/mnet/db/upgrade.php @@ -22,33 +22,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_auth_mnet_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/blocks/community/db/upgrade.php b/blocks/community/db/upgrade.php index bcc82dc28f9ba..3a3e7b1c59e00 100644 --- a/blocks/community/db/upgrade.php +++ b/blocks/community/db/upgrade.php @@ -37,31 +37,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * * @param int $oldversion - * @param object $block */ function xmldb_block_community_upgrade($oldversion) { - global $CFG, $DB; - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/blocks/completionstatus/db/upgrade.php b/blocks/completionstatus/db/upgrade.php index 070ebcc6217a3..f44773ad4b1ec 100644 --- a/blocks/completionstatus/db/upgrade.php +++ b/blocks/completionstatus/db/upgrade.php @@ -37,6 +37,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Handles upgrading instances of this block. * @@ -44,31 +46,7 @@ * @param object $block */ function xmldb_block_completionstatus_upgrade($oldversion, $block) { - global $DB; - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - if ($oldversion < 2012112901) { - // Get the instances of this block. - if ($blocks = $DB->get_records('block_instances', array('blockname' => 'completionstatus', 'pagetypepattern' => 'my-index'))) { - // Loop through and remove them from the My Moodle page. - foreach ($blocks as $block) { - blocks_delete_instance($block); - } - } - // Savepoint reached. - upgrade_block_savepoint(true, 2012112901, 'completionstatus'); - } - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -80,4 +58,4 @@ function xmldb_block_completionstatus_upgrade($oldversion, $block) { // Put any upgrade step following this. return true; -} \ No newline at end of file +} diff --git a/blocks/course_summary/db/upgrade.php b/blocks/course_summary/db/upgrade.php index 0c1549e7518d8..1678a1be5353a 100644 --- a/blocks/course_summary/db/upgrade.php +++ b/blocks/course_summary/db/upgrade.php @@ -37,6 +37,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Handles upgrading instances of this block. * @@ -44,35 +46,7 @@ * @param object $block */ function xmldb_block_course_summary_upgrade($oldversion, $block) { - global $DB; - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - if ($oldversion < 2012112901) { - // Get the instances of this block. - if ($blocks = $DB->get_records('block_instances', array('blockname' => 'course_summary', 'pagetypepattern' => 'my-index'))) { - // Loop through and remove them from the My Moodle page. - foreach ($blocks as $block) { - blocks_delete_instance($block); - } - - } - - // Savepoint reached. - upgrade_block_savepoint(true, 2012112901, 'course_summary'); - } - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -84,4 +58,4 @@ function xmldb_block_course_summary_upgrade($oldversion, $block) { // Put any upgrade step following this. return true; -} \ No newline at end of file +} diff --git a/blocks/html/db/upgrade.php b/blocks/html/db/upgrade.php index ff87abfc02bdb..4b5a51a4a157e 100644 --- a/blocks/html/db/upgrade.php +++ b/blocks/html/db/upgrade.php @@ -23,32 +23,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Upgrade code for the HTML block. * * @param int $oldversion - * @param object $block */ function xmldb_block_html_upgrade($oldversion) { - global $CFG, $DB; - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/blocks/navigation/db/upgrade.php b/blocks/navigation/db/upgrade.php index 6ea926847267a..430bb9ed0b9d7 100644 --- a/blocks/navigation/db/upgrade.php +++ b/blocks/navigation/db/upgrade.php @@ -37,6 +37,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * As of the implementation of this block and the general navigation code * in Moodle 2.0 the body of immediate upgrade work for this block and @@ -47,33 +49,11 @@ * was complex due to us wanting to remvoe the outmoded blocks that this * block was going to replace. * - * @global moodle_database $DB * @param int $oldversion * @param object $block */ function xmldb_block_navigation_upgrade($oldversion, $block) { - global $DB; - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -85,4 +65,4 @@ function xmldb_block_navigation_upgrade($oldversion, $block) { // Put any upgrade step following this. return true; -} \ No newline at end of file +} diff --git a/blocks/recent_activity/db/upgrade.php b/blocks/recent_activity/db/upgrade.php index 8d0f8935866a8..02e8be0f8cfbd 100644 --- a/blocks/recent_activity/db/upgrade.php +++ b/blocks/recent_activity/db/upgrade.php @@ -36,53 +36,16 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Upgrade code for the recent activity block. * - * @global moodle_database $DB * @param int $oldversion * @param object $block */ function xmldb_block_recent_activity_upgrade($oldversion, $block) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes - - if ($oldversion < 2014012000) { - - // Define table block_recent_activity to be created. - $table = new xmldb_table('block_recent_activity'); - - // Adding fields to table block_recent_activity. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('cmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('action', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null); - $table->add_field('modname', XMLDB_TYPE_CHAR, '20', null, null, null, null); - - // Adding keys to table block_recent_activity. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Adding indexes to table block_recent_activity. - $table->add_index('coursetime', XMLDB_INDEX_NOTUNIQUE, array('courseid', 'timecreated')); - - // Conditionally launch create table for block_recent_activity. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - // Insert dummy log record for each existing course to notify that their logs need to be migrated. - $DB->execute('INSERT INTO {block_recent_activity} (timecreated, userid, courseid, cmid, action) '. - 'SELECT ?, 0, id, 0, 3 FROM {course}', - array(time())); - } - - // Recent_activity savepoint reached. - upgrade_block_savepoint(true, 2014012000, 'recent_activity'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/blocks/section_links/db/upgrade.php b/blocks/section_links/db/upgrade.php index 057f2752fa308..66f795733945e 100644 --- a/blocks/section_links/db/upgrade.php +++ b/blocks/section_links/db/upgrade.php @@ -37,6 +37,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Upgrade code for the section links block. * @@ -45,46 +47,7 @@ * @param object $block */ function xmldb_block_section_links_upgrade($oldversion, $block) { - global $DB; - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2013012200.00) { - - // The section links block used to use its own crazy plugin name. - // Here we are converting it to the proper component name. - $oldplugin = 'blocks/section_links'; - $newplugin = 'block_section_links'; - - // Use the proper API here... thats what we should be doing as it ensures any caches etc are cleared - // along the way! - // It may be quicker to just write an SQL statement but that would be reckless. - $config = get_config($oldplugin); - if (!empty($config)) { - foreach ($config as $name => $value) { - set_config($name, $value, $newplugin); - unset_config($name, $oldplugin); - } - } - - // Main savepoint reached. - upgrade_block_savepoint(true, 2013012200.00, 'section_links'); - } - - - // Moodle v2.5.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/blocks/selfcompletion/db/upgrade.php b/blocks/selfcompletion/db/upgrade.php index e79331c6338de..9dee1f5fc6b61 100644 --- a/blocks/selfcompletion/db/upgrade.php +++ b/blocks/selfcompletion/db/upgrade.php @@ -37,6 +37,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Handles upgrading instances of this block. * @@ -44,35 +46,7 @@ * @param object $block */ function xmldb_block_selfcompletion_upgrade($oldversion, $block) { - global $DB; - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - if ($oldversion < 2012112901) { - // Get the instances of this block. - if ($blocks = $DB->get_records('block_instances', array('blockname' => 'selfcompletion', 'pagetypepattern' => 'my-index'))) { - // Loop through and remove them from the My Moodle page. - foreach ($blocks as $block) { - blocks_delete_instance($block); - } - - } - - // Savepoint reached. - upgrade_block_savepoint(true, 2012112901, 'selfcompletion'); - } - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -84,4 +58,4 @@ function xmldb_block_selfcompletion_upgrade($oldversion, $block) { // Put any upgrade step following this. return true; -} \ No newline at end of file +} diff --git a/blocks/settings/db/upgrade.php b/blocks/settings/db/upgrade.php index b1cf6f8bc2ec4..bd96db66f6405 100644 --- a/blocks/settings/db/upgrade.php +++ b/blocks/settings/db/upgrade.php @@ -37,6 +37,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * As of the implementation of this block and the general navigation code * in Moodle 2.0 the body of immediate upgrade work for this block and @@ -47,33 +49,11 @@ * was complex due to us wanting to remvoe the outmoded blocks that this * block was going to replace. * - * @global moodle_database $DB * @param int $oldversion * @param object $block */ function xmldb_block_settings_upgrade($oldversion, $block) { - global $DB; - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -85,4 +65,4 @@ function xmldb_block_settings_upgrade($oldversion, $block) { // Put any upgrade step following this. return true; -} \ No newline at end of file +} diff --git a/enrol/database/db/upgrade.php b/enrol/database/db/upgrade.php index d1eb164670e55..a2d2c53ef53d5 100644 --- a/enrol/database/db/upgrade.php +++ b/enrol/database/db/upgrade.php @@ -23,29 +23,9 @@ */ defined('MOODLE_INTERNAL') || die(); -function xmldb_enrol_database_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_enrol_database_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/enrol/flatfile/db/upgrade.php b/enrol/flatfile/db/upgrade.php index ebe5dd7824589..f16aa4d9ffb98 100644 --- a/enrol/flatfile/db/upgrade.php +++ b/enrol/flatfile/db/upgrade.php @@ -25,28 +25,7 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_enrol_flatfile_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/enrol/guest/db/upgrade.php b/enrol/guest/db/upgrade.php index 8ae20049c9091..e1111f76a56b7 100644 --- a/enrol/guest/db/upgrade.php +++ b/enrol/guest/db/upgrade.php @@ -18,44 +18,14 @@ * This file keeps track of upgrades to the guest enrolment plugin. * * @package enrol_guest - * @copyright 2011 Petr Skoda {@link http://skodak.org + * @copyright 2011 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); function xmldb_enrol_guest_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2011112901) { - // convert all null passwords to empty strings - $DB->set_field('enrol', 'password', '', array('enrol'=>'guest', 'password'=>null)); - - upgrade_plugin_savepoint(true, 2011112901, 'enrol', 'guest'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -68,5 +38,3 @@ function xmldb_enrol_guest_upgrade($oldversion) { return true; } - - diff --git a/enrol/imsenterprise/db/upgrade.php b/enrol/imsenterprise/db/upgrade.php index 7fb9ea32f9ea5..0bc61348f834b 100644 --- a/enrol/imsenterprise/db/upgrade.php +++ b/enrol/imsenterprise/db/upgrade.php @@ -31,24 +31,7 @@ * @return bool true */ function xmldb_enrol_imsenterprise_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/enrol/manual/db/upgrade.php b/enrol/manual/db/upgrade.php index 7b98f19124aa5..5ec65e3f38c0b 100644 --- a/enrol/manual/db/upgrade.php +++ b/enrol/manual/db/upgrade.php @@ -18,47 +18,14 @@ * This file keeps track of upgrades to the manual enrolment plugin * * @package enrol_manual - * @copyright 2012 Petr Skoda {@link http://skodak.org + * @copyright 2012 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); function xmldb_enrol_manual_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012100702) { - // Set default expiry threshold to 1 day. - $DB->execute("UPDATE {enrol} SET expirythreshold = 86400 WHERE enrol = 'manual' AND expirythreshold = 0"); - upgrade_plugin_savepoint(true, 2012100702, 'enrol', 'manual'); - } - - if ($oldversion < 2012101400) { - // Delete obsoleted settings, now using expiry* prefix to make them more consistent. - unset_config('notifylast', 'enrol_manual'); - unset_config('notifyhour', 'enrol_manual'); - upgrade_plugin_savepoint(true, 2012101400, 'enrol', 'manual'); - } - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -77,5 +44,3 @@ function xmldb_enrol_manual_upgrade($oldversion) { return true; } - - diff --git a/enrol/mnet/db/upgrade.php b/enrol/mnet/db/upgrade.php index e66d6ec26c93b..2a596416f91fa 100644 --- a/enrol/mnet/db/upgrade.php +++ b/enrol/mnet/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/enrol/paypal/db/upgrade.php b/enrol/paypal/db/upgrade.php index faf51dc318cc5..1497469672cc7 100644 --- a/enrol/paypal/db/upgrade.php +++ b/enrol/paypal/db/upgrade.php @@ -40,29 +40,10 @@ // Please do not forget to use upgrade_set_timeout() // before any action that may take longer time to finish. -function xmldb_enrol_paypal_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - +defined('MOODLE_INTERNAL') || die(); - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_enrol_paypal_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/enrol/self/db/upgrade.php b/enrol/self/db/upgrade.php index 62cb0dfa4644f..82bb97d36acaf 100644 --- a/enrol/self/db/upgrade.php +++ b/enrol/self/db/upgrade.php @@ -18,52 +18,14 @@ * This file keeps track of upgrades to the self enrolment plugin * * @package enrol_self - * @copyright 2012 Petr Skoda {@link http://skodak.org + * @copyright 2012 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); function xmldb_enrol_self_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012101400) { - // Set default expiry threshold to 1 day. - $DB->execute("UPDATE {enrol} SET expirythreshold = 86400 WHERE enrol = 'self' AND expirythreshold = 0"); - upgrade_plugin_savepoint(true, 2012101400, 'enrol', 'self'); - } - - if ($oldversion < 2012120600) { - // Enable new self enrolments everywhere. - $DB->execute("UPDATE {enrol} SET customint6 = 1 WHERE enrol = 'self'"); - upgrade_plugin_savepoint(true, 2012120600, 'enrol', 'self'); - } - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013112100) { - // Set customint1 (group enrolment key) to 0 if it was not set (null). - $DB->execute("UPDATE {enrol} SET customint1 = 0 WHERE enrol = 'self' AND customint1 IS NULL"); - upgrade_plugin_savepoint(true, 2013112100, 'enrol', 'self'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -76,5 +38,3 @@ function xmldb_enrol_self_upgrade($oldversion) { return true; } - - diff --git a/filter/mathjaxloader/db/upgrade.php b/filter/mathjaxloader/db/upgrade.php index eb1e4cd56e76a..056cc18bc95ed 100644 --- a/filter/mathjaxloader/db/upgrade.php +++ b/filter/mathjaxloader/db/upgrade.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result @@ -31,9 +33,6 @@ function xmldb_filter_mathjaxloader_upgrade($oldversion) { $dbman = $DB->get_manager(); - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014081100) { $sslcdnurl = get_config('filter_mathjaxloader', 'httpsurl'); diff --git a/filter/mediaplugin/db/upgrade.php b/filter/mediaplugin/db/upgrade.php index 3e37445315d7d..2a70d6135e25d 100644 --- a/filter/mediaplugin/db/upgrade.php +++ b/filter/mediaplugin/db/upgrade.php @@ -23,54 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_filter_mediaplugin_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - if ($oldversion < 2011121200) { - // Move all the media enable setttings that are now handled by core media renderer. - foreach (array('html5video', 'html5audio', 'mp3', 'flv', 'wmp', 'qt', 'rm', - 'youtube', 'vimeo', 'swf') as $type) { - $existingkey = 'filter_mediaplugin_enable_' . $type; - if (array_key_exists($existingkey, $CFG)) { - set_config('core_media_enable_' . $type, $CFG->{$existingkey}); - unset_config($existingkey); - } - } - - // Override setting for html5 to turn it on (previous default was off; because - // of changes in the way fallbacks are handled, this is now unlikely to cause - // a problem, and is required for mobile a/v support on non-Flash devices, so - // this change is basically needed in order to maintain existing behaviour). - set_config('core_media_enable_html5video', 1); - set_config('core_media_enable_html5audio', 1); - - upgrade_plugin_savepoint(true, 2011121200, 'filter', 'mediaplugin'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/filter/tex/db/upgrade.php b/filter/tex/db/upgrade.php index 703a7d400a8f9..14aa3d8ac22f1 100644 --- a/filter/tex/db/upgrade.php +++ b/filter/tex/db/upgrade.php @@ -23,50 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_filter_tex_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013120300) { - $settings = array( - 'density', 'latexbackground', 'convertformat', 'pathlatex', - 'convertformat', 'pathconvert', 'pathdvips', 'latexpreamble'); - - // Move tex settings to config_pluins and delete entries from the config table. - foreach ($settings as $setting) { - $existingkey = 'filter_tex_'.$setting; - if (array_key_exists($existingkey, $CFG)) { - set_config($setting, $CFG->{$existingkey}, 'filter_tex'); - unset_config($existingkey); - } - } - - upgrade_plugin_savepoint(true, 2013120300, 'filter', 'tex'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/grade/grading/form/rubric/db/upgrade.php b/grade/grading/form/rubric/db/upgrade.php index a40da47ac6030..68a632f9b528f 100644 --- a/grade/grading/form/rubric/db/upgrade.php +++ b/grade/grading/form/rubric/db/upgrade.php @@ -31,30 +31,7 @@ * @return bool true */ function xmldb_gradingform_rubric_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 7e6ca5c4af044..82ac37768723c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -85,3557 +85,22 @@ * @return bool always true */ function xmldb_main_upgrade($oldversion) { - global $CFG, $USER, $DB, $OUTPUT, $SITE, $COURSE; + global $CFG, $DB; - require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions + require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions. - $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes + $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. - if ($oldversion < 2011120500) { - // just in case somebody hacks upgrade scripts or env, we really can not continue - echo("You need to upgrade to 2.2.x first!\n"); + // Always keep this upgrade step with version being the minimum + // allowed version to upgrade from (v2.7.0 right now). + if ($oldversion < 2014051200) { + // Just in case somebody hacks upgrade scripts or env, we really can not continue. + echo("You need to upgrade to 2.7.x or higher first!\n"); exit(1); - // Note this savepoint is 100% unreachable, but needed to pass the upgrade checks - upgrade_main_savepoint(true, 2011120500); + // Note this savepoint is 100% unreachable, but needed to pass the upgrade checks. + upgrade_main_savepoint(true, 2014051200); } - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2011120500.02) { - - upgrade_set_timeout(60*20); // This may take a while - // MDL-28180. Some missing restrictions in certain backup & restore operations - // were causing incorrect duplicates in the course_completion_aggr_methd table. - // This upgrade step takes rid of them. - $sql = 'SELECT course, criteriatype, MIN(id) AS minid - FROM {course_completion_aggr_methd} - GROUP BY course, criteriatype - HAVING COUNT(*) > 1'; - $duprs = $DB->get_recordset_sql($sql); - foreach ($duprs as $duprec) { - // We need to handle NULLs in criteriatype diferently - if (is_null($duprec->criteriatype)) { - $where = 'course = ? AND criteriatype IS NULL AND id > ?'; - $params = array($duprec->course, $duprec->minid); - } else { - $where = 'course = ? AND criteriatype = ? AND id > ?'; - $params = array($duprec->course, $duprec->criteriatype, $duprec->minid); - } - $DB->delete_records_select('course_completion_aggr_methd', $where, $params); - } - $duprs->close(); - - // Main savepoint reached - upgrade_main_savepoint(true, 2011120500.02); - } - - if ($oldversion < 2011120500.03) { - - // Changing precision of field value on table user_preferences to (1333) - $table = new xmldb_table('user_preferences'); - $field = new xmldb_field('value', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'name'); - - // Launch change of precision for field value - $dbman->change_field_precision($table, $field); - - // Main savepoint reached - upgrade_main_savepoint(true, 2011120500.03); - } - - if ($oldversion < 2012020200.03) { - - // Define index rolecontext (not unique) to be added to role_assignments - $table = new xmldb_table('role_assignments'); - $index = new xmldb_index('rolecontext', XMLDB_INDEX_NOTUNIQUE, array('roleid', 'contextid')); - - // Conditionally launch add index rolecontext - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Define index usercontextrole (not unique) to be added to role_assignments - $index = new xmldb_index('usercontextrole', XMLDB_INDEX_NOTUNIQUE, array('userid', 'contextid', 'roleid')); - - // Conditionally launch add index usercontextrole - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012020200.03); - } - - if ($oldversion < 2012020200.06) { - // Previously we always allowed users to override their email address via the messaging system - // We have now added a setting to allow admins to turn this this ability on and off - // While this setting defaults to 0 (off) we're setting it to 1 (on) to maintain the behaviour for upgrading sites - set_config('messagingallowemailoverride', 1); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012020200.06); - } - - if ($oldversion < 2012021700.01) { - // Changing precision of field uniquehash on table post to 255 - $table = new xmldb_table('post'); - $field = new xmldb_field('uniquehash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'content'); - - // Launch change of precision for field uniquehash - $dbman->change_field_precision($table, $field); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012021700.01); - } - - if ($oldversion < 2012021700.02) { - // Somewhere before 1.9 summary and content column in post table were not null. In 1.9+ - // not null became false. - $columns = $DB->get_columns('post'); - - // Fix discrepancies in summary field after upgrade from 1.9 - if (array_key_exists('summary', $columns) && $columns['summary']->not_null != false) { - $table = new xmldb_table('post'); - $summaryfield = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'subject'); - - if ($dbman->field_exists($table, $summaryfield)) { - $dbman->change_field_notnull($table, $summaryfield); - } - - } - - // Fix discrepancies in content field after upgrade from 1.9 - if (array_key_exists('content', $columns) && $columns['content']->not_null != false) { - $table = new xmldb_table('post'); - $contentfield = new xmldb_field('content', XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'summary'); - - if ($dbman->field_exists($table, $contentfield)) { - $dbman->change_field_notnull($table, $contentfield); - } - - } - - upgrade_main_savepoint(true, 2012021700.02); - } - - // The ability to backup user (private) files is out completely - MDL-29248 - if ($oldversion < 2012030100.01) { - unset_config('backup_general_user_files', 'backup'); - unset_config('backup_general_user_files_locked', 'backup'); - unset_config('backup_auto_user_files', 'backup'); - - upgrade_main_savepoint(true, 2012030100.01); - } - - if ($oldversion < 2012030900.01) { - // Migrate all numbers to signed & all texts and binaries to big size. - // It should be safe to interrupt this and continue later. - upgrade_mysql_fix_unsigned_and_lob_columns(); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012030900.01); - } - - if ($oldversion < 2012031500.01) { - // Upgrade old course_allowed_modules data to be permission overrides. - if ($CFG->restrictmodulesfor === 'all') { - $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1'); - } else if ($CFG->restrictmodulesfor === 'requested') { - $courses = $DB->get_records_menu('course', array('restrictmodules' => 1), 'id', 'id, 1'); - } else { - $courses = array(); - } - - if (!$dbman->table_exists('course_allowed_modules')) { - // Upgrade must already have been run on this server. This might happen, - // for example, during development of these changes. - $courses = array(); - } - - $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name'); - - $coursecount = count($courses); - if ($coursecount) { - $pbar = new progress_bar('allowedmods', 500, true); - $transaction = $DB->start_delegated_transaction(); - } - - $i = 0; - foreach ($courses as $courseid => $notused) { - $i += 1; - upgrade_set_timeout(60); // 1 minute per course should be fine. - - $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', - array('course' => $courseid), 'module', 'module, 1'); - if (empty($allowedmoduleids)) { - // This seems to be the best match for backwards compatibility, - // not necessarily with the old code in course_allowed_module function, - // but with the code that used to be in the coures settings form. - $allowedmoduleids = explode(',', $CFG->defaultallowedmodules); - $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids); - } - - $context = context_course::instance($courseid); - - list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities'); - list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config'); - foreach ($managerroleids as $roleid) { - unset($roleids[$roleid]); - } - - foreach ($modidtoname as $modid => $modname) { - if (isset($allowedmoduleids[$modid])) { - // Module is allowed, no worries. - continue; - } - - $capability = 'mod/' . $modname . ':addinstance'; - foreach ($roleids as $roleid) { - assign_capability($capability, CAP_PREVENT, $roleid, $context); - } - } - - $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - $i/$coursecount."); - } - - if ($coursecount) { - $transaction->allow_commit(); - } - - upgrade_main_savepoint(true, 2012031500.01); - } - - if ($oldversion < 2012031500.02) { - - // Define field restrictmodules to be dropped from course - $table = new xmldb_table('course'); - $field = new xmldb_field('restrictmodules'); - - // Conditionally launch drop field requested - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - upgrade_main_savepoint(true, 2012031500.02); - } - - if ($oldversion < 2012031500.03) { - - // Define table course_allowed_modules to be dropped - $table = new xmldb_table('course_allowed_modules'); - - // Conditionally launch drop table for course_allowed_modules - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - upgrade_main_savepoint(true, 2012031500.03); - } - - if ($oldversion < 2012031500.04) { - // Clean up the old admin settings. - unset_config('restrictmodulesfor'); - unset_config('restrictbydefault'); - unset_config('defaultallowedmodules'); - - upgrade_main_savepoint(true, 2012031500.04); - } - - if ($oldversion < 2012032300.02) { - // Migrate the old admin debug setting. - if ($CFG->debug == 38911) { - set_config('debug', DEBUG_DEVELOPER); - } else if ($CFG->debug == 6143) { - set_config('debug', DEBUG_ALL); - } - upgrade_main_savepoint(true, 2012032300.02); - } - - if ($oldversion < 2012042300.00) { - // This change makes the course_section index unique. - - // Look for any duplicate course_sections entries. There should not be - // any but on some busy systems we found a few, maybe due to previous - // bugs. - $transaction = $DB->start_delegated_transaction(); - $rs = $DB->get_recordset_sql(' - SELECT DISTINCT - cs.id, cs.course - FROM - {course_sections} cs - INNER JOIN {course_sections} older - ON cs.course = older.course AND cs.section = older.section - AND older.id < cs.id'); - foreach ($rs as $rec) { - $DB->delete_records('course_sections', array('id' => $rec->id)); - // We can't use rebuild_course_cache() here because introducing sectioncache later - // so reset modinfo manually. - $DB->set_field('course', 'modinfo', null, array('id' => $rec->course)); - } - $rs->close(); - $transaction->allow_commit(); - - // XMLDB does not allow changing index uniqueness - instead we must drop - // index then add it again. - // MDL-46182: The query to make the index unique uses the index, - // so the removal of the non-unique version needs to happen after any - // data changes have been made. - $table = new xmldb_table('course_sections'); - $index = new xmldb_index('course_section', XMLDB_INDEX_NOTUNIQUE, array('course', 'section')); - - // Conditionally launch drop index course_section. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Define index course_section (unique) to be added to course_sections - $index = new xmldb_index('course_section', XMLDB_INDEX_UNIQUE, array('course', 'section')); - - // Conditionally launch add index course_section - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012042300.00); - } - - if ($oldversion < 2012042300.02) { - require_once($CFG->dirroot.'/completion/criteria/completion_criteria.php'); - // Delete orphaned criteria which were left when modules were removed - if ($DB->get_dbfamily() === 'mysql') { - $sql = "DELETE cc FROM {course_completion_criteria} cc - LEFT JOIN {course_modules} cm ON cm.id = cc.moduleinstance - WHERE cm.id IS NULL AND cc.criteriatype = ".COMPLETION_CRITERIA_TYPE_ACTIVITY; - } else { - $sql = "DELETE FROM {course_completion_criteria} - WHERE NOT EXISTS ( - SELECT 'x' FROM {course_modules} - WHERE {course_modules}.id = {course_completion_criteria}.moduleinstance) - AND {course_completion_criteria}.criteriatype = ".COMPLETION_CRITERIA_TYPE_ACTIVITY; - } - $DB->execute($sql); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012042300.02); - } - - if ($oldversion < 2012050300.01) { - // Make sure deleted users do not have picture flag. - $DB->set_field('user', 'picture', 0, array('deleted'=>1, 'picture'=>1)); - upgrade_main_savepoint(true, 2012050300.01); - } - - if ($oldversion < 2012050300.02) { - - // Changing precision of field picture on table user to (10) - $table = new xmldb_table('user'); - $field = new xmldb_field('picture', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'secret'); - - // Launch change of precision for field picture - $dbman->change_field_precision($table, $field); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012050300.02); - } - - if ($oldversion < 2012050300.03) { - - // Define field coursedisplay to be added to course - $table = new xmldb_table('course'); - $field = new xmldb_field('coursedisplay', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'completionnotify'); - - // Conditionally launch add field coursedisplay - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012050300.03); - } - - if ($oldversion < 2012050300.04) { - - // Define table course_display to be dropped - $table = new xmldb_table('course_display'); - - // Conditionally launch drop table for course_display - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012050300.04); - } - - if ($oldversion < 2012050300.05) { - - // Clean up removed admin setting. - unset_config('navlinkcoursesections'); - - upgrade_main_savepoint(true, 2012050300.05); - } - - if ($oldversion < 2012050400.01) { - - // Define index sortorder (not unique) to be added to course - $table = new xmldb_table('course'); - $index = new xmldb_index('sortorder', XMLDB_INDEX_NOTUNIQUE, array('sortorder')); - - // Conditionally launch add index sortorder - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012050400.01); - } - - if ($oldversion < 2012050400.02) { - - // Clean up removed admin setting. - unset_config('enablecourseajax'); - - upgrade_main_savepoint(true, 2012050400.02); - } - - if ($oldversion < 2012051100.01) { - - // Define field idnumber to be added to groups - $table = new xmldb_table('groups'); - $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'courseid'); - $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); - - // Conditionally launch add field idnumber - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Conditionally launch add index idnumber - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Define field idnumber to be added to groupings - $table = new xmldb_table('groupings'); - $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'name'); - $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); - - // Conditionally launch add field idnumber - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Conditionally launch add index idnumber - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012051100.01); - } - - if ($oldversion < 2012051100.03) { - - // Amend course table to add sectioncache cache - $table = new xmldb_table('course'); - $field = new xmldb_field('sectioncache', XMLDB_TYPE_TEXT, null, null, null, null, null, 'showgrades'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Amend course_sections to add date, time and groupingid availability - // conditions and a setting about whether to show them - $table = new xmldb_table('course_sections'); - $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'visible'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'availablefrom'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'availableuntil'); - // Conditionally launch add field showavailability - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - $field = new xmldb_field('groupingid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'showavailability'); - // Conditionally launch add field groupingid - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Add course_sections_availability to add completion & grade availability conditions - $table = new xmldb_table('course_sections_availability'); - - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('coursesectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', null, null, null, null); - $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', null, 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); - - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('coursesectionid', XMLDB_KEY_FOREIGN, array('coursesectionid'), 'course_sections', 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')); - - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012051100.03); - } - - if ($oldversion < 2012052100.00) { - - // Define field referencefileid to be added to files. - $table = new xmldb_table('files'); - - // Define field referencefileid to be added to files. - $field = new xmldb_field('referencefileid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'sortorder'); - - // Conditionally launch add field referencefileid. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field referencelastsync to be added to files. - $field = new xmldb_field('referencelastsync', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'referencefileid'); - - // Conditionally launch add field referencelastsync. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field referencelifetime to be added to files. - $field = new xmldb_field('referencelifetime', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'referencelastsync'); - - // Conditionally launch add field referencelifetime. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $key = new xmldb_key('referencefileid', XMLDB_KEY_FOREIGN, array('referencefileid'), 'files_reference', array('id')); - // Launch add key referencefileid - $dbman->add_key($table, $key); - - // Define table files_reference to be created. - $table = new xmldb_table('files_reference'); - - // Adding fields to table files_reference. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('repositoryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('lastsync', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('lifetime', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('reference', XMLDB_TYPE_TEXT, null, null, null, null, null); - - // Adding keys to table files_reference. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('repositoryid', XMLDB_KEY_FOREIGN, array('repositoryid'), 'repository_instances', array('id')); - - // Conditionally launch create table for files_reference - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052100.00); - } - - if ($oldversion < 2012052500.03) { // fix invalid course_completion_records MDL-27368 - //first get all instances of duplicate records - $sql = 'SELECT userid, course FROM {course_completions} WHERE (deleted IS NULL OR deleted <> 1) GROUP BY userid, course HAVING (count(id) > 1)'; - $duplicates = $DB->get_recordset_sql($sql, array()); - - foreach ($duplicates as $duplicate) { - $pointer = 0; - //now get all the records for this user/course - $sql = 'userid = ? AND course = ? AND (deleted IS NULL OR deleted <> 1)'; - $completions = $DB->get_records_select('course_completions', $sql, - array($duplicate->userid, $duplicate->course), 'timecompleted DESC, timestarted DESC'); - $needsupdate = false; - $origcompletion = null; - foreach ($completions as $completion) { - $pointer++; - if ($pointer === 1) { //keep 1st record but delete all others. - $origcompletion = $completion; - } else { - //we need to keep the "oldest" of all these fields as the valid completion record. - $fieldstocheck = array('timecompleted', 'timestarted', 'timeenrolled'); - foreach ($fieldstocheck as $f) { - if ($origcompletion->$f > $completion->$f) { - $origcompletion->$f = $completion->$f; - $needsupdate = true; - } - } - $DB->delete_records('course_completions', array('id'=>$completion->id)); - } - } - if ($needsupdate) { - $DB->update_record('course_completions', $origcompletion); - } - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052500.03); - } - - if ($oldversion < 2012052900.00) { - // Clean up all duplicate records in the course_completions table in preparation - // for adding a new index there. - upgrade_course_completion_remove_duplicates( - 'course_completions', - array('userid', 'course'), - array('timecompleted', 'timestarted', 'timeenrolled') - ); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052900.00); - } - - if ($oldversion < 2012052900.01) { - // Add indexes to prevent new duplicates in the course_completions table. - // Define index useridcourse (unique) to be added to course_completions - $table = new xmldb_table('course_completions'); - $index = new xmldb_index('useridcourse', XMLDB_INDEX_UNIQUE, array('userid', 'course')); - - // Conditionally launch add index useridcourse - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052900.01); - } - - if ($oldversion < 2012052900.02) { - // Clean up all duplicate records in the course_completion_crit_compl table in preparation - // for adding a new index there. - upgrade_course_completion_remove_duplicates( - 'course_completion_crit_compl', - array('userid', 'course', 'criteriaid'), - array('timecompleted') - ); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052900.02); - } - - if ($oldversion < 2012052900.03) { - // Add indexes to prevent new duplicates in the course_completion_crit_compl table. - // Define index useridcoursecriteraid (unique) to be added to course_completion_crit_compl - $table = new xmldb_table('course_completion_crit_compl'); - $index = new xmldb_index('useridcoursecriteraid', XMLDB_INDEX_UNIQUE, array('userid', 'course', 'criteriaid')); - - // Conditionally launch add index useridcoursecriteraid - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052900.03); - } - - if ($oldversion < 2012052900.04) { - // Clean up all duplicate records in the course_completion_aggr_methd table in preparation - // for adding a new index there. - upgrade_course_completion_remove_duplicates( - 'course_completion_aggr_methd', - array('course', 'criteriatype') - ); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052900.04); - } - - if ($oldversion < 2012052900.05) { - // Add indexes to prevent new duplicates in the course_completion_aggr_methd table. - // Define index coursecriteratype (unique) to be added to course_completion_aggr_methd - $table = new xmldb_table('course_completion_aggr_methd'); - $index = new xmldb_index('coursecriteriatype', XMLDB_INDEX_UNIQUE, array('course', 'criteriatype')); - - // Conditionally launch add index coursecriteratype - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012052900.05); - } - - if ($oldversion < 2012060600.01) { - // Add field referencehash to files_reference - $table = new xmldb_table('files_reference'); - $field = new xmldb_field('referencehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'reference'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_main_savepoint(true, 2012060600.01); - } - - if ($oldversion < 2012060600.02) { - // Populate referencehash field with SHA1 hash of the reference - this shoudl affect only 2.3dev sites - // that were using the feature for testing. Production sites have the table empty. - $rs = $DB->get_recordset('files_reference', null, '', 'id, reference'); - foreach ($rs as $record) { - $hash = sha1($record->reference); - $DB->set_field('files_reference', 'referencehash', $hash, array('id' => $record->id)); - } - $rs->close(); - - upgrade_main_savepoint(true, 2012060600.02); - } - - if ($oldversion < 2012060600.03) { - // Merge duplicate records in files_reference that were created during the development - // phase at 2.3dev sites. This is needed so we can create the unique index over - // (repositoryid, referencehash) fields. - $sql = "SELECT repositoryid, referencehash, MIN(id) AS minid - FROM {files_reference} - GROUP BY repositoryid, referencehash - HAVING COUNT(*) > 1"; - $duprs = $DB->get_recordset_sql($sql); - foreach ($duprs as $duprec) { - // get the list of all ids in {files_reference} that need to be remapped - $dupids = $DB->get_records_select('files_reference', "repositoryid = ? AND referencehash = ? AND id > ?", - array($duprec->repositoryid, $duprec->referencehash, $duprec->minid), '', 'id'); - $dupids = array_keys($dupids); - // relink records in {files} that are now referring to a duplicate record - // in {files_reference} to refer to the first one - list($subsql, $subparams) = $DB->get_in_or_equal($dupids); - $DB->set_field_select('files', 'referencefileid', $duprec->minid, "referencefileid $subsql", $subparams); - // and finally remove all orphaned records from {files_reference} - $DB->delete_records_list('files_reference', 'id', $dupids); - } - $duprs->close(); - - upgrade_main_savepoint(true, 2012060600.03); - } - - if ($oldversion < 2012060600.04) { - // Add a unique index over repositoryid and referencehash fields in files_reference table - $table = new xmldb_table('files_reference'); - $index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('repositoryid', 'referencehash')); - - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - upgrade_main_savepoint(true, 2012060600.04); - } - - if ($oldversion < 2012061800.01) { - - // Define field screenreader to be dropped from user - $table = new xmldb_table('user'); - $field = new xmldb_field('ajax'); - - // Conditionally launch drop field screenreader - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012061800.01); - } - - if ($oldversion < 2012062000.00) { - // Add field newcontextid to backup_files_template - $table = new xmldb_table('backup_files_template'); - $field = new xmldb_field('newcontextid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'info'); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_main_savepoint(true, 2012062000.00); - } - - if ($oldversion < 2012062000.01) { - // Add field newitemid to backup_files_template - $table = new xmldb_table('backup_files_template'); - $field = new xmldb_field('newitemid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'newcontextid'); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_main_savepoint(true, 2012062000.01); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012062500.02) { - // 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, 2012062500.02); - } - - if ($oldversion < 2012070600.04) { - // Define table course_modules_avail_fields to be created - $table = new xmldb_table('course_modules_avail_fields'); - - // Adding fields to table course_modules_avail_fields - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('userfield', XMLDB_TYPE_CHAR, '50', null, null, null, null); - $table->add_field('customfieldid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('operator', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); - $table->add_field('value', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - - // Adding keys to table course_modules_avail_fields - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id')); - - // Conditionally launch create table for course_modules_avail_fields - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.04); - } - - if ($oldversion < 2012070600.05) { - // Define table course_sections_avail_fields to be created - $table = new xmldb_table('course_sections_avail_fields'); - - // Adding fields to table course_sections_avail_fields - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('coursesectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('userfield', XMLDB_TYPE_CHAR, '50', null, null, null, null); - $table->add_field('customfieldid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('operator', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); - $table->add_field('value', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - - // Adding keys to table course_sections_avail_fields - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('coursesectionid', XMLDB_KEY_FOREIGN, array('coursesectionid'), 'course_sections', array('id')); - - // Conditionally launch create table for course_sections_avail_fields - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.05); - } - - if ($oldversion < 2012070600.06) { - - // Drop "deleted" fields - $table = new xmldb_table('course_completions'); - $field = new xmldb_field('timenotified'); - $field = new xmldb_field('deleted'); - - // Conditionally launch drop field deleted from course_completions - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('timenotified'); - // Conditionally launch drop field timenotified from course_completions - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.06); - } - - if ($oldversion < 2012070600.07) { - $table = new xmldb_table('course_completion_crit_compl'); - $field = new xmldb_field('deleted'); - - // Conditionally launch drop field deleted from course_completion_crit_compl - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.07); - } - - if ($oldversion < 2012070600.08) { - - // Drop unused table "course_completion_notify" - $table = new xmldb_table('course_completion_notify'); - - // Conditionally launch drop table course_completion_notify - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.08); - } - - if ($oldversion < 2012070600.09) { - - // Define index path (not unique) to be added to context - $table = new xmldb_table('context'); - $index = new xmldb_index('path', XMLDB_INDEX_NOTUNIQUE, array('path'), array('varchar_pattern_ops')); - - // Recreate index with new pattern hint - if ($DB->get_dbfamily() === 'postgres') { - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.09); - } - - if ($oldversion < 2012070600.10) { - - // Define index name (unique) to be dropped form role - $table = new xmldb_table('role'); - $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); - - // Conditionally launch drop index name - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.10); - } - - if ($oldversion < 2012070600.11) { - - // Define index component-itemid-userid (not unique) to be added to role_assignments - $table = new xmldb_table('role_assignments'); - $index = new xmldb_index('component-itemid-userid', XMLDB_INDEX_NOTUNIQUE, array('component', 'itemid', 'userid')); - - // Conditionally launch add index component-itemid-userid - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012070600.11); - } - - if ($oldversion < 2012071900.01) { - // Cleanup after simpeltests tool - capabilities_cleanup('tool_unittest'); - unset_all_config_for_plugin('tool_unittest'); - - upgrade_main_savepoint(true, 2012071900.01); - } - - if ($oldversion < 2012072400.00) { - // Remove obsolete xhtml strict setting - use THEME->doctype in theme config if necessary, - // see theme_config->doctype in lib/outputlib.php for more details. - unset_config('xmlstrictheaders'); - upgrade_main_savepoint(true, 2012072400.00); - } - - if ($oldversion < 2012072401.00) { - - // Saves orphaned questions from the Dark Side - upgrade_save_orphaned_questions(); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012072401.00); - } - - if ($oldversion < 2012072600.01) { - // Handle events with empty eventtype //MDL-32827 - - $DB->set_field('event', 'eventtype', 'site', array('eventtype' => '', 'courseid' => $SITE->id)); - $DB->set_field_select('event', 'eventtype', 'due', "eventtype = '' AND courseid != 0 AND groupid = 0 AND (modulename = 'assignment' OR modulename = 'assign')"); - $DB->set_field_select('event', 'eventtype', 'course', "eventtype = '' AND courseid != 0 AND groupid = 0"); - $DB->set_field_select('event', 'eventtype', 'group', "eventtype = '' AND groupid != 0"); - $DB->set_field_select('event', 'eventtype', 'user', "eventtype = '' AND userid != 0"); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012072600.01); - } - - if ($oldversion < 2012080200.02) { - // Drop obsolete question upgrade field that should have been added to the install.xml. - $table = new xmldb_table('question'); - $field = new xmldb_field('oldquestiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); - - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - upgrade_main_savepoint(true, 2012080200.02); - } - - if ($oldversion < 2012081400.01) { - // Move the ability to disable blogs to its own setting MDL-25012. - - if (isset($CFG->bloglevel)) { - // Only change settings if existing setting was set. - if (empty($CFG->bloglevel)) { - set_config('enableblogs', 0); - // Now set the bloglevel to a valid setting as the disabled setting has been removed. - // This prevents confusing results when users enable the blog system in future. - set_config('bloglevel', BLOG_USER_LEVEL); - } else { - set_config('enableblogs', 1); - } - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012081400.01); - } - - if ($oldversion < 2012081600.01) { - // Delete removed setting - Google Maps API V2 will not work in 2013. - unset_config('googlemapkey'); - upgrade_main_savepoint(true, 2012081600.01); - } - - if ($oldversion < 2012082300.01) { - // Add more custom enrol fields. - $table = new xmldb_table('enrol'); - $field = new xmldb_field('customint5', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint4'); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('customint6', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint5'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('customint7', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint6'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('customint8', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint7'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('customchar3', XMLDB_TYPE_CHAR, '1333', null, null, null, null, 'customchar2'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('customtext3', XMLDB_TYPE_TEXT, null, null, null, null, null, 'customtext2'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('customtext4', XMLDB_TYPE_TEXT, null, null, null, null, null, 'customtext3'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012082300.01); - } - - if ($oldversion < 2012082300.02) { - // Define field component to be added to groups_members - $table = new xmldb_table('groups_members'); - $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'timeadded'); - - // Conditionally launch add field component - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field itemid to be added to groups_members - $field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'component'); - - // Conditionally launch add field itemid - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012082300.02); - } - - if ($oldversion < 2012090500.00) { - $subquery = 'SELECT b.id FROM {blog_external} b where b.id = ' . $DB->sql_cast_char2int('{post}.content', true); - $sql = 'DELETE FROM {post} - WHERE {post}.module = \'blog_external\' - AND NOT EXISTS (' . $subquery . ') - AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false); - $DB->execute($sql); - upgrade_main_savepoint(true, 2012090500.00); - } - - if ($oldversion < 2012090700.01) { - // Add a category field in the course_request table - $table = new xmldb_table('course_request'); - $field = new xmldb_field('category', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'summaryformat'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012090700.01); - } - - if ($oldversion < 2012091700.00) { - - // Dropping screenreader field from user. - $table = new xmldb_table('user'); - $field = new xmldb_field('screenreader'); - - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012091700.00); - } - - if ($oldversion < 2012092100.01) { - // Some folders still have a sortorder set, which is used for main files but is not - // supported by the folder resource. We reset the value here. - $sql = 'UPDATE {files} SET sortorder = ? WHERE component = ? AND filearea = ? AND sortorder <> ?'; - $DB->execute($sql, array(0, 'mod_folder', 'content', 0)); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012092100.01); - } - - if ($oldversion < 2012092600.00) { - // Define index idname (unique) to be added to tag - $table = new xmldb_table('tag'); - $index = new xmldb_index('idname', XMLDB_INDEX_UNIQUE, array('id', 'name')); - - // Conditionally launch add index idname - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012092600.00); - } - - if ($oldversion < 2012101500.01) { - // Find all orphaned blog associations that might exist. - $sql = "SELECT ba.id - FROM {blog_association} ba - LEFT JOIN {post} p - ON p.id = ba.blogid - WHERE p.id IS NULL"; - $orphanedrecordids = $DB->get_records_sql($sql); - // Now delete these associations. - foreach ($orphanedrecordids as $orphanedrecord) { - $DB->delete_records('blog_association', array('id' => $orphanedrecord->id)); - } - - upgrade_main_savepoint(true, 2012101500.01); - } - - if ($oldversion < 2012101800.02) { - // Renaming backups using previous file naming convention. - upgrade_rename_old_backup_files_using_shortname(); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012101800.02); - } - - if ($oldversion < 2012103001.00) { - // create new event_subscriptions table - $table = new xmldb_table('event_subscriptions'); - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('url', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('pollinterval', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('lastupdated', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - // Main savepoint reached - upgrade_main_savepoint(true, 2012103001.00); - } - - if ($oldversion < 2012103002.00) { - // Add subscription field to the event table - $table = new xmldb_table('event'); - $field = new xmldb_field('subscriptionid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'timemodified'); - - // Conditionally launch add field subscriptionid - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_main_savepoint(true, 2012103002.00); - } - - if ($oldversion < 2012103003.00) { - // Fix uuid field in event table to match RFC-2445 UID property. - $table = new xmldb_table('event'); - $field = new xmldb_field('uuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'visible'); - // The column already exists, so make sure there are no nulls (crazy mysql). - $DB->set_field_select('event', 'uuid', '', "uuid IS NULL"); - // Changing precision of field uuid on table event to (255). - $dbman->change_field_precision($table, $field); - // Main savepoint reached - upgrade_main_savepoint(true, 2012103003.00); - } - - if ($oldversion < 2012110200.00) { - - // Define table course_format_options to be created - $table = new xmldb_table('course_format_options'); - - // Adding fields to table course_format_options - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('format', XMLDB_TYPE_CHAR, '21', null, XMLDB_NOTNULL, null, null); - $table->add_field('sectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'format'); - $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); - $table->add_field('value', XMLDB_TYPE_TEXT, null, null, null, null, null); - - // Adding keys to table course_format_options - $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 course_format_options - $table->add_index('formatoption', XMLDB_INDEX_UNIQUE, array('courseid', 'format', 'sectionid', 'name')); - - // Conditionally launch create table for course_format_options - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Changing type of field format on table course to char with length 21 - $table = new xmldb_table('course'); - $field = new xmldb_field('format', XMLDB_TYPE_CHAR, '21', null, XMLDB_NOTNULL, null, 'topics', 'summaryformat'); - - // Launch change of type for field format - $dbman->change_field_type($table, $field); - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012110200.00); - } - - if ($oldversion < 2012110201.00) { - - // Copy fields 'coursedisplay', 'numsections', 'hiddensections' from table {course} - // to table {course_format_options} as the additional format options - $fields = array(); - $table = new xmldb_table('course'); - foreach (array('coursedisplay', 'numsections', 'hiddensections') as $fieldname) { - // first check that fields still exist - $field = new xmldb_field($fieldname); - if ($dbman->field_exists($table, $field)) { - $fields[] = $fieldname; - } - } - - if (!empty($fields)) { - $transaction = $DB->start_delegated_transaction(); - $rs = $DB->get_recordset_sql('SELECT id, format, '. join(',', $fields).' - FROM {course} - WHERE format <> ? AND format <> ?', - array('scorm', 'social')); - // (do not copy fields from scrom and social formats, we already know that they are not used) - foreach ($rs as $rec) { - foreach ($fields as $field) { - try { - $DB->insert_record('course_format_options', - array( - 'courseid' => $rec->id, - 'format' => $rec->format, - 'sectionid' => 0, - 'name' => $field, - 'value' => $rec->$field - )); - } catch (dml_exception $e) { - // index 'courseid,format,sectionid,name' violation - // continue; the entry in course_format_options already exists, use it - } - } - } - $rs->close(); - $transaction->allow_commit(); - - // Drop fields from table course - foreach ($fields as $fieldname) { - $field = new xmldb_field($fieldname); - $dbman->drop_field($table, $field); - } - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Main savepoint reached - upgrade_main_savepoint(true, 2012110201.00); - } - - if ($oldversion < 2012110700.01) { - - // Define field caller_component to be added to portfolio_log. - $table = new xmldb_table('portfolio_log'); - $field = new xmldb_field('caller_component', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'caller_file'); - - // Conditionally launch add field caller_component. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012110700.01); - } - - if ($oldversion < 2012111200.00) { - - // Define table temp_enroled_template to be created - $table = new xmldb_table('temp_enroled_template'); - - // Adding fields to table temp_enroled_template - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - - // Adding keys to table temp_enroled_template - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Adding indexes to table temp_enroled_template - $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); - $table->add_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid')); - $table->add_index('roleid', XMLDB_INDEX_NOTUNIQUE, array('roleid')); - - // Conditionally launch create table for temp_enroled_template - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table temp_log_template to be created - $table = new xmldb_table('temp_log_template'); - - // Adding fields to table temp_log_template - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('action', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); - - // Adding keys to table temp_log_template - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Adding indexes to table temp_log_template - $table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action')); - $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); - $table->add_index('user', XMLDB_INDEX_NOTUNIQUE, array('userid')); - $table->add_index('usercourseaction', XMLDB_INDEX_NOTUNIQUE, array('userid', 'course', 'action')); - - // Conditionally launch create table for temp_log_template - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012111200.00); - } - - if ($oldversion < 2012111200.01) { - // Force the rebuild of the cache of every courses, some cached information could contain wrong icon references. - $DB->execute('UPDATE {course} set modinfo = ?, sectioncache = ?', array(null, null)); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012111200.01); - } - - if ($oldversion < 2012111601.01) { - // Clea up after old shared memory caching support. - unset_config('cachetype'); - unset_config('rcache'); - unset_config('rcachettl'); - unset_config('intcachemax'); - unset_config('memcachedhosts'); - unset_config('memcachedpconn'); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012111601.01); - } - - if ($oldversion < 2012112100.00) { - - // Define field eventtype to be added to event_subscriptions. - $table = new xmldb_table('event_subscriptions'); - $field = new xmldb_field('eventtype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'userid'); - - // Conditionally launch add field eventtype. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012112100.00); - } - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012120300.01) { - // Make sure site-course has format='site' //MDL-36840 - - if ($SITE->format !== 'site') { - $DB->set_field('course', 'format', 'site', array('id' => $SITE->id)); - $SITE->format = 'site'; - $COURSE->format = 'site'; - } - - // Main savepoint reached - upgrade_main_savepoint(true, 2012120300.01); - } - - if ($oldversion < 2012120300.04) { - // Remove "_utf8" suffix from all langs in course table. - $langs = $DB->get_records_sql("SELECT DISTINCT lang FROM {course} WHERE lang LIKE ?", array('%_utf8')); - - foreach ($langs as $lang=>$unused) { - $newlang = str_replace('_utf8', '', $lang); - $sql = "UPDATE {course} SET lang = :newlang WHERE lang = :lang"; - $DB->execute($sql, array('newlang'=>$newlang, 'lang'=>$lang)); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012120300.04); - } - - if ($oldversion < 2012123000.00) { - // Purge removed module filters and all their settings. - - $tables = array('filter_active', 'filter_config'); - foreach ($tables as $table) { - $DB->delete_records_select($table, "filter LIKE 'mod/%'"); - $filters = $DB->get_records_sql("SELECT DISTINCT filter FROM {{$table}} WHERE filter LIKE 'filter/%'"); - foreach ($filters as $filter) { - $DB->set_field($table, 'filter', substr($filter->filter, 7), array('filter'=>$filter->filter)); - } - } - - $configs = array('stringfilters', 'filterall'); - foreach ($configs as $config) { - if ($filters = get_config(null, $config)) { - $filters = explode(',', $filters); - $newfilters = array(); - foreach($filters as $filter) { - if (strpos($filter, '/') === false) { - $newfilters[] = $filter; - } else if (strpos($filter, 'filter/') === 0) { - $newfilters[] = substr($filter, 7); - } - } - $filters = implode(',', $newfilters); - set_config($config, $filters); - } - } - - unset($tables); - unset($table); - unset($configs); - unset($newfilters); - unset($filters); - unset($filter); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2012123000.00); - } - - if ($oldversion < 2013021100.01) { - // Make sure there are no bogus nulls in old MySQL tables. - $DB->set_field_select('user', 'password', '', "password IS NULL"); - - // Changing precision of field password on table user to (255). - $table = new xmldb_table('user'); - $field = new xmldb_field('password', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'username'); - - // Launch change of precision for field password. - $dbman->change_field_precision($table, $field); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013021100.01); - } - - if ($oldversion < 2013021800.00) { - // Add the site identifier to the cache config's file. - $siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier')); - cache_helper::update_site_identifier($siteidentifier); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013021800.00); - } - - if ($oldversion < 2013021801.00) { - // Fixing possible wrong MIME types for SMART Notebook files. - $extensions = array('%.gallery', '%.galleryitem', '%.gallerycollection', '%.nbk', '%.notebook', '%.xbk'); - $select = $DB->sql_like('filename', '?', false); - foreach ($extensions as $extension) { - $DB->set_field_select( - 'files', - 'mimetype', - 'application/x-smarttech-notebook', - $select, - array($extension) - ); - } - upgrade_main_savepoint(true, 2013021801.00); - } - - if ($oldversion < 2013021801.01) { - // This upgrade step is re-written under MDL-38228 (see below). - /* - // Retrieve the list of course_sections as a recordset to save memory - $coursesections = $DB->get_recordset('course_sections', null, 'course, id', 'id, course, sequence'); - foreach ($coursesections as $coursesection) { - // Retrieve all of the actual modules in this course and section combination to reduce DB calls - $actualsectionmodules = $DB->get_records('course_modules', - array('course' => $coursesection->course, 'section' => $coursesection->id), '', 'id, section'); - - // Break out the current sequence so that we can compare it - $currentsequence = explode(',', $coursesection->sequence); - $newsequence = array(); - - // Check each of the modules in the current sequence - foreach ($currentsequence as $module) { - if (isset($actualsectionmodules[$module])) { - $newsequence[] = $module; - // We unset the actualsectionmodules so that we don't get duplicates and that we can add orphaned - // modules later - unset($actualsectionmodules[$module]); - } - } - - // Append any modules which have somehow been orphaned - foreach ($actualsectionmodules as $module) { - $newsequence[] = $module->id; - } - - // Piece it all back together - $sequence = implode(',', $newsequence); - - // Only update if there have been changes - if ($sequence !== $coursesection->sequence) { - $coursesection->sequence = $sequence; - $DB->update_record('course_sections', $coursesection); - - // And clear the sectioncache and modinfo cache - they'll be regenerated on next use - $course = new stdClass(); - $course->id = $coursesection->course; - $course->sectioncache = null; - $course->modinfo = null; - $DB->update_record('course', $course); - } - } - $coursesections->close(); - */ - // Main savepoint reached. - upgrade_main_savepoint(true, 2013021801.01); - } - - if ($oldversion < 2013021902.00) { - // ISO country change: Netherlands Antilles is split into BQ, CW & SX - // http://www.iso.org/iso/iso_3166-1_newsletter_vi-8_split_of_the_dutch_antilles_final-en.pdf - $sql = "UPDATE {user} SET country = '' WHERE country = ?"; - $DB->execute($sql, array('AN')); - - upgrade_main_savepoint(true, 2013021902.00); - } - - if ($oldversion < 2013022600.00) { - // Delete entries regarding invalid 'interests' option which breaks course. - $DB->delete_records('course_sections_avail_fields', array('userfield' => 'interests')); - $DB->delete_records('course_modules_avail_fields', array('userfield' => 'interests')); - // Clear course cache (will be rebuilt on first visit) in case of changes to these. - $DB->execute('UPDATE {course} set modinfo = ?, sectioncache = ?', array(null, null)); - - upgrade_main_savepoint(true, 2013022600.00); - } - - // Add index to field "timemodified" for grade_grades_history table. - if ($oldversion < 2013030400.00) { - $table = new xmldb_table('grade_grades_history'); - $field = new xmldb_field('timemodified'); - - if ($dbman->field_exists($table, $field)) { - $index = new xmldb_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013030400.00); - } - - if ($oldversion < 2013030400.02) { - // Cleanup qformat blackboard settings. - unset_all_config_for_plugin('qformat_blackboard'); - - upgrade_main_savepoint(true, 2013030400.02); - } - - // This is checking to see if the site has been running a specific version with a bug in it - // because this upgrade step is slow and is only needed if the site has been running with the affected versions. - if ($oldversion >= 2012062504.08 && $oldversion < 2012062504.13) { - // This upgrade step is re-written under MDL-38228 (see below). - - /* - // Retrieve the list of course_sections as a recordset to save memory. - // This is to fix a regression caused by MDL-37939. - // In this case the upgrade step is fixing records where: - // The data in course_sections.sequence contains the correct module id - // The section field for on the course modules table may have been updated to point to the incorrect id. - - // This query is looking for sections where the sequence is not in sync with the course_modules table. - // The syntax for the like query is looking for a value in a comma separated list. - // It adds a comma to either site of the list and then searches for LIKE '%,id,%'. - $sequenceconcat = $DB->sql_concat("','", 's.sequence', "','"); - $moduleconcat = $DB->sql_concat("'%,'", 'cm.id', "',%'"); - $sql = 'SELECT s2.id, s2.course, s2.sequence - FROM {course_sections} s2 - JOIN( - SELECT DISTINCT s.id - FROM - {course_modules} cm - JOIN {course_sections} s - ON - cm.course = s.course - WHERE cm.section != s.id AND ' . $sequenceconcat . ' LIKE ' . $moduleconcat . ' - ) d - ON s2.id = d.id'; - $coursesections = $DB->get_recordset_sql($sql); - - foreach ($coursesections as $coursesection) { - // Retrieve all of the actual modules in this course and section combination to reduce DB calls. - $actualsectionmodules = $DB->get_records('course_modules', - array('course' => $coursesection->course, 'section' => $coursesection->id), '', 'id, section'); - - // Break out the current sequence so that we can compare it. - $currentsequence = explode(',', $coursesection->sequence); - $orphanlist = array(); - - // Check each of the modules in the current sequence. - foreach ($currentsequence as $cmid) { - if (!empty($cmid) && !isset($actualsectionmodules[$cmid])) { - $orphanlist[] = $cmid; - } - } - - if (!empty($orphanlist)) { - list($sql, $params) = $DB->get_in_or_equal($orphanlist, SQL_PARAMS_NAMED); - $sql = "id $sql"; - - $DB->set_field_select('course_modules', 'section', $coursesection->id, $sql, $params); - - // And clear the sectioncache and modinfo cache - they'll be regenerated on next use. - $course = new stdClass(); - $course->id = $coursesection->course; - $course->sectioncache = null; - $course->modinfo = null; - $DB->update_record('course', $course); - } - } - $coursesections->close(); - - // No savepoint needed for this change. - */ - } - - if ($oldversion < 2013032200.01) { - // GD is now always available - set_config('gdversion', 2); - - upgrade_main_savepoint(true, 2013032200.01); - } - - if ($oldversion < 2013032600.03) { - // Fixing possible wrong MIME type for MIME HTML (MHTML) files. - $extensions = array('%.mht', '%.mhtml'); - $select = $DB->sql_like('filename', '?', false); - foreach ($extensions as $extension) { - $DB->set_field_select( - 'files', - 'mimetype', - 'message/rfc822', - $select, - array($extension) - ); - } - upgrade_main_savepoint(true, 2013032600.03); - } - - if ($oldversion < 2013032600.04) { - // MDL-31983 broke the quiz version number. Fix it. - $DB->set_field('modules', 'version', '2013021500', - array('name' => 'quiz', 'version' => '2013310100')); - upgrade_main_savepoint(true, 2013032600.04); - } - - if ($oldversion < 2013040200.00) { - // Add openbadges tables. - - // Define table 'badge' to be created. - $table = new xmldb_table('badge'); - - // Adding fields to table 'badge'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); - $table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name'); - $table->add_field('image', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'description'); - $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'image'); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timecreated'); - $table->add_field('usercreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'timemodified'); - $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'usercreated'); - $table->add_field('issuername', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'usermodified'); - $table->add_field('issuerurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'issuername'); - $table->add_field('issuercontact', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'issuerurl'); - $table->add_field('expiredate', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'issuercontact'); - $table->add_field('expireperiod', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'expiredate'); - $table->add_field('type', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'expireperiod'); - $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'type'); - $table->add_field('message', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'courseid'); - $table->add_field('messagesubject', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'message'); - $table->add_field('attachment', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'messagesubject'); - $table->add_field('notification', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'attachment'); - $table->add_field('status', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'notification'); - $table->add_field('nextcron', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'status'); - - // Adding keys to table 'badge'. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->add_key('fk_usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); - $table->add_key('fk_usercreated', XMLDB_KEY_FOREIGN, array('usercreated'), 'user', array('id')); - - // Adding indexes to table 'badge'. - $table->add_index('type', XMLDB_INDEX_NOTUNIQUE, array('type')); - - // Conditionally launch create table for 'badge'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table 'badge_criteria' to be created. - $table = new xmldb_table('badge_criteria'); - - // Adding fields to table 'badge_criteria'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - $table->add_field('criteriatype', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'badgeid'); - $table->add_field('method', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'criteriatype'); - - // Adding keys to table 'badge_criteria'. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); - - // Adding indexes to table 'badge_criteria'. - $table->add_index('criteriatype', XMLDB_INDEX_NOTUNIQUE, array('criteriatype')); - $table->add_index('badgecriteriatype', XMLDB_INDEX_UNIQUE, array('badgeid', 'criteriatype')); - - // Conditionally launch create table for 'badge_criteria'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table 'badge_criteria_param' to be created. - $table = new xmldb_table('badge_criteria_param'); - - // Adding fields to table 'badge_criteria_param'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('critid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); - $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'critid'); - $table->add_field('value', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'name'); - - // Adding keys to table 'badge_criteria_param'. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_critid', XMLDB_KEY_FOREIGN, array('critid'), 'badge_criteria', array('id')); - - // Conditionally launch create table for 'badge_criteria_param'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table 'badge_issued' to be created. - $table = new xmldb_table('badge_issued'); - - // Adding fields to table 'badge_issued'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'badgeid'); - $table->add_field('uniquehash', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'userid'); - $table->add_field('dateissued', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'uniquehash'); - $table->add_field('dateexpire', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'dateissued'); - $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'dateexpire'); - $table->add_field('issuernotified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'visible'); - - // Adding keys to table 'badge_issued'. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); - $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - - $table->add_index('badgeuser', XMLDB_INDEX_UNIQUE, array('badgeid', 'userid')); - - // Conditionally launch create table for 'badge_issued'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table 'badge_criteria_met' to be created. - $table = new xmldb_table('badge_criteria_met'); - - // Adding fields to table 'badge_criteria_met'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('issuedid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'id'); - $table->add_field('critid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuedid'); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'critid'); - $table->add_field('datemet', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'userid'); - - // Adding keys to table 'badge_criteria_met' - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_critid', XMLDB_KEY_FOREIGN, array('critid'), 'badge_criteria', array('id')); - $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - $table->add_key('fk_issuedid', XMLDB_KEY_FOREIGN, array('issuedid'), 'badge_issued', array('id')); - - // Conditionally launch create table for 'badge_criteria_met'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table 'badge_manual_award' to be created. - $table = new xmldb_table('badge_manual_award'); - - // Adding fields to table 'badge_manual_award'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); - $table->add_field('recipientid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'badgeid'); - $table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'recipientid'); - $table->add_field('issuerrole', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuerid'); - $table->add_field('datemet', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuerrole'); - - // Adding keys to table 'badge_manual_award'. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); - $table->add_key('fk_recipientid', XMLDB_KEY_FOREIGN, array('recipientid'), 'user', array('id')); - $table->add_key('fk_issuerid', XMLDB_KEY_FOREIGN, array('issuerid'), 'user', array('id')); - $table->add_key('fk_issuerrole', XMLDB_KEY_FOREIGN, array('issuerrole'), 'role', array('id')); - - // Conditionally launch create table for 'badge_manual_award'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table 'badge_backpack' to be created. - $table = new xmldb_table('badge_backpack'); - - // Adding fields to table 'badge_backpack'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - $table->add_field('email', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'userid'); - $table->add_field('backpackurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'email'); - $table->add_field('backpackuid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackurl'); - $table->add_field('backpackgid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackuid'); - $table->add_field('autosync', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'backpackgid'); - $table->add_field('password', XMLDB_TYPE_CHAR, '50', null, null, null, null, 'autosync'); - - // Adding keys to table 'badge_backpack'. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - - // Conditionally launch create table for 'badge_backpack'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013040200.00); - } - - if ($oldversion < 2013040201.00) { - // Convert name field in event table to text type as RFC-2445 doesn't have any limitation on it. - $table = new xmldb_table('event'); - $field = new xmldb_field('name', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); - if ($dbman->field_exists($table, $field)) { - $dbman->change_field_type($table, $field); - } - // Main savepoint reached. - upgrade_main_savepoint(true, 2013040201.00); - } - - if ($oldversion < 2013040300.01) { - - // Define field completionstartonenrol to be dropped from course. - $table = new xmldb_table('course'); - $field = new xmldb_field('completionstartonenrol'); - - // Conditionally launch drop field completionstartonenrol. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013040300.01); - } - - if ($oldversion < 2013041200.00) { - // MDL-29877 Some bad restores created grade items with no category information. - $sql = "UPDATE {grade_items} - SET categoryid = courseid - WHERE itemtype <> 'course' and itemtype <> 'category' - AND categoryid IS NULL"; - $DB->execute($sql); - upgrade_main_savepoint(true, 2013041200.00); - } - - if ($oldversion < 2013041600.00) { - // Copy constants from /course/lib.php instead of including the whole library: - $c = array( 'FRONTPAGENEWS' => 0, - 'FRONTPAGECOURSELIST' => 1, - 'FRONTPAGECATEGORYNAMES' => 2, - 'FRONTPAGETOPICONLY' => 3, - 'FRONTPAGECATEGORYCOMBO' => 4, - 'FRONTPAGEENROLLEDCOURSELIST' => 5, - 'FRONTPAGEALLCOURSELIST' => 6, - 'FRONTPAGECOURSESEARCH' => 7); - // Update frontpage settings $CFG->frontpage and $CFG->frontpageloggedin. In 2.4 there was too much of hidden logic about them. - // This script tries to make sure that with the new (more user-friendly) frontpage settings the frontpage looks as similar as possible to what it was before upgrade. - $ncourses = $DB->count_records('course'); - foreach (array('frontpage', 'frontpageloggedin') as $configkey) { - if ($frontpage = explode(',', $CFG->{$configkey})) { - $newfrontpage = array(); - foreach ($frontpage as $v) { - switch ($v) { - case $c['FRONTPAGENEWS']: - // Not related to course listings, leave as it is. - $newfrontpage[] = $c['FRONTPAGENEWS']; - break; - case $c['FRONTPAGECOURSELIST']: - if ($configkey === 'frontpageloggedin' && empty($CFG->disablemycourses)) { - // In 2.4 unless prohibited in config, the "list of courses" was considered "list of enrolled courses" plus course search box. - $newfrontpage[] = $c['FRONTPAGEENROLLEDCOURSELIST']; - } else if ($ncourses <= 200) { - // Still list of courses was only displayed in there were less than 200 courses in system. Otherwise - search box only. - $newfrontpage[] = $c['FRONTPAGEALLCOURSELIST']; - break; // skip adding search box - } - if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { - $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; - } - break; - case $c['FRONTPAGECATEGORYNAMES']: - // In 2.4 search box was displayed automatically after categories list. In 2.5 it is displayed as a separate setting. - $newfrontpage[] = $c['FRONTPAGECATEGORYNAMES']; - if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { - $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; - } - break; - case $c['FRONTPAGECATEGORYCOMBO']: - $maxcourses = empty($CFG->numcoursesincombo) ? 500 : $CFG->numcoursesincombo; - // In 2.4 combo list was not displayed if there are more than $CFG->numcoursesincombo courses in the system. - if ($ncourses < $maxcourses) { - $newfrontpage[] = $c['FRONTPAGECATEGORYCOMBO']; - } - if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { - $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; - } - break; - } - } - set_config($configkey, join(',', $newfrontpage)); - } - } - // $CFG->numcoursesincombo no longer affects whether the combo list is displayed. Setting is deprecated. - unset_config('numcoursesincombo'); - - upgrade_main_savepoint(true, 2013041600.00); - } - - if ($oldversion < 2013041601.00) { - // Create a new 'badge_external' table first. - // Define table 'badge_external' to be created. - $table = new xmldb_table('badge_external'); - - // Adding fields to table 'badge_external'. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('backpackid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); - $table->add_field('collectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackid'); - - // Adding keys to table 'badge_external'. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_backpackid', XMLDB_KEY_FOREIGN, array('backpackid'), 'badge_backpack', array('id')); - - // Conditionally launch create table for 'badge_external'. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Perform user data migration. - $usercollections = $DB->get_records('badge_backpack'); - foreach ($usercollections as $usercollection) { - $collection = new stdClass(); - $collection->backpackid = $usercollection->id; - $collection->collectionid = $usercollection->backpackgid; - $DB->insert_record('badge_external', $collection); - } - - // Finally, drop the column. - // Define field backpackgid to be dropped from 'badge_backpack'. - $table = new xmldb_table('badge_backpack'); - $field = new xmldb_field('backpackgid'); - - // Conditionally launch drop field backpackgid. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013041601.00); - } - - if ($oldversion < 2013041601.01) { - // Changing the default of field descriptionformat on table user to 1. - $table = new xmldb_table('user'); - $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1', 'description'); - - // Launch change of default for field descriptionformat. - $dbman->change_field_default($table, $field); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013041601.01); - } - - if ($oldversion < 2013041900.00) { - require_once($CFG->dirroot . '/cache/locallib.php'); - // The features bin needs updating. - cache_config_writer::update_default_config_stores(); - // Main savepoint reached. - upgrade_main_savepoint(true, 2013041900.00); - } - - if ($oldversion < 2013042300.00) { - // Adding index to unreadmessageid field of message_working table (MDL-34933) - $table = new xmldb_table('message_working'); - $index = new xmldb_index('unreadmessageid_idx', XMLDB_INDEX_NOTUNIQUE, array('unreadmessageid')); - - // Conditionally launch add index unreadmessageid - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013042300.00); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013051400.01) { - // Fix incorrect cc-nc url. Unfortunately the license 'plugins' do - // not give a mechanism to do this. - - $sql = "UPDATE {license} - SET source = :url, version = :newversion - WHERE shortname = :shortname AND version = :oldversion"; - - $params = array( - 'url' => 'http://creativecommons.org/licenses/by-nc/3.0/', - 'shortname' => 'cc-nc', - 'newversion' => '2013051500', - 'oldversion' => '2010033100' - ); - - $DB->execute($sql, $params); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013051400.01); - } - - if ($oldversion < 2013061400.01) { - // Clean up old tokens which haven't been deleted. - $DB->execute("DELETE FROM {user_private_key} WHERE NOT EXISTS - (SELECT 'x' FROM {user} WHERE deleted = 0 AND id = userid)"); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013061400.01); - } - - if ($oldversion < 2013061700.00) { - // MDL-40103: Remove unused template tables from the database. - // These are now created inline with xmldb_table. - - $tablestocleanup = array('temp_enroled_template','temp_log_template','backup_files_template','backup_ids_template'); - $dbman = $DB->get_manager(); - - foreach ($tablestocleanup as $table) { - $xmltable = new xmldb_table($table); - if ($dbman->table_exists($xmltable)) { - $dbman->drop_table($xmltable); - } - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013061700.00); - } - - if ($oldversion < 2013070800.00) { - - // Remove orphan repository instances. - if ($DB->get_dbfamily() === 'mysql') { - $sql = "DELETE {repository_instances} FROM {repository_instances} - LEFT JOIN {context} ON {context}.id = {repository_instances}.contextid - WHERE {context}.id IS NULL"; - } else { - $sql = "DELETE FROM {repository_instances} - WHERE NOT EXISTS ( - SELECT 'x' FROM {context} - WHERE {context}.id = {repository_instances}.contextid)"; - } - $DB->execute($sql); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013070800.00); - } - - if ($oldversion < 2013070800.01) { - - // Define field lastnamephonetic to be added to user. - $table = new xmldb_table('user'); - $field = new xmldb_field('lastnamephonetic', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'imagealt'); - $index = new xmldb_index('lastnamephonetic', XMLDB_INDEX_NOTUNIQUE, array('lastnamephonetic')); - - // Conditionally launch add field lastnamephonetic. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - $dbman->add_index($table, $index); - } - - // Define field firstnamephonetic to be added to user. - $table = new xmldb_table('user'); - $field = new xmldb_field('firstnamephonetic', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'lastnamephonetic'); - $index = new xmldb_index('firstnamephonetic', XMLDB_INDEX_NOTUNIQUE, array('firstnamephonetic')); - - // Conditionally launch add field firstnamephonetic. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - $dbman->add_index($table, $index); - } - - // Define field alternatename to be added to user. - $table = new xmldb_table('user'); - $field = new xmldb_field('middlename', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'firstnamephonetic'); - $index = new xmldb_index('middlename', XMLDB_INDEX_NOTUNIQUE, array('middlename')); - - // Conditionally launch add field firstnamephonetic. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - $dbman->add_index($table, $index); - } - - // Define field alternatename to be added to user. - $table = new xmldb_table('user'); - $field = new xmldb_field('alternatename', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'middlename'); - $index = new xmldb_index('alternatename', XMLDB_INDEX_NOTUNIQUE, array('alternatename')); - - // Conditionally launch add field alternatename. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - $dbman->add_index($table, $index); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013070800.01); - } - if ($oldversion < 2013071500.01) { - // The enrol_authorize plugin has been removed, if there are no records - // and no plugin files then remove the plugin data. - $enrolauthorize = new xmldb_table('enrol_authorize'); - $enrolauthorizerefunds = new xmldb_table('enrol_authorize_refunds'); - - if (!file_exists($CFG->dirroot.'/enrol/authorize/version.php') && - $dbman->table_exists($enrolauthorize) && - $dbman->table_exists($enrolauthorizerefunds)) { - - $enrolauthorizecount = $DB->count_records('enrol_authorize'); - $enrolauthorizerefundcount = $DB->count_records('enrol_authorize_refunds'); - - if (empty($enrolauthorizecount) && empty($enrolauthorizerefundcount)) { - - // Drop the database tables. - $dbman->drop_table($enrolauthorize); - $dbman->drop_table($enrolauthorizerefunds); - - // Drop the message provider and associated data manually. - $DB->delete_records('message_providers', array('component' => 'enrol_authorize')); - $DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("%_provider_enrol_authorize_%")); - $DB->delete_records_select('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_enrol_authorize_%")); - - // Remove capabilities. - capabilities_cleanup('enrol_authorize'); - - // Remove all other associated config. - unset_all_config_for_plugin('enrol_authorize'); - } - } - upgrade_main_savepoint(true, 2013071500.01); - } - - if ($oldversion < 2013071500.02) { - // Define field attachment to be dropped from badge. - $table = new xmldb_table('badge'); - $field = new xmldb_field('image'); - - // Conditionally launch drop field eventtype. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - upgrade_main_savepoint(true, 2013071500.02); - } - - if ($oldversion < 2013072600.01) { - upgrade_mssql_nvarcharmax(); - upgrade_mssql_varbinarymax(); - - upgrade_main_savepoint(true, 2013072600.01); - } - - if ($oldversion < 2013081200.00) { - // Define field uploadfiles to be added to external_services. - $table = new xmldb_table('external_services'); - $field = new xmldb_field('uploadfiles', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'downloadfiles'); - - // Conditionally launch add field uploadfiles. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013081200.00); - } - - if ($oldversion < 2013082300.01) { - // Define the table 'backup_logs' and the field 'message' which we will be changing from a char to a text field. - $table = new xmldb_table('backup_logs'); - $field = new xmldb_field('message', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'loglevel'); - - // Perform the change. - $dbman->change_field_type($table, $field); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013082300.01); - } - - // Convert SCORM course format courses to singleactivity. - if ($oldversion < 2013082700.00) { - // First set relevant singleactivity settings. - $formatoptions = new stdClass(); - $formatoptions->format = 'singleactivity'; - $formatoptions->sectionid = 0; - $formatoptions->name = 'activitytype'; - $formatoptions->value = 'scorm'; - - $courses = $DB->get_recordset('course', array('format' => 'scorm'), 'id'); - foreach ($courses as $course) { - $formatoptions->courseid = $course->id; - $DB->insert_record('course_format_options', $formatoptions); - } - $courses->close(); - - // Now update course format for these courses. - $sql = "UPDATE {course} - SET format = 'singleactivity', modinfo = '', sectioncache = '' - WHERE format = 'scorm'"; - $DB->execute($sql); - upgrade_main_savepoint(true, 2013082700.00); - } - - if ($oldversion < 2013090500.01) { - // Define field calendartype to be added to course. - $table = new xmldb_table('course'); - $field = new xmldb_field('calendartype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null); - - // Conditionally launch add field calendartype. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Define field calendartype to be added to user. - $table = new xmldb_table('user'); - $field = new xmldb_field('calendartype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'gregorian'); - - // Conditionally launch add field calendartype. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013090500.01); - } - - if ($oldversion < 2013091000.02) { - - // Define field cacherev to be added to course. - $table = new xmldb_table('course'); - $field = new xmldb_field('cacherev', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'completionnotify'); - - // Conditionally launch add field cacherev. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013091000.02); - } - - if ($oldversion < 2013091000.03) { - - // Define field modinfo to be dropped from course. - $table = new xmldb_table('course'); - $field = new xmldb_field('modinfo'); - - // Conditionally launch drop field modinfo. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Define field sectioncache to be dropped from course. - $field = new xmldb_field('sectioncache'); - - // Conditionally launch drop field sectioncache. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Since structure of 'course' table has changed we need to re-read $SITE from DB. - $SITE = $DB->get_record('course', array('id' => $SITE->id)); - $COURSE = clone($SITE); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013091000.03); - } - - if ($oldversion < 2013091300.01) { - - $table = new xmldb_table('user'); - - // Changing precision of field institution on table user to (255). - $field = new xmldb_field('institution', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'phone2'); - - // Launch change of precision for field institution. - $dbman->change_field_precision($table, $field); - - // Changing precision of field department on table user to (255). - $field = new xmldb_field('department', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'institution'); - - // Launch change of precision for field department. - $dbman->change_field_precision($table, $field); - - // Changing precision of field address on table user to (255). - $field = new xmldb_field('address', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'department'); - - // Launch change of precision for field address. - $dbman->change_field_precision($table, $field); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013091300.01); - } - - if ($oldversion < 2013092000.01) { - - // Define table question_statistics to be created. - $table = new xmldb_table('question_statistics'); - - // Adding fields to table question_statistics. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('hashcode', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('slot', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('subquestion', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); - $table->add_field('s', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('effectiveweight', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('negcovar', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('discriminationindex', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('discriminativeefficiency', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('sd', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); - $table->add_field('facility', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); - $table->add_field('subquestions', XMLDB_TYPE_TEXT, null, null, null, null, null); - $table->add_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); - $table->add_field('positions', XMLDB_TYPE_TEXT, null, null, null, null, null); - $table->add_field('randomguessscore', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); - - // Adding keys to table question_statistics. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Conditionally launch create table for question_statistics. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table question_response_analysis to be created. - $table = new xmldb_table('question_response_analysis'); - - // Adding fields to table question_response_analysis. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('hashcode', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('subqid', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); - $table->add_field('aid', XMLDB_TYPE_CHAR, '100', null, null, null, null); - $table->add_field('response', XMLDB_TYPE_TEXT, null, null, null, null, null); - $table->add_field('rcount', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('credit', XMLDB_TYPE_NUMBER, '15, 5', null, XMLDB_NOTNULL, null, null); - - // Adding keys to table question_response_analysis. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Conditionally launch create table for question_response_analysis. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013092000.01); - } - - if ($oldversion < 2013092001.01) { - // Force uninstall of deleted tool. - if (!file_exists("$CFG->dirroot/$CFG->admin/tool/bloglevelupgrade")) { - // Remove capabilities. - capabilities_cleanup('tool_bloglevelupgrade'); - // Remove all other associated config. - unset_all_config_for_plugin('tool_bloglevelupgrade'); - } - upgrade_main_savepoint(true, 2013092001.01); - } - - if ($oldversion < 2013092001.02) { - // Define field version to be dropped from modules. - $table = new xmldb_table('modules'); - $field = new xmldb_field('version'); - - // Conditionally launch drop field version. - if ($dbman->field_exists($table, $field)) { - // Migrate all plugin version info to config_plugins table. - $modules = $DB->get_records('modules'); - foreach ($modules as $module) { - set_config('version', $module->version, 'mod_'.$module->name); - } - unset($modules); - - $dbman->drop_field($table, $field); - } - - // Define field version to be dropped from block. - $table = new xmldb_table('block'); - $field = new xmldb_field('version'); - - // Conditionally launch drop field version. - if ($dbman->field_exists($table, $field)) { - $blocks = $DB->get_records('block'); - foreach ($blocks as $block) { - set_config('version', $block->version, 'block_'.$block->name); - } - unset($blocks); - - $dbman->drop_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013092001.02); - } - - if ($oldversion < 2013092700.01) { - - $table = new xmldb_table('files'); - - // Define field referencelastsync to be dropped from files. - $field = new xmldb_field('referencelastsync'); - - // Conditionally launch drop field referencelastsync. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Define field referencelifetime to be dropped from files. - $field = new xmldb_field('referencelifetime'); - - // Conditionally launch drop field referencelifetime. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013092700.01); - } - - if ($oldversion < 2013100400.01) { - // Add user_devices core table. - - // Define field id to be added to user_devices. - $table = new xmldb_table('user_devices'); - - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - $table->add_field('appid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, 'userid'); - $table->add_field('name', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'appid'); - $table->add_field('model', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'name'); - $table->add_field('platform', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'model'); - $table->add_field('version', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'platform'); - $table->add_field('pushid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'version'); - $table->add_field('uuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'pushid'); - $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'uuid'); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'timecreated'); - - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('pushid-userid', XMLDB_KEY_UNIQUE, array('pushid', 'userid')); - $table->add_key('pushid-platform', XMLDB_KEY_UNIQUE, array('pushid', 'platform')); - $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013100400.01); - } - - if ($oldversion < 2013100800.00) { - - // Define field maxfraction to be added to question_attempts. - $table = new xmldb_table('question_attempts'); - $field = new xmldb_field('maxfraction', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '1', 'minfraction'); - - // Conditionally launch add field maxfraction. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013100800.00); - } - - if ($oldversion < 2013100800.01) { - // Create a new 'user_password_resets' table. - $table = new xmldb_table('user_password_resets'); - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null); - $table->add_field('timerequested', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null); - $table->add_field('timererequested', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, null); - $table->add_field('token', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null); - - // Adding keys to table. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - - // Conditionally launch create table. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - upgrade_main_savepoint(true, 2013100800.01); - } - - if ($oldversion < 2013100800.02) { - $sql = "INSERT INTO {user_preferences}(userid, name, value) - SELECT id, 'htmleditor', 'textarea' FROM {user} u where u.htmleditor = 0"; - $DB->execute($sql); - - // Define field htmleditor to be dropped from user - $table = new xmldb_table('user'); - $field = new xmldb_field('htmleditor'); - - // Conditionally launch drop field requested - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - // Main savepoint reached. - upgrade_main_savepoint(true, 2013100800.02); - } - - if ($oldversion < 2013100900.00) { - - // Define field lifetime to be dropped from files_reference. - $table = new xmldb_table('files_reference'); - $field = new xmldb_field('lifetime'); - - // Conditionally launch drop field lifetime. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013100900.00); - } - - if ($oldversion < 2013100901.00) { - // Fixing possible wrong MIME type for Java Network Launch Protocol (JNLP) files. - $select = $DB->sql_like('filename', '?', false); - $DB->set_field_select( - 'files', - 'mimetype', - 'application/x-java-jnlp-file', - $select, - array('%.jnlp') - ); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013100901.00); - } - - if ($oldversion < 2013102100.00) { - // Changing default value for the status of a course backup. - $table = new xmldb_table('backup_courses'); - $field = new xmldb_field('laststatus', XMLDB_TYPE_CHAR, '1', null, XMLDB_NOTNULL, null, '5', 'lastendtime'); - - // Launch change of precision for field value - $dbman->change_field_precision($table, $field); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013102100.00); - } - - if ($oldversion < 2013102201.00) { - $params = array('plugin' => 'editor_atto', 'name' => 'version'); - $attoversion = $DB->get_record('config_plugins', - $params, - 'value', - IGNORE_MISSING); - - if ($attoversion) { - $attoversion = floatval($attoversion->value); - } - // Only these versions that were part of 2.6 beta should be removed. - // Manually installed versions of 2.5 - or later releases for 2.6 installed - // via the plugins DB should not be uninstalled. - if ($attoversion && $attoversion > 2013051500.00 && $attoversion < 2013102201.00) { - // Remove all other associated config. - unset_all_config_for_plugin('editor_atto'); - unset_all_config_for_plugin('atto_bold'); - unset_all_config_for_plugin('atto_clear'); - unset_all_config_for_plugin('atto_html'); - unset_all_config_for_plugin('atto_image'); - unset_all_config_for_plugin('atto_indent'); - unset_all_config_for_plugin('atto_italic'); - unset_all_config_for_plugin('atto_link'); - unset_all_config_for_plugin('atto_media'); - unset_all_config_for_plugin('atto_orderedlist'); - unset_all_config_for_plugin('atto_outdent'); - unset_all_config_for_plugin('atto_strike'); - unset_all_config_for_plugin('atto_title'); - unset_all_config_for_plugin('atto_underline'); - unset_all_config_for_plugin('atto_unlink'); - unset_all_config_for_plugin('atto_unorderedlist'); - - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013102201.00); - } - - if ($oldversion < 2013102500.01) { - // Find all fileareas that have missing root folder entry and add the root folder entry. - if (empty($CFG->filesrootrecordsfixed)) { - upgrade_fix_missing_root_folders(); - // To skip running the same script on the upgrade to the next major release. - set_config('filesrootrecordsfixed', 1); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013102500.01); - } - - if ($oldversion < 2013110500.01) { - // MDL-38228. Corrected course_modules upgrade script instead of 2013021801.01. - - // This upgrade script fixes the mismatches between DB fields course_modules.section - // and course_sections.sequence. It makes sure that each module is included - // in the sequence of at least one section. - // There is also a separate script for admins: admin/cli/fix_course_sortorder.php - - // This script in included in each major version upgrade process so make sure we don't run it twice. - if (empty($CFG->movingmoduleupgradescriptwasrun)) { - upgrade_course_modules_sequences(); - - // To skip running the same script on the upgrade to the next major release. - set_config('movingmoduleupgradescriptwasrun', 1); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013110500.01); - } - - if ($oldversion < 2013110600.01) { - - if (!file_exists($CFG->dirroot . '/theme/mymobile')) { - // Replace the mymobile settings. - $DB->set_field('course', 'theme', 'clean', array('theme' => 'mymobile')); - $DB->set_field('course_categories', 'theme', 'clean', array('theme' => 'mymobile')); - $DB->set_field('user', 'theme', 'clean', array('theme' => 'mymobile')); - $DB->set_field('mnet_host', 'theme', 'clean', array('theme' => 'mymobile')); - - // Replace the theme configs. - if (get_config('core', 'theme') === 'mymobile') { - set_config('theme', 'clean'); - } - if (get_config('core', 'thememobile') === 'mymobile') { - set_config('thememobile', 'clean'); - } - if (get_config('core', 'themelegacy') === 'mymobile') { - set_config('themelegacy', 'clean'); - } - if (get_config('core', 'themetablet') === 'mymobile') { - set_config('themetablet', 'clean'); - } - - // Hacky emulation of plugin uninstallation. - unset_all_config_for_plugin('theme_mymobile'); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013110600.01); - } - - if ($oldversion < 2013110600.02) { - - // If the user is logged in, we ensure that the alternate name fields are present - // in the session. It will not be the case when upgrading from 2.5 downwards. - if (!empty($USER->id)) { - $refreshuser = $DB->get_record('user', array('id' => $USER->id)); - $fields = array('firstnamephonetic', 'lastnamephonetic', 'middlename', 'alternatename', 'firstname', 'lastname'); - foreach ($fields as $field) { - $USER->{$field} = $refreshuser->{$field}; - } - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013110600.02); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2013111800.01) { - - // Delete notes of deleted courses. - $sql = "DELETE FROM {post} - WHERE NOT EXISTS (SELECT {course}.id FROM {course} - WHERE {course}.id = {post}.courseid) - AND {post}.module = ?"; - $DB->execute($sql, array('notes')); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2013111800.01); - } - - if ($oldversion < 2013122400.01) { - // Purge stored passwords from config_log table, ideally this should be in each plugin - // but that would complicate backporting... - $items = array( - 'core/cronremotepassword', 'core/proxypassword', 'core/smtppass', 'core/jabberpassword', - 'enrol_database/dbpass', 'enrol_ldap/bind_pw', 'url/secretphrase'); - foreach ($items as $item) { - list($plugin, $name) = explode('/', $item); - $sqlcomparevalue = $DB->sql_compare_text('value'); - $sqlcompareoldvalue = $DB->sql_compare_text('oldvalue'); - if ($plugin === 'core') { - $sql = "UPDATE {config_log} - SET value = :value - WHERE name = :name AND plugin IS NULL AND $sqlcomparevalue <> :empty"; - $params = array('value' => '********', 'name' => $name, 'empty' => ''); - $DB->execute($sql, $params); - - $sql = "UPDATE {config_log} - SET oldvalue = :value - WHERE name = :name AND plugin IS NULL AND $sqlcompareoldvalue <> :empty"; - $params = array('value' => '********', 'name' => $name, 'empty' => ''); - $DB->execute($sql, $params); - - } else { - $sql = "UPDATE {config_log} - SET value = :value - WHERE name = :name AND plugin = :plugin AND $sqlcomparevalue <> :empty"; - $params = array('value' => '********', 'name' => $name, 'plugin' => $plugin, 'empty' => ''); - $DB->execute($sql, $params); - - $sql = "UPDATE {config_log} - SET oldvalue = :value - WHERE name = :name AND plugin = :plugin AND $sqlcompareoldvalue <> :empty"; - $params = array('value' => '********', 'name' => $name, 'plugin' => $plugin, 'empty' => ''); - $DB->execute($sql, $params); - } - } - // Main savepoint reached. - upgrade_main_savepoint(true, 2013122400.01); - } - - if ($oldversion < 2014011000.01) { - - // Define table cache_text to be dropped. - $table = new xmldb_table('cache_text'); - - // Conditionally launch drop table for cache_text. - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - unset_config('cachetext'); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014011000.01); - } - - if ($oldversion < 2014011701.00) { - // Fix gradebook sortorder duplicates. - upgrade_grade_item_fix_sortorder(); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014011701.00); - } - - if ($oldversion < 2014012300.01) { - // Remove deleted users home pages. - $sql = "DELETE FROM {my_pages} - WHERE EXISTS (SELECT {user}.id - FROM {user} - WHERE {user}.id = {my_pages}.userid - AND {user}.deleted = 1) - AND {my_pages}.private = 1"; - $DB->execute($sql); - - // Reached main savepoint. - upgrade_main_savepoint(true, 2014012300.01); - } - - if ($oldversion < 2014012400.00) { - // Define table lock_db to be created. - $table = new xmldb_table('lock_db'); - - // Adding fields to table lock_db. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('resourcekey', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - $table->add_field('expires', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('owner', XMLDB_TYPE_CHAR, '36', null, null, null, null); - - // Adding keys to table lock_db. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Adding indexes to table lock_db. - $table->add_index('resourcekey_uniq', XMLDB_INDEX_UNIQUE, array('resourcekey')); - $table->add_index('expires_idx', XMLDB_INDEX_NOTUNIQUE, array('expires')); - $table->add_index('owner_idx', XMLDB_INDEX_NOTUNIQUE, array('owner')); - - // Conditionally launch create table for lock_db. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014012400.00); - } - - if ($oldversion < 2014021300.01) { - // Delete any cached stats to force recalculation later, then we can be sure that cached records will have the correct - // field. - $DB->delete_records('question_response_analysis'); - $DB->delete_records('question_statistics'); - $DB->delete_records('quiz_statistics'); - - // Define field variant to be added to question_statistics. - $table = new xmldb_table('question_statistics'); - $field = new xmldb_field('variant', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'subquestion'); - - // Conditionally launch add field variant. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014021300.01); - } - - if ($oldversion < 2014021300.02) { - - // Define field variant to be added to question_response_analysis. - $table = new xmldb_table('question_response_analysis'); - $field = new xmldb_field('variant', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'questionid'); - - // Conditionally launch add field variant. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014021300.02); - } - - if ($oldversion < 2014021800.00) { - - // Define field queued to be added to portfolio_tempdata. - $table = new xmldb_table('portfolio_tempdata'); - $field = new xmldb_field('queued', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'instance'); - - // Conditionally launch add field queued. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014021800.00); - } - - if ($oldversion < 2014021900.01) { - // Force uninstall of deleted tool. - - // Normally, in this sort of situation, we would do a file_exists check, - // in case the plugin had been added back as an add-on. However, this - // plugin is completely useless after Moodle 2.6, so we check that the - // files have been removed in upgrade_stale_php_files_present, and we - // uninstall it unconditionally here. - - // Remove all associated config. - unset_all_config_for_plugin('tool_qeupgradehelper'); - - upgrade_main_savepoint(true, 2014021900.01); - } - - if ($oldversion < 2014021900.02) { - - // Define table question_states to be dropped. - $table = new xmldb_table('question_states'); - - // Conditionally launch drop table for question_states. - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014021900.02); - } - - if ($oldversion < 2014021900.03) { - - // Define table question_sessions to be dropped. - $table = new xmldb_table('question_sessions'); - - // Conditionally launch drop table for question_sessions. - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014021900.03); - } - - if ($oldversion < 2014022600.00) { - $table = new xmldb_table('task_scheduled'); - - // Adding fields to table task_scheduled. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('component', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - $table->add_field('classname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - $table->add_field('lastruntime', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('nextruntime', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('blocking', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('minute', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null); - $table->add_field('hour', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null); - $table->add_field('day', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null); - $table->add_field('month', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null); - $table->add_field('dayofweek', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null); - $table->add_field('faildelay', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('customised', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('disabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0'); - - // Adding keys to table task_scheduled. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Adding indexes to table task_scheduled. - $table->add_index('classname_uniq', XMLDB_INDEX_UNIQUE, array('classname')); - - // Conditionally launch create table for task_scheduled. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define table task_adhoc to be created. - $table = new xmldb_table('task_adhoc'); - - // Adding fields to table task_adhoc. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('component', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - $table->add_field('classname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); - $table->add_field('nextruntime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('faildelay', XMLDB_TYPE_INTEGER, '10', null, null, null, null); - $table->add_field('customdata', XMLDB_TYPE_TEXT, null, null, null, null, null); - $table->add_field('blocking', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); - - // Adding keys to table task_adhoc. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Adding indexes to table task_adhoc. - $table->add_index('nextruntime_idx', XMLDB_INDEX_NOTUNIQUE, array('nextruntime')); - - // Conditionally launch create table for task_adhoc. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014022600.00); - } - - if ($oldversion < 2014031400.02) { - // Delete any cached stats to force recalculation later, then we can be sure that cached records will have the correct - // field. - $DB->delete_records('question_response_analysis'); - $DB->delete_records('question_statistics'); - $DB->delete_records('quiz_statistics'); - - // Define field response to be dropped from question_response_analysis. - $table = new xmldb_table('question_response_analysis'); - $field = new xmldb_field('rcount'); - - // Conditionally launch drop field response. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014031400.02); - } - - if ($oldversion < 2014031400.03) { - - // Define table question_response_count to be created. - $table = new xmldb_table('question_response_count'); - - // Adding fields to table question_response_count. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('analysisid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('try', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('rcount', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - - // Adding keys to table question_response_count. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('analysisid', XMLDB_KEY_FOREIGN, array('analysisid'), 'question_response_analysis', array('id')); - - // Conditionally launch create table for question_response_count. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014031400.03); - } - - if ($oldversion < 2014031400.04) { - - // Define field whichtries to be added to question_response_analysis. - $table = new xmldb_table('question_response_analysis'); - $field = new xmldb_field('whichtries', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'hashcode'); - - // Conditionally launch add field whichtries. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014031400.04); - } - - if ($oldversion < 2014032600.00) { - // Removing the themes from core. - $themes = array('afterburner', 'anomaly', 'arialist', 'binarius', 'boxxie', 'brick', 'formal_white', 'formfactor', - 'fusion', 'leatherbound', 'magazine', 'nimble', 'nonzero', 'overlay', 'serenity', 'sky_high', 'splash', - 'standard', 'standardold'); - - foreach ($themes as $key => $theme) { - if (check_dir_exists($CFG->dirroot . '/theme/' . $theme, false)) { - // Ignore the themes that have been re-downloaded. - unset($themes[$key]); - } - } - - // Check we actually have themes to remove. - if (count($themes) > 0) { - - // Replace the theme configs. - if (in_array(get_config('core', 'theme'), $themes)) { - set_config('theme', 'clean'); - } - if (in_array(get_config('core', 'thememobile'), $themes)) { - set_config('thememobile', 'clean'); - } - if (in_array(get_config('core', 'themelegacy'), $themes)) { - set_config('themelegacy', 'clean'); - } - if (in_array(get_config('core', 'themetablet'), $themes)) { - set_config('themetablet', 'clean'); - } - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014032600.00); - } - - if ($oldversion < 2014032600.02) { - // Add new fields to the 'tag_instance' table. - $table = new xmldb_table('tag_instance'); - $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, false, null, null, 'tagid'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', null, false, null, null, 'itemid'); - // Define the 'contextid' foreign key to be added to the tag_instance table. - $key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_key($table, $key); - $DB->set_field('tag_instance', 'contextid', null, array('contextid' => 0)); - $dbman->change_field_default($table, $field); - } else { - $dbman->add_field($table, $field); - } - $dbman->add_key($table, $key); - - $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'ordering'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $sql = "UPDATE {tag_instance} - SET timecreated = timemodified"; - $DB->execute($sql); - - // Update all the course tags. - $sql = "UPDATE {tag_instance} - SET component = 'core', - contextid = (SELECT ctx.id - FROM {context} ctx - WHERE ctx.contextlevel = :contextlevel - AND ctx.instanceid = {tag_instance}.itemid) - WHERE itemtype = 'course' AND contextid IS NULL"; - $DB->execute($sql, array('contextlevel' => CONTEXT_COURSE)); - - // Update all the user tags. - $sql = "UPDATE {tag_instance} - SET component = 'core', - contextid = (SELECT ctx.id - FROM {context} ctx - WHERE ctx.contextlevel = :contextlevel - AND ctx.instanceid = {tag_instance}.itemid) - WHERE itemtype = 'user' AND contextid IS NULL"; - $DB->execute($sql, array('contextlevel' => CONTEXT_USER)); - - // Update all the blog post tags. - $sql = "UPDATE {tag_instance} - SET component = 'core', - contextid = (SELECT ctx.id - FROM {context} ctx - JOIN {post} p - ON p.userid = ctx.instanceid - WHERE ctx.contextlevel = :contextlevel - AND p.id = {tag_instance}.itemid) - WHERE itemtype = 'post' AND contextid IS NULL"; - $DB->execute($sql, array('contextlevel' => CONTEXT_USER)); - - // Update all the wiki page tags. - $sql = "UPDATE {tag_instance} - SET component = 'mod_wiki', - contextid = (SELECT ctx.id - FROM {context} ctx - JOIN {course_modules} cm - ON cm.id = ctx.instanceid - JOIN {modules} m - ON m.id = cm.module - JOIN {wiki} w - ON w.id = cm.instance - JOIN {wiki_subwikis} sw - ON sw.wikiid = w.id - JOIN {wiki_pages} wp - ON wp.subwikiid = sw.id - WHERE m.name = 'wiki' - AND ctx.contextlevel = :contextlevel - AND wp.id = {tag_instance}.itemid) - WHERE itemtype = 'wiki_pages' AND contextid IS NULL"; - $DB->execute($sql, array('contextlevel' => CONTEXT_MODULE)); - - // Update all the question tags. - $sql = "UPDATE {tag_instance} - SET component = 'core_question', - contextid = (SELECT qc.contextid - FROM {question} q - JOIN {question_categories} qc - ON q.category = qc.id - WHERE q.id = {tag_instance}.itemid) - WHERE itemtype = 'question' AND contextid IS NULL"; - $DB->execute($sql); - - // Update all the tag tags. - $sql = "UPDATE {tag_instance} - SET component = 'core', - contextid = :systemcontext - WHERE itemtype = 'tag' AND contextid IS NULL"; - $DB->execute($sql, array('systemcontext' => context_system::instance()->id)); - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014032600.02); - } - - if ($oldversion < 2014032700.01) { - - // Define field disabled to be added to task_scheduled. - $table = new xmldb_table('task_scheduled'); - $field = new xmldb_field('disabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'customised'); - - // Conditionally launch add field disabled. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014032700.01); - } - - if ($oldversion < 2014032700.02) { - - // Update displayloginfailures setting. - if (empty($CFG->displayloginfailures)) { - set_config('displayloginfailures', 0); - } else { - set_config('displayloginfailures', 1); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014032700.02); - } - - if ($oldversion < 2014040800.00) { - - // Define field availability to be added to course_modules. - $table = new xmldb_table('course_modules'); - $field = new xmldb_field('availability', XMLDB_TYPE_TEXT, null, null, null, null, null, 'showdescription'); - - // Conditionally launch add field availability. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field availability to be added to course_sections. - $table = new xmldb_table('course_sections'); - $field = new xmldb_field('availability', XMLDB_TYPE_TEXT, null, null, null, null, null, 'groupingid'); - - // Conditionally launch add field availability. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Update existing conditions to new format. This could be a slow - // process, so begin by counting the number of affected modules/sections. - // (Performance: On the OU system, these took ~0.3 seconds, with about - // 20,000 results out of about 400,000 total rows in those tables.) - $cmcount = $DB->count_records_sql(" - SELECT COUNT(1) - FROM {course_modules} cm - WHERE cm.availablefrom != 0 OR - cm.availableuntil != 0 OR - EXISTS (SELECT 1 FROM {course_modules_availability} WHERE coursemoduleid = cm.id) OR - EXISTS (SELECT 1 FROM {course_modules_avail_fields} WHERE coursemoduleid = cm.id)"); - $sectcount = $DB->count_records_sql(" - SELECT COUNT(1) - FROM {course_sections} cs - WHERE cs.groupingid != 0 OR - cs.availablefrom != 0 OR - cs.availableuntil != 0 OR - EXISTS (SELECT 1 FROM {course_sections_availability} WHERE coursesectionid = cs.id) OR - EXISTS (SELECT 1 FROM {course_sections_avail_fields} WHERE coursesectionid = cs.id)"); - - if ($cmcount + $sectcount > 0) { - // Show progress bar and start db transaction. - $transaction = $DB->start_delegated_transaction(); - $pbar = new progress_bar('availupdate', 500, true); - - // Loop through all course-modules. - // (Performance: On the OU system, the query took <1 second for ~20k - // results; updating all those entries took ~3 minutes.) - $done = 0; - $lastupdate = 0; - $rs = $DB->get_recordset_sql(" - SELECT cm.id, cm.availablefrom, cm.availableuntil, cm.showavailability, - COUNT(DISTINCT cma.id) AS availcount, - COUNT(DISTINCT cmf.id) AS fieldcount - FROM {course_modules} cm - LEFT JOIN {course_modules_availability} cma ON cma.coursemoduleid = cm.id - LEFT JOIN {course_modules_avail_fields} cmf ON cmf.coursemoduleid = cm.id - WHERE cm.availablefrom != 0 OR - cm.availableuntil != 0 OR - cma.id IS NOT NULL OR - cmf.id IS NOT NULL - GROUP BY cm.id, cm.availablefrom, cm.availableuntil, cm.showavailability"); - foreach ($rs as $rec) { - // Update progress initially and then once per second. - if (time() != $lastupdate) { - $lastupdate = time(); - $pbar->update($done, $cmcount + $sectcount, - "Updating activity availability settings ($done/$cmcount)"); - } - - // Get supporting records - only if there are any (to reduce the - // number of queries where just date/group is used). - if ($rec->availcount) { - $availrecs = $DB->get_records('course_modules_availability', - array('coursemoduleid' => $rec->id)); - } else { - $availrecs = array(); - } - if ($rec->fieldcount) { - $fieldrecs = $DB->get_records_sql(" - SELECT cmaf.userfield, cmaf.operator, cmaf.value, uif.shortname - FROM {course_modules_avail_fields} cmaf - LEFT JOIN {user_info_field} uif ON uif.id = cmaf.customfieldid - WHERE cmaf.coursemoduleid = ?", array($rec->id)); - } else { - $fieldrecs = array(); - } - - // Update item. - $availability = upgrade_availability_item(0, 0, - $rec->availablefrom, $rec->availableuntil, - $rec->showavailability, $availrecs, $fieldrecs); - if ($availability) { - $DB->set_field('course_modules', 'availability', $availability, array('id' => $rec->id)); - } - - // Update progress. - $done++; - } - $rs->close(); - - // Loop through all course-sections. - // (Performance: On the OU system, this took <1 second for, er, 150 results.) - $done = 0; - $rs = $DB->get_recordset_sql(" - SELECT cs.id, cs.groupingid, cs.availablefrom, - cs.availableuntil, cs.showavailability, - COUNT(DISTINCT csa.id) AS availcount, - COUNT(DISTINCT csf.id) AS fieldcount - FROM {course_sections} cs - LEFT JOIN {course_sections_availability} csa ON csa.coursesectionid = cs.id - LEFT JOIN {course_sections_avail_fields} csf ON csf.coursesectionid = cs.id - WHERE cs.groupingid != 0 OR - cs.availablefrom != 0 OR - cs.availableuntil != 0 OR - csa.id IS NOT NULL OR - csf.id IS NOT NULL - GROUP BY cs.id, cs.groupingid, cs.availablefrom, - cs.availableuntil, cs.showavailability"); - foreach ($rs as $rec) { - // Update progress once per second. - if (time() != $lastupdate) { - $lastupdate = time(); - $pbar->update($done + $cmcount, $cmcount + $sectcount, - "Updating section availability settings ($done/$sectcount)"); - } - - // Get supporting records - only if there are any (to reduce the - // number of queries where just date/group is used). - if ($rec->availcount) { - $availrecs = $DB->get_records('course_sections_availability', - array('coursesectionid' => $rec->id)); - } else { - $availrecs = array(); - } - if ($rec->fieldcount) { - $fieldrecs = $DB->get_records_sql(" - SELECT csaf.userfield, csaf.operator, csaf.value, uif.shortname - FROM {course_sections_avail_fields} csaf - LEFT JOIN {user_info_field} uif ON uif.id = csaf.customfieldid - WHERE csaf.coursesectionid = ?", array($rec->id)); - } else { - $fieldrecs = array(); - } - - // Update item. - $availability = upgrade_availability_item($rec->groupingid ? 1 : 0, - $rec->groupingid, $rec->availablefrom, $rec->availableuntil, - $rec->showavailability, $availrecs, $fieldrecs); - if ($availability) { - $DB->set_field('course_sections', 'availability', $availability, array('id' => $rec->id)); - } - - // Update progress. - $done++; - } - $rs->close(); - - // Final progress update for 100%. - $pbar->update($done + $cmcount, $cmcount + $sectcount, - 'Availability settings updated for ' . ($cmcount + $sectcount) . - ' activities and sections'); - - $transaction->allow_commit(); - } - - // Drop tables which are not necessary because they are covered by the - // new availability fields. - $table = new xmldb_table('course_modules_availability'); - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - $table = new xmldb_table('course_modules_avail_fields'); - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - $table = new xmldb_table('course_sections_availability'); - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - $table = new xmldb_table('course_sections_avail_fields'); - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - // Drop unnnecessary fields from course_modules. - $table = new xmldb_table('course_modules'); - $field = new xmldb_field('availablefrom'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - $field = new xmldb_field('availableuntil'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - $field = new xmldb_field('showavailability'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Drop unnnecessary fields from course_sections. - $table = new xmldb_table('course_sections'); - $field = new xmldb_field('availablefrom'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - $field = new xmldb_field('availableuntil'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - $field = new xmldb_field('showavailability'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - $field = new xmldb_field('groupingid'); - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014040800.00); - } - - if ($oldversion < 2014041500.01) { - - $table = new xmldb_table('user_info_data'); - - $sql = 'SELECT DISTINCT info.id - FROM {user_info_data} info - INNER JOIN {user_info_data} older - ON info.fieldid = older.fieldid - AND info.userid = older.userid - AND older.id < info.id'; - $transaction = $DB->start_delegated_transaction(); - $rs = $DB->get_recordset_sql($sql); - foreach ($rs as $rec) { - $DB->delete_records('user_info_data', array('id' => $rec->id)); - } - $transaction->allow_commit(); - - $oldindex = new xmldb_index('userid_fieldid', XMLDB_INDEX_NOTUNIQUE, array('userid', 'fieldid')); - if ($dbman->index_exists($table, $oldindex)) { - $dbman->drop_index($table, $oldindex); - } - - $newindex = new xmldb_index('userid_fieldid', XMLDB_INDEX_UNIQUE, array('userid', 'fieldid')); - - if (!$dbman->index_exists($table, $newindex)) { - $dbman->add_index($table, $newindex); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014041500.01); - } - - if ($oldversion < 2014050100.00) { - // Fixing possible wrong MIME type for DigiDoc files. - $extensions = array('%.bdoc', '%.cdoc', '%.ddoc'); - $select = $DB->sql_like('filename', '?', false); - foreach ($extensions as $extension) { - $DB->set_field_select( - 'files', - 'mimetype', - 'application/x-digidoc', - $select, - array($extension) - ); - } - upgrade_main_savepoint(true, 2014050100.00); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - // MDL-32543 Make sure that the log table has correct length for action and url fields. if ($oldversion < 2014051200.02) { diff --git a/lib/editor/atto/db/upgrade.php b/lib/editor/atto/db/upgrade.php index 547bbad3d42fb..87a5bcf8e410d 100644 --- a/lib/editor/atto/db/upgrade.php +++ b/lib/editor/atto/db/upgrade.php @@ -34,25 +34,6 @@ function xmldb_editor_atto_upgrade($oldversion) { $dbman = $DB->get_manager(); - if ($oldversion < 2014032800) { - // Make Atto the default. - $currenteditors = $CFG->texteditors; - $neweditors = array(); - - $list = explode(',', $currenteditors); - array_push($neweditors, 'atto'); - foreach ($list as $editor) { - if ($editor != 'atto') { - array_push($neweditors, $editor); - } - } - - set_config('texteditors', implode(',', $neweditors)); - upgrade_plugin_savepoint(true, 2014032800, 'editor', 'atto'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. if ($oldversion < 2014081400) { // Define table editor_atto_autosave to be created. diff --git a/lib/editor/tinymce/db/upgrade.php b/lib/editor/tinymce/db/upgrade.php index 6323f52b99c22..14204f5e84de4 100644 --- a/lib/editor/tinymce/db/upgrade.php +++ b/lib/editor/tinymce/db/upgrade.php @@ -27,137 +27,6 @@ function xmldb_editor_tinymce_upgrade($oldversion) { global $CFG, $DB; - $dbman = $DB->get_manager(); - - - if ($oldversion < 2012083100) { - // Reset redesigned editor toolbar setting. - unset_config('customtoolbar', 'editor_tinymce'); - upgrade_plugin_savepoint(true, 2012083100, 'editor', 'tinymce'); - } - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013061400) { - // Reset redesigned editor toolbar setting. - $oldorder = "fontselect,fontsizeselect,formatselect,|,undo,redo,|,search,replace,|,fullscreen - -bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl - -bullist,numlist,outdent,indent,|,link,unlink,|,image,nonbreaking,charmap,table,|,code"; - - $neworder = "formatselect,bold,italic,|,bullist,numlist,|,link,unlink,|,image - -undo,redo,|,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,outdent,indent,|,forecolor,backcolor,|,ltr,rtl,|,nonbreaking,charmap,table - -fontselect,fontsizeselect,code,search,replace,|,cleanup,removeformat,pastetext,pasteword,|,fullscreen"; - $currentorder = get_config('editor_tinymce', 'customtoolbar'); - if ($currentorder == $oldorder) { - unset_config('customtoolbar', 'editor_tinymce'); - set_config('customtoolbar', $neworder, 'editor_tinymce'); - } - upgrade_plugin_savepoint(true, 2013061400, 'editor', 'tinymce'); - } - - if ($oldversion < 2013070500) { - // Insert wrap plugin to nicely wrap the toolbars on small screens. - $oldorder = "formatselect,bold,italic,|,bullist,numlist,|,link,unlink,|,image - -undo,redo,|,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,outdent,indent,|,forecolor,backcolor,|,ltr,rtl,|,nonbreaking,charmap,table - -fontselect,fontsizeselect,code,search,replace,|,cleanup,removeformat,pastetext,pasteword,|,fullscreen"; - - $neworder = "formatselect,bold,italic,wrap,bullist,numlist,|,link,unlink,|,image - -undo,redo,|,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,wrap,outdent,indent,|,forecolor,backcolor,|,ltr,rtl,|,nonbreaking,charmap,table - -fontselect,fontsizeselect,wrap,code,search,replace,|,cleanup,removeformat,pastetext,pasteword,|,fullscreen"; - $currentorder = get_config('editor_tinymce', 'customtoolbar'); - if ($currentorder == $oldorder) { - unset_config('customtoolbar', 'editor_tinymce'); - set_config('customtoolbar', $neworder, 'editor_tinymce'); - } else { - // Simple auto conversion algorithm. - $toolbars = explode("\n", $oldorder); - $newtoolbars = array(); - foreach ($toolbars as $toolbar) { - $sepcount = substr_count($toolbar, '|'); - - if ($sepcount > 0) { - // We assume the middle separator (rounding down). - $divisionindex = round($sepcount / 2, 0, PHP_ROUND_HALF_DOWN); - - $buttons = explode(',', $toolbar); - $index = 0; - foreach ($buttons as $key => $button) { - if ($button === "|") { - if ($index == $divisionindex) { - $buttons[$key] = 'wrap'; - break; - } else { - $index += 1; - } - } - } - $toolbar = implode(',', $buttons); - } - array_push($newtoolbars, $toolbar); - } - $neworder = implode("\n", $newtoolbars); - - // Set the new config. - unset_config('customtoolbar', 'editor_tinymce'); - set_config('customtoolbar', $neworder, 'editor_tinymce'); - } - upgrade_plugin_savepoint(true, 2013070500, 'editor', 'tinymce'); - } - - if ($oldversion < 2013102900) { - // Reset redesigned editor toolbar setting. - $currentorder = get_config('editor_tinymce', 'customtoolbar'); - // Start with a wrap. - $neworder = "wrap,". $currentorder; - // Replace all separators with wraps to allow for proper display of groups. - $neworder = preg_replace('/\|\|*/', "wrap", $neworder); - // Insert a wrap between the format selector and the bold button. - $neworder = str_replace("formatselect,bold", "formatselect,wrap,bold", $neworder); - set_config('customtoolbar', $neworder, 'editor_tinymce'); - upgrade_plugin_savepoint(true, 2013102900, 'editor', 'tinymce'); - } - - if ($oldversion < 2013110600) { - // Reset redesigned editor toolbar setting. - $currentorder = get_config('editor_tinymce', 'customtoolbar'); - $olddefaultorder = "wrap,formatselect,wrap,bold,italic,wrap,bullist,numlist,wrap,link,unlink,wrap,image - -undo,redo,wrap,underline,strikethrough,sub,sup,wrap,justifyleft,justifycenter,justifyright,wrap,outdent,indent,wrap,forecolor,backcolor,wrap,ltr,rtl,wrap,nonbreaking,charmap,table - -fontselect,fontsizeselect,wrap,code,search,replace,wrap,cleanup,removeformat,pastetext,pasteword,wrap,fullscreen"; - $neworder = "wrap,formatselect,wrap,bold,italic,wrap,bullist,numlist,wrap,link,unlink,wrap,image - -undo,redo,wrap,underline,strikethrough,sub,sup,wrap,justifyleft,justifycenter,justifyright,wrap,outdent,indent,wrap,forecolor,backcolor,wrap,ltr,rtl - -fontselect,fontsizeselect,wrap,code,search,replace,wrap,nonbreaking,charmap,table,wrap,cleanup,removeformat,pastetext,pasteword,wrap,fullscreen"; - if ($currentorder == $olddefaultorder) { - set_config('customtoolbar', $neworder, 'editor_tinymce'); - } - - upgrade_plugin_savepoint(true, 2013110600, 'editor', 'tinymce'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014062900) { // We only want to delete DragMath from the customtoolbar setting if the directory no longer exists. If // the directory is present then it means it has been restored, so do not remove any settings. diff --git a/lib/editor/tinymce/plugins/spellchecker/db/upgrade.php b/lib/editor/tinymce/plugins/spellchecker/db/upgrade.php index 021ab4572582d..2186346d6fec1 100644 --- a/lib/editor/tinymce/plugins/spellchecker/db/upgrade.php +++ b/lib/editor/tinymce/plugins/spellchecker/db/upgrade.php @@ -25,30 +25,7 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_tinymce_spellchecker_upgrade($oldversion) { - global $CFG, $DB; - require_once(__DIR__.'/upgradelib.php'); - - $dbman = $DB->get_manager(); - - if ($oldversion < 2012051800) { - tinymce_spellchecker_migrate_settings(); - upgrade_plugin_savepoint(true, 2012051800, 'tinymce', 'spellchecker'); - } - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/message/output/email/db/upgrade.php b/message/output/email/db/upgrade.php index 4d9e1d4953d06..e5ad5311c92c3 100644 --- a/message/output/email/db/upgrade.php +++ b/message/output/email/db/upgrade.php @@ -22,37 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ +defined('MOODLE_INTERNAL') || die(); + /** * Upgrade code for the email message processor * * @param int $oldversion The version that we are upgrading from */ function xmldb_message_email_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -65,5 +43,3 @@ function xmldb_message_email_upgrade($oldversion) { return true; } - - diff --git a/message/output/jabber/db/upgrade.php b/message/output/jabber/db/upgrade.php index a42641f0b8265..3979a91a12a84 100644 --- a/message/output/jabber/db/upgrade.php +++ b/message/output/jabber/db/upgrade.php @@ -22,37 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Upgrade code for the jabber message processor * * @param int $oldversion The version that we are upgrading from */ function xmldb_message_jabber_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -65,5 +43,3 @@ function xmldb_message_jabber_upgrade($oldversion) { return true; } - - diff --git a/message/output/popup/db/upgrade.php b/message/output/popup/db/upgrade.php index 50353b6f1c680..5c0882823693f 100644 --- a/message/output/popup/db/upgrade.php +++ b/message/output/popup/db/upgrade.php @@ -22,37 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ +defined('MOODLE_INTERNAL') || die(); + /** * Upgrade code for the popup message processor * * @param int $oldversion The version that we are upgrading from */ function xmldb_message_popup_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -65,5 +43,3 @@ function xmldb_message_popup_upgrade($oldversion) { return true; } - - diff --git a/mod/assign/db/upgrade.php b/mod/assign/db/upgrade.php index 2debb16447e14..d5e358eb0f417 100644 --- a/mod/assign/db/upgrade.php +++ b/mod/assign/db/upgrade.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * upgrade this assignment instance - this function could be skipped but it will be needed later * @param int $oldversion The old version of the assign module @@ -32,461 +34,6 @@ function xmldb_assign_upgrade($oldversion) { $dbman = $DB->get_manager(); - if ($oldversion < 2012051700) { - - // Define field to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('sendlatenotifications', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'sendnotifications'); - - // Conditionally launch add field. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Assign savepoint reached. - upgrade_mod_savepoint(true, 2012051700, 'assign'); - } - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2012071800) { - - // Define field requiresubmissionstatement to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('requiresubmissionstatement', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'timemodified'); - - // Conditionally launch add field requiresubmissionstatement. - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Assign savepoint reached. - upgrade_mod_savepoint(true, 2012071800, 'assign'); - } - - if ($oldversion < 2012081600) { - - // Define field to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'timemodified'); - - // Conditionally launch add field. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Assign savepoint reached. - upgrade_mod_savepoint(true, 2012081600, 'assign'); - } - - // Individual extension dates support. - if ($oldversion < 2012082100) { - - // Define field cutoffdate to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('cutoffdate', XMLDB_TYPE_INTEGER, '10', null, - XMLDB_NOTNULL, null, '0', 'completionsubmit'); - - // Conditionally launch add field cutoffdate. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - // If prevent late is on - set cutoffdate to due date. - - // Now remove the preventlatesubmissions column. - $field = new xmldb_field('preventlatesubmissions', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'nosubmissions'); - if ($dbman->field_exists($table, $field)) { - // Set the cutoffdate to the duedate if preventlatesubmissions was enabled. - $sql = 'UPDATE {assign} SET cutoffdate = duedate WHERE preventlatesubmissions = 1'; - $DB->execute($sql); - - $dbman->drop_field($table, $field); - } - - // Define field extensionduedate to be added to assign_grades. - $table = new xmldb_table('assign_grades'); - $field = new xmldb_field('extensionduedate', XMLDB_TYPE_INTEGER, '10', null, - XMLDB_NOTNULL, null, '0', 'mailed'); - - // Conditionally launch add field extensionduedate. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Assign savepoint reached. - upgrade_mod_savepoint(true, 2012082100, 'assign'); - } - - // Team assignment support. - if ($oldversion < 2012082300) { - - // Define field to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('teamsubmission', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'cutoffdate'); - - // Conditionally launch add field. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - $field = new xmldb_field('requireallteammemberssubmit', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'teamsubmission'); - // Conditionally launch add field. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - $field = new xmldb_field('teamsubmissiongroupingid', XMLDB_TYPE_INTEGER, '10', null, - XMLDB_NOTNULL, null, '0', 'requireallteammemberssubmit'); - // Conditionally launch add field. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - $index = new xmldb_index('teamsubmissiongroupingid', - XMLDB_INDEX_NOTUNIQUE, - array('teamsubmissiongroupingid')); - // Conditionally launch add index. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - $table = new xmldb_table('assign_submission'); - $field = new xmldb_field('groupid', XMLDB_TYPE_INTEGER, '10', null, - XMLDB_NOTNULL, null, '0', 'status'); - // Conditionally launch add field. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_mod_savepoint(true, 2012082300, 'assign'); - } - if ($oldversion < 2012082400) { - - // Define table assign_user_mapping to be created. - $table = new xmldb_table('assign_user_mapping'); - - // Adding fields to table assign_user_mapping. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('assignment', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - - // Adding keys to table assign_user_mapping. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('assignment', XMLDB_KEY_FOREIGN, array('assignment'), 'assign', array('id')); - $table->add_key('user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - - // Conditionally launch create table for assign_user_mapping. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Define field blindmarking to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('blindmarking', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'teamsubmissiongroupingid'); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field revealidentities to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('revealidentities', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'blindmarking'); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Assignment savepoint reached. - upgrade_mod_savepoint(true, 2012082400, 'assign'); - } - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013030600) { - upgrade_set_timeout(60*20); - - // Some assignments (upgraded from 2.2 assignment) have duplicate entries in the assign_submission - // and assign_grades tables for a single user. This needs to be cleaned up before we can add the unique indexes - // below. - - // Only do this cleanup if the attempt number field has not been added to the table yet. - $table = new xmldb_table('assign_submission'); - $field = new xmldb_field('attemptnumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'groupid'); - if (!$dbman->field_exists($table, $field)) { - // OK safe to cleanup duplicates here. - - $sql = 'SELECT assignment, userid, groupid from {assign_submission} ' . - 'GROUP BY assignment, userid, groupid HAVING (count(id) > 1)'; - $badrecords = $DB->get_recordset_sql($sql); - - foreach ($badrecords as $badrecord) { - $params = array('userid'=>$badrecord->userid, - 'groupid'=>$badrecord->groupid, - 'assignment'=>$badrecord->assignment); - $duplicates = $DB->get_records('assign_submission', $params, 'timemodified DESC', 'id, timemodified'); - if ($duplicates) { - // Take the first (last updated) entry out of the list so it doesn't get deleted. - $valid = array_shift($duplicates); - $deleteids = array(); - foreach ($duplicates as $duplicate) { - $deleteids[] = $duplicate->id; - } - - list($sqlids, $sqlidparams) = $DB->get_in_or_equal($deleteids); - $DB->delete_records_select('assign_submission', 'id ' . $sqlids, $sqlidparams); - } - } - - $badrecords->close(); - } - - // Same cleanup required for assign_grades - // Only do this cleanup if the attempt number field has not been added to the table yet. - $table = new xmldb_table('assign_grades'); - $field = new xmldb_field('attemptnumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'grade'); - if (!$dbman->field_exists($table, $field)) { - // OK safe to cleanup duplicates here. - - $sql = 'SELECT assignment, userid from {assign_grades} GROUP BY assignment, userid HAVING (count(id) > 1)'; - $badrecords = $DB->get_recordset_sql($sql); - - foreach ($badrecords as $badrecord) { - $params = array('userid'=>$badrecord->userid, - 'assignment'=>$badrecord->assignment); - $duplicates = $DB->get_records('assign_grades', $params, 'timemodified DESC', 'id, timemodified'); - if ($duplicates) { - // Take the first (last updated) entry out of the list so it doesn't get deleted. - $valid = array_shift($duplicates); - $deleteids = array(); - foreach ($duplicates as $duplicate) { - $deleteids[] = $duplicate->id; - } - - list($sqlids, $sqlidparams) = $DB->get_in_or_equal($deleteids); - $DB->delete_records_select('assign_grades', 'id ' . $sqlids, $sqlidparams); - } - } - - $badrecords->close(); - } - - // Define table assign_user_flags to be created. - $table = new xmldb_table('assign_user_flags'); - - // Adding fields to table assign_user_flags. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('assignment', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('mailed', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('extensionduedate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - - // Adding keys to table assign_user_flags. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - $table->add_key('assignment', XMLDB_KEY_FOREIGN, array('assignment'), 'assign', array('id')); - - // Adding indexes to table assign_user_flags. - $table->add_index('mailed', XMLDB_INDEX_NOTUNIQUE, array('mailed')); - - // Conditionally launch create table for assign_user_flags. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - - // Copy the flags from the old table to the new one. - $sql = 'INSERT INTO {assign_user_flags} - (assignment, userid, locked, mailed, extensionduedate) - SELECT assignment, userid, locked, mailed, extensionduedate - FROM {assign_grades}'; - $DB->execute($sql); - } - - // And delete the old columns. - // Define index mailed (not unique) to be dropped form assign_grades. - $table = new xmldb_table('assign_grades'); - $index = new xmldb_index('mailed', XMLDB_INDEX_NOTUNIQUE, array('mailed')); - - // Conditionally launch drop index mailed. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Define field locked to be dropped from assign_grades. - $table = new xmldb_table('assign_grades'); - $field = new xmldb_field('locked'); - - // Conditionally launch drop field locked. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Define field mailed to be dropped from assign_grades. - $table = new xmldb_table('assign_grades'); - $field = new xmldb_field('mailed'); - - // Conditionally launch drop field mailed. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Define field extensionduedate to be dropped from assign_grades. - $table = new xmldb_table('assign_grades'); - $field = new xmldb_field('extensionduedate'); - - // Conditionally launch drop field extensionduedate. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Define field attemptreopenmethod to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('attemptreopenmethod', XMLDB_TYPE_CHAR, '10', null, - XMLDB_NOTNULL, null, 'none', 'revealidentities'); - - // Conditionally launch add field attemptreopenmethod. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field maxattempts to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('maxattempts', XMLDB_TYPE_INTEGER, '6', null, XMLDB_NOTNULL, null, '-1', 'attemptreopenmethod'); - - // Conditionally launch add field maxattempts. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field attemptnumber to be added to assign_submission. - $table = new xmldb_table('assign_submission'); - $field = new xmldb_field('attemptnumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'groupid'); - - // Conditionally launch add field attemptnumber. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define index attemptnumber (not unique) to be added to assign_submission. - $table = new xmldb_table('assign_submission'); - $index = new xmldb_index('attemptnumber', XMLDB_INDEX_NOTUNIQUE, array('attemptnumber')); - // Conditionally launch add index attemptnumber. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Define field attemptnumber to be added to assign_grades. - $table = new xmldb_table('assign_grades'); - $field = new xmldb_field('attemptnumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'grade'); - - // Conditionally launch add field attemptnumber. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define index attemptnumber (not unique) to be added to assign_grades. - $table = new xmldb_table('assign_grades'); - $index = new xmldb_index('attemptnumber', XMLDB_INDEX_NOTUNIQUE, array('attemptnumber')); - - // Conditionally launch add index attemptnumber. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Define index uniqueattemptsubmission (unique) to be added to assign_submission. - $table = new xmldb_table('assign_submission'); - $index = new xmldb_index('uniqueattemptsubmission', - XMLDB_INDEX_UNIQUE, - array('assignment', 'userid', 'groupid', 'attemptnumber')); - - // Conditionally launch add index uniqueattempt. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Define index uniqueattemptgrade (unique) to be added to assign_grades. - $table = new xmldb_table('assign_grades'); - $index = new xmldb_index('uniqueattemptgrade', XMLDB_INDEX_UNIQUE, array('assignment', 'userid', 'attemptnumber')); - - // Conditionally launch add index uniqueattempt. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Module assign savepoint reached. - upgrade_mod_savepoint(true, 2013030600, 'assign'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013061101) { - // Define field markingworkflow to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('markingworkflow', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'maxattempts'); - - // Conditionally launch add field markingworkflow. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field markingallocation to be added to assign. - $field = new xmldb_field('markingallocation', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'markingworkflow'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field workflowstate to be added to assign_grades. - $table = new xmldb_table('assign_user_flags'); - $field = new xmldb_field('workflowstate', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'extensionduedate'); - - // Conditionally launch add field workflowstate. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field allocatedmarker to be added to assign_grades. - $field = new xmldb_field('allocatedmarker', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'workflowstate'); - // Conditionally launch add field workflowstate. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_mod_savepoint(true, 2013061101, 'assign'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2014010801) { - - // Define field sendstudentnotifications to be added to assign. - $table = new xmldb_table('assign'); - $field = new xmldb_field('sendstudentnotifications', - XMLDB_TYPE_INTEGER, - '2', - null, - XMLDB_NOTNULL, - null, - '1', - 'markingallocation'); - - // Conditionally launch add field sendstudentnotifications. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Assign savepoint reached. - upgrade_mod_savepoint(true, 2014010801, 'assign'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014051201) { // Cleanup bad database records where assignid is missing. @@ -495,6 +42,7 @@ function xmldb_assign_upgrade($oldversion) { // Assign savepoint reached. upgrade_mod_savepoint(true, 2014051201, 'assign'); } + if ($oldversion < 2014072400) { // Add "latest" column to submissions table to mark the latest attempt. diff --git a/mod/assign/feedback/comments/db/upgrade.php b/mod/assign/feedback/comments/db/upgrade.php index 30cb8e9cb12b1..3c35f2f638ee9 100644 --- a/mod/assign/feedback/comments/db/upgrade.php +++ b/mod/assign/feedback/comments/db/upgrade.php @@ -22,27 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Stub for upgrade code * @param int $oldversion * @return bool */ function xmldb_assignfeedback_comments_upgrade($oldversion) { - // Do the upgrades. - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/assign/feedback/editpdf/db/upgrade.php b/mod/assign/feedback/editpdf/db/upgrade.php index 89d6e74b5010e..65861e88005ae 100644 --- a/mod/assign/feedback/editpdf/db/upgrade.php +++ b/mod/assign/feedback/editpdf/db/upgrade.php @@ -32,44 +32,6 @@ function xmldb_assignfeedback_editpdf_upgrade($oldversion) { global $CFG; - if ($oldversion < 2013110800) { - - // Check that no stamps where uploaded. - $fs = get_file_storage(); - $stamps = $fs->get_area_files(context_system::instance()->id, 'assignfeedback_editpdf', - 'stamps', 0, "filename", false); - - // Add default stamps. - if (empty($stamps)) { - // List of default stamps. - $defaultstamps = array('smile.png', 'sad.png', 'tick.png', 'cross.png'); - - // Stamp file object. - $filerecord = new stdClass; - $filerecord->component = 'assignfeedback_editpdf'; - $filerecord->contextid = context_system::instance()->id; - $filerecord->userid = get_admin()->id; - $filerecord->filearea = 'stamps'; - $filerecord->filepath = '/'; - $filerecord->itemid = 0; - - // Add all default stamps. - foreach ($defaultstamps as $stamp) { - $filerecord->filename = $stamp; - $fs->create_file_from_pathname($filerecord, - $CFG->dirroot . '/mod/assign/feedback/editpdf/pix/' . $filerecord->filename); - } - } - - upgrade_plugin_savepoint(true, 2013110800, 'assignfeedback', 'editpdf'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/assign/feedback/file/db/upgrade.php b/mod/assign/feedback/file/db/upgrade.php index 1f50fac1b5a62..ecfe0bad889b7 100644 --- a/mod/assign/feedback/file/db/upgrade.php +++ b/mod/assign/feedback/file/db/upgrade.php @@ -22,27 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Stub for upgrade code * @param int $oldversion * @return bool */ function xmldb_assignfeedback_file_upgrade($oldversion) { - // Do the upgrades. - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/assign/submission/comments/db/upgrade.php b/mod/assign/submission/comments/db/upgrade.php index b090b37faf337..273eadee3242a 100644 --- a/mod/assign/submission/comments/db/upgrade.php +++ b/mod/assign/submission/comments/db/upgrade.php @@ -22,26 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Stub for upgrade code * @param int $oldversion * @return bool */ function xmldb_assignsubmission_comments_upgrade($oldversion) { - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -54,5 +43,3 @@ function xmldb_assignsubmission_comments_upgrade($oldversion) { return true; } - - diff --git a/mod/assign/submission/file/db/upgrade.php b/mod/assign/submission/file/db/upgrade.php index 13eeff0082417..62f13766e9046 100644 --- a/mod/assign/submission/file/db/upgrade.php +++ b/mod/assign/submission/file/db/upgrade.php @@ -22,24 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Stub for upgrade code * @param int $oldversion * @return bool */ function xmldb_assignsubmission_file_upgrade($oldversion) { - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -52,5 +43,3 @@ function xmldb_assignsubmission_file_upgrade($oldversion) { return true; } - - diff --git a/mod/assign/submission/onlinetext/db/upgrade.php b/mod/assign/submission/onlinetext/db/upgrade.php index ee9c2b79f888d..1b1907f45f6a7 100644 --- a/mod/assign/submission/onlinetext/db/upgrade.php +++ b/mod/assign/submission/onlinetext/db/upgrade.php @@ -22,26 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** * Stub for upgrade code * @param int $oldversion * @return bool */ function xmldb_assignsubmission_onlinetext_upgrade($oldversion) { - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -54,5 +43,3 @@ function xmldb_assignsubmission_onlinetext_upgrade($oldversion) { return true; } - - diff --git a/mod/assignment/db/upgrade.php b/mod/assignment/db/upgrade.php index a2030947b4273..c083cc4454674 100644 --- a/mod/assignment/db/upgrade.php +++ b/mod/assignment/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - if ($oldversion < 2012061701) { - // Fixed/updated numfiles field in assignment_submissions table to count the actual - // number of files has been uploaded when sendformarking is disabled - upgrade_set_timeout(600); // increase excution time for in large sites - $fs = get_file_storage(); - - // Fetch the moduleid for use in the course_modules table - $moduleid = $DB->get_field('modules', 'id', array('name' => 'assignment'), MUST_EXIST); +defined('MOODLE_INTERNAL') || die(); - $selectcount = 'SELECT COUNT(s.id) '; - $select = 'SELECT s.id, cm.id AS cmid '; - $query = 'FROM {assignment_submissions} s - JOIN {assignment} a ON a.id = s.assignment - JOIN {course_modules} cm ON a.id = cm.instance AND cm.module = :moduleid - WHERE assignmenttype = :assignmenttype'; - - $params = array('moduleid' => $moduleid, 'assignmenttype' => 'upload'); - - $countsubmissions = $DB->count_records_sql($selectcount.$query, $params); - $submissions = $DB->get_recordset_sql($select.$query, $params); - - $pbar = new progress_bar('assignmentupgradenumfiles', 500, true); - $i = 0; - foreach ($submissions as $sub) { - $i++; - if ($context = context_module::instance($sub->cmid)) { - $sub->numfiles = count($fs->get_area_files($context->id, 'mod_assignment', 'submission', $sub->id, 'sortorder', false)); - $DB->update_record('assignment_submissions', $sub); - } - $pbar->update($i, $countsubmissions, "Counting files of submissions ($i/$countsubmissions)"); - } - $submissions->close(); - - // assignment savepoint reached - upgrade_mod_savepoint(true, 2012061701, 'assignment'); - } - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013121900) { - // Define table assignment_upgrade to be created. - $table = new xmldb_table('assignment_upgrade'); - - // Adding fields to table assignment_upgrade. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('oldcmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('oldinstance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('newcmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('newinstance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); - - // Adding keys to table assignment_upgrade. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Adding indexes to table assignment_upgrade. - $table->add_index('oldcmid', XMLDB_INDEX_NOTUNIQUE, array('oldcmid')); - $table->add_index('oldinstance', XMLDB_INDEX_NOTUNIQUE, array('oldinstance')); - - // Conditionally launch create table for assignment_upgrade. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - if ($module = $DB->get_record("modules", array("name" => "assignment"))) { - $DB->set_field("modules", "visible", "0", array("id" => $module->id)); // Hide module. - } - - $count = $DB->count_records('assignment'); - if ($count) { - mod_assignment_pending_upgrades_notification($count); - } - - // Assignment savepoint reached. - upgrade_mod_savepoint(true, 2013121900, 'assignment'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_assignment_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -133,5 +35,3 @@ function xmldb_assignment_upgrade($oldversion) { return true; } - - diff --git a/mod/book/db/upgrade.php b/mod/book/db/upgrade.php index b430fefabe8e7..f55aab03cf4d2 100644 --- a/mod/book/db/upgrade.php +++ b/mod/book/db/upgrade.php @@ -34,176 +34,6 @@ function xmldb_book_upgrade($oldversion) { $dbman = $DB->get_manager(); - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - // Note: The next steps (up to 2012090408 included, are a "replay" of old upgrade steps, - // because some sites updated to Moodle 2.3 didn't have the latest contrib mod_book - // installed, so some required changes were missing. - // - // All the steps are run conditionally so sites upgraded from latest contrib mod_book or - // new (2.3 and upwards) sites won't get affected. - // - // Warn: It will be safe to delete these steps once Moodle 2.5 (not 2.4!) is declared as minimum - // requirement (environment.xml) in some future Moodle 2.x version. Never, never, before! - // - // See MDL-35297 and commit msg for more information. - - if ($oldversion < 2012090401) { - // Rename field summary on table book to intro - $table = new xmldb_table('book'); - $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name'); - - // Launch rename field summary - if ($dbman->field_exists($table, $field)) { - $dbman->rename_field($table, $field, 'intro'); - } - - // book savepoint reached - upgrade_mod_savepoint(true, 2012090401, 'book'); - } - - if ($oldversion < 2012090402) { - // Define field introformat to be added to book - $table = new xmldb_table('book'); - $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, 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 - // Si está activo el htmleditor!!!!! - if ($CFG->texteditors !== 'textarea') { - $rs = $DB->get_recordset('book', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat'); - foreach ($rs as $b) { - $b->intro = text_to_html($b->intro, false, false, true); - $b->introformat = FORMAT_HTML; - $DB->update_record('book', $b); - upgrade_set_timeout(); - } - unset($b); - $rs->close(); - } - } - - // book savepoint reached - upgrade_mod_savepoint(true, 2012090402, 'book'); - } - - if ($oldversion < 2012090403) { - // Define field introformat to be added to book - $table = new xmldb_table('book_chapters'); - $field = new xmldb_field('contentformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'content'); - - // Launch add field introformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - - $DB->set_field('book_chapters', 'contentformat', FORMAT_HTML, array()); - } - - // book savepoint reached - upgrade_mod_savepoint(true, 2012090403, 'book'); - } - - if ($oldversion < 2012090404) { - require_once("$CFG->dirroot/mod/book/db/upgradelib.php"); - - $sqlfrom = "FROM {book} b - JOIN {modules} m ON m.name = 'book' - JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = b.id)"; - - $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); - - if ($rs = $DB->get_recordset_sql("SELECT b.id, b.course, cm.id AS cmid $sqlfrom ORDER BY b.course, b.id")) { - - $pbar = new progress_bar('migratebookfiles', 500, true); - - $i = 0; - foreach ($rs as $book) { - $i++; - upgrade_set_timeout(360); // set up timeout, may also abort execution - $pbar->update($i, $count, "Migrating book files - $i/$count."); - - $context = context_module::instance($book->cmid); - - mod_book_migrate_moddata_dir_to_legacy($book, $context, '/'); - - // remove dirs if empty - @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/book/$book->id/"); - @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/book/"); - @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/"); - @rmdir("$CFG->dataroot/$book->course/"); - } - $rs->close(); - } - - // book savepoint reached - upgrade_mod_savepoint(true, 2012090404, 'book'); - } - - if ($oldversion < 2012090405) { - // Define field disableprinting to be dropped from book - $table = new xmldb_table('book'); - $field = new xmldb_field('disableprinting'); - - // Conditionally launch drop field disableprinting - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // book savepoint reached - upgrade_mod_savepoint(true, 2012090405, 'book'); - } - - if ($oldversion < 2012090406) { - unset_config('book_tocwidth'); - - // book savepoint reached - upgrade_mod_savepoint(true, 2012090406, 'book'); - } - - if ($oldversion < 2012090407) { - require_once("$CFG->dirroot/mod/book/db/upgradelib.php"); - - mod_book_migrate_all_areas(); - - upgrade_mod_savepoint(true, 2012090407, 'book'); - } - - if ($oldversion < 2012090408) { - - // Define field revision to be added to book - $table = new xmldb_table('book'); - $field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'customtitles'); - - // Conditionally launch add field revision - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // book savepoint reached - upgrade_mod_savepoint(true, 2012090408, 'book'); - } - // End of MDL-35297 "replayed" steps. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/chat/db/upgrade.php b/mod/chat/db/upgrade.php index ace39f04c1c75..37e7922385209 100644 --- a/mod/chat/db/upgrade.php +++ b/mod/chat/db/upgrade.php @@ -22,28 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -function xmldb_chat_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. +defined('MOODLE_INTERNAL') || die(); - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_chat_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -56,5 +38,3 @@ function xmldb_chat_upgrade($oldversion) { return true; } - - diff --git a/mod/choice/db/upgrade.php b/mod/choice/db/upgrade.php index 6f297c87e9529..fafd471fb8456 100644 --- a/mod/choice/db/upgrade.php +++ b/mod/choice/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014051201) { // Define field allowmultiple to be added to choice. @@ -103,5 +82,3 @@ function xmldb_choice_upgrade($oldversion) { return true; } - - diff --git a/mod/data/db/upgrade.php b/mod/data/db/upgrade.php index bde3b999c38f1..bd68fcd5770a6 100644 --- a/mod/data/db/upgrade.php +++ b/mod/data/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012112901) { - // Check if there is a directory containing any old presets. - $olddatadir = $CFG->dataroot . '/data'; - $oldpresetdir = "$olddatadir/preset"; - if (file_exists($oldpresetdir)) { - // Get directory contents. - $userfolders = new DirectoryIterator($oldpresetdir); - // Store the system context, these are site wide presets. - $context = context_system::instance(); - // Create file storage object. - $fs = get_file_storage(); - // Create array of accepted files. - $arracceptedfilenames = array('singletemplate.html', 'listtemplateheader.html', 'listtemplate.html', - 'listtemplatefooter.html', 'addtemplate.html', 'rsstemplate.html', - 'rsstitletemplate.html', 'csstemplate.css', 'jstemplate.js', - 'asearchtemplate.html', 'preset.xml'); - // Loop through all the folders, they should represent userids. - foreach ($userfolders as $userfolder) { - // If it is a file, skip it. - if ($userfolder->isFile()) { - continue; - } - // The folder name should represent the user id. - $userid = $userfolder->getFilename(); - // Skip if it is not numeric. - if (!is_numeric($userid)) { - continue; - } - // Skip if the number does not correspond to a user (does not matter if user was deleted). - if (!$DB->record_exists('user', array('id' => $userid))) { - continue; - } - // Open this folder. - $presetfolders = new DirectoryIterator("$oldpresetdir/$userid"); - foreach ($presetfolders as $presetfolder) { - // If it is a file, skip it. - if ($presetfolder->isFile()) { - continue; - } - // Save the name of the preset. - $presetname = $presetfolder->getFilename(); - // Get the files in this preset folder. - $presetfiles = new DirectoryIterator("$oldpresetdir/$userid/$presetname"); - // Now we want to get the contents of the presets. - foreach ($presetfiles as $file) { - // If it is not a file, skip it. - if (!$file->isFile()) { - continue; - } - // Set the filename. - $filename = $file->getFilename(); - // If it is not in the array of accepted file names skip it. - if (!in_array($filename, $arracceptedfilenames)) { - continue; - } - // Store the full file path. - $fullfilepath = "$oldpresetdir/$userid/$presetname/$filename"; - // Create file record. - $filerecord = array('contextid' => $context->id, - 'component' => 'mod_data', - 'filearea' => 'site_presets', - 'itemid' => 0, - 'filename' => $filename, - 'userid' => $userid); - // Check to ensure it does not already exists in the file directory. - if (!$fs->file_exists($context->id, 'mod_data', 'site_presets', 0, '/' . $presetfolder . '/', $filename)) { - $filerecord['filepath'] = '/' . $presetfolder . '/'; - } else { - $filerecord['filepath'] = '/' . $presetfolder . '_' . $userid . '_old/'; - } - $fs->create_file_from_pathname($filerecord, $fullfilepath); - // Remove the file. - @unlink($fullfilepath); - } - // Remove the preset directory. - @rmdir("$oldpresetdir/$userid/$presetname"); - } - // Remove the user directory. - @rmdir("$oldpresetdir/$userid"); - } - // Remove the final directories. - @rmdir("$oldpresetdir"); - @rmdir("$olddatadir"); - } - - upgrade_mod_savepoint(true, 2012112901, 'data'); - } - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/feedback/db/upgrade.php b/mod/feedback/db/upgrade.php index ea8d27557b218..6733a3452d525 100644 --- a/mod/feedback/db/upgrade.php +++ b/mod/feedback/db/upgrade.php @@ -34,32 +34,10 @@ // Please do not forget to use upgrade_set_timeout() // before any action that may take longer time to finish. -function xmldb_feedback_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this +defined('MOODLE_INTERNAL') || die(); - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_feedback_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -72,5 +50,3 @@ function xmldb_feedback_upgrade($oldversion) { return true; } - - diff --git a/mod/folder/db/upgrade.php b/mod/folder/db/upgrade.php index 85ef365615df2..530b818106db5 100644 --- a/mod/folder/db/upgrade.php +++ b/mod/folder/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2013012100) { - - // Define field display to be added to folder - $table = new xmldb_table('folder'); - $field = new xmldb_field('display', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'timemodified'); - - // Conditionally launch add field display - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // folder savepoint reached - upgrade_mod_savepoint(true, 2013012100, 'folder'); - } - - if ($oldversion < 2013031500) { - - // Define field showexpanded to be added to folder - $table = new xmldb_table('folder'); - $field = new xmldb_field('showexpanded', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'revision'); - - // Conditionally launch add field showexpanded - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // folder savepoint reached - upgrade_mod_savepoint(true, 2013031500, 'folder'); - } - - // Rename show_expanded to showexpanded (see MDL-38646). - if ($oldversion < 2013040700) { - - // Rename site config setting. - $showexpanded = get_config('folder', 'show_expanded'); - set_config('showexpanded', $showexpanded, 'folder'); - set_config('show_expanded', null, 'folder'); - - // Rename table column. - $table = new xmldb_table('folder'); - $field = new xmldb_field('show_expanded', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'revision'); - if ($dbman->field_exists($table, $field)) { - $dbman->rename_field($table, $field, 'showexpanded'); - } - - // folder savepoint reached - upgrade_mod_savepoint(true, 2013040700, 'folder'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index a3e8fd370578d..218f527a7e630 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); // Loads ddl manager and xmldb classes. - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013020500) { - - // Define field displaywordcount to be added to forum. - $table = new xmldb_table('forum'); - $field = new xmldb_field('displaywordcount', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'completionposts'); - - // Conditionally launch add field displaywordcount. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Forum savepoint reached. - upgrade_mod_savepoint(true, 2013020500, 'forum'); - } - - // Forcefully assign mod/forum:allowforcesubscribe to frontpage role, as we missed that when - // capability was introduced. - if ($oldversion < 2013021200) { - // If capability mod/forum:allowforcesubscribe is defined then set it for frontpage role. - if (get_capability_info('mod/forum:allowforcesubscribe')) { - assign_legacy_capabilities('mod/forum:allowforcesubscribe', array('frontpage' => CAP_ALLOW)); - } - // Forum savepoint reached. - upgrade_mod_savepoint(true, 2013021200, 'forum'); - } - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2013071000) { - // Define table forum_digests to be created. - $table = new xmldb_table('forum_digests'); - - // Adding fields to table forum_digests. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('maildigest', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '-1'); - - // Adding keys to table forum_digests. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - $table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id')); - $table->add_key('forumdigest', XMLDB_KEY_UNIQUE, array('forum', 'userid', 'maildigest')); - - // Conditionally launch create table for forum_digests. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Forum savepoint reached. - upgrade_mod_savepoint(true, 2013071000, 'forum'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2014040400) { - - // Define index userid-postid (not unique) to be dropped form forum_read. - $table = new xmldb_table('forum_read'); - $index = new xmldb_index('userid-postid', XMLDB_INDEX_NOTUNIQUE, array('userid', 'postid')); - - // Conditionally launch drop index userid-postid. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - - // Define index postid-userid (not unique) to be added to forum_read. - $index = new xmldb_index('postid-userid', XMLDB_INDEX_NOTUNIQUE, array('postid', 'userid')); - - // Conditionally launch add index postid-userid. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Forum savepoint reached. - upgrade_mod_savepoint(true, 2014040400, 'forum'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014051201) { // Incorrect values that need to be replaced. diff --git a/mod/glossary/db/upgrade.php b/mod/glossary/db/upgrade.php index 6c1e1dc7316ac..34e1d6e668361 100644 --- a/mod/glossary/db/upgrade.php +++ b/mod/glossary/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012022000) { - - // Define field approvaldisplayformat to be added to glossary - $table = new xmldb_table('glossary'); - $field = new xmldb_field('approvaldisplayformat', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, 'default', 'defaultapproval'); - - // Conditionally launch add field approvaldisplayformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // glossary savepoint reached - upgrade_mod_savepoint(true, 2012022000, 'glossary'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -88,5 +50,3 @@ function xmldb_glossary_upgrade($oldversion) { return true; } - - diff --git a/mod/imscp/db/upgrade.php b/mod/imscp/db/upgrade.php index 16cc4118f317d..e2d951531c4f5 100644 --- a/mod/imscp/db/upgrade.php +++ b/mod/imscp/db/upgrade.php @@ -29,27 +29,7 @@ * @param int $oldversion */ function xmldb_imscp_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/label/db/upgrade.php b/mod/label/db/upgrade.php index 32f93323dfafb..eda7448f29f6d 100644 --- a/mod/label/db/upgrade.php +++ b/mod/label/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2013021400) { - // find all courses that contain labels and reset their cache - $modid = $DB->get_field_sql("SELECT id FROM {modules} WHERE name=?", - array('label')); - if ($modid) { - $courses = $DB->get_fieldset_sql('SELECT DISTINCT course '. - 'FROM {course_modules} WHERE module=?', array($modid)); - foreach ($courses as $courseid) { - rebuild_course_cache($courseid, true); - } - } - - // label savepoint reached - upgrade_mod_savepoint(true, 2013021400, 'label'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -98,5 +58,3 @@ function xmldb_label_upgrade($oldversion) { return true; } - - diff --git a/mod/lesson/db/upgrade.php b/mod/lesson/db/upgrade.php index b0ca176fded82..277db095e323c 100644 --- a/mod/lesson/db/upgrade.php +++ b/mod/lesson/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014091001) { $table = new xmldb_table('lesson'); $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name'); diff --git a/mod/lti/db/upgrade.php b/mod/lti/db/upgrade.php index 21286992e088f..dc2418c32a38b 100644 --- a/mod/lti/db/upgrade.php +++ b/mod/lti/db/upgrade.php @@ -65,24 +65,6 @@ function xmldb_lti_upgrade($oldversion) { $dbman = $DB->get_manager(); - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014060201) { // Changing type of field grade on table lti to int. @@ -199,4 +181,3 @@ function xmldb_lti_upgrade($oldversion) { return true; } - diff --git a/mod/page/db/upgrade.php b/mod/page/db/upgrade.php index 5a6d42b9afaec..9691188bfdcae 100644 --- a/mod/page/db/upgrade.php +++ b/mod/page/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/quiz/db/upgrade.php b/mod/quiz/db/upgrade.php index c8cebfacda074..c8590e38ffec9 100644 --- a/mod/quiz/db/upgrade.php +++ b/mod/quiz/db/upgrade.php @@ -22,10 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Quiz module upgrade function. * @param string $oldversion the version we are upgrading from. @@ -35,746 +33,6 @@ function xmldb_quiz_upgrade($oldversion) { $dbman = $DB->get_manager(); - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2011120700) { - - // Define field lastcron to be dropped from quiz_reports. - $table = new xmldb_table('quiz_reports'); - $field = new xmldb_field('lastcron'); - - // Conditionally launch drop field lastcron. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2011120700, 'quiz'); - } - - if ($oldversion < 2011120701) { - - // Define field cron to be dropped from quiz_reports. - $table = new xmldb_table('quiz_reports'); - $field = new xmldb_field('cron'); - - // Conditionally launch drop field cron. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2011120701, 'quiz'); - } - - if ($oldversion < 2011120703) { - // Track page of quiz attempts. - $table = new xmldb_table('quiz_attempts'); - - $field = new xmldb_field('currentpage', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_mod_savepoint(true, 2011120703, 'quiz'); - } - - if ($oldversion < 2012030901) { - // Configuration option for navigation method. - $table = new xmldb_table('quiz'); - - $field = new xmldb_field('navmethod', XMLDB_TYPE_CHAR, '16', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 'free'); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_mod_savepoint(true, 2012030901, 'quiz'); - } - - if ($oldversion < 2012040198) { - // This step was added later. In MDL-32727, it was found that adding the - // unique index on quiz-userid-attempt sometimes failed because of - // duplicate entries {quizid}-{userid}-{attempt}. We do two things to - // prevent these problems. First, here, we delete all preview attempts. - - // This code is an approximate copy-and-paste from - // question_engine_data_mapper::delete_questions_usage_by_activities - // Note that, for simplicity, the MySQL performance hack has been removed. - // Since this code is for upgrade only, performance in not so critical, - // where as simplicity of testing the code is. - - // Note that there is a limit to how far I am prepared to go in eliminating - // all calls to library functions in this upgrade code. The only library - // function still being used in question_engine::get_all_response_file_areas(); - // I think it is pretty safe not to inline it here. - - // Get a list of response variables that have files. - require_once($CFG->dirroot . '/question/type/questiontypebase.php'); - $variables = array(); - foreach (core_component::get_plugin_list('qtype') as $qtypename => $path) { - $file = $path . '/questiontype.php'; - if (!is_readable($file)) { - continue; - } - include_once($file); - $class = 'qtype_' . $qtypename; - if (!class_exists($class)) { - continue; - } - $qtype = new $class(); - if (!method_exists($qtype, 'response_file_areas')) { - continue; - } - $variables += $qtype->response_file_areas(); - } - - // Conver that to a list of actual file area names. - $fileareas = array(); - foreach (array_unique($variables) as $variable) { - $fileareas[] = 'response_' . $variable; - } - // No point checking if this is empty as an optimisation, because essay - // has response file areas, so the array will never be empty. - - // Get all the contexts where there are previews. - $contextids = $DB->get_records_sql_menu(" - SELECT DISTINCT qu.contextid, 1 - FROM {question_usages} qu - JOIN {quiz_attempts} quiza ON quiza.uniqueid = qu.id - WHERE quiza.preview = 1"); - - // Loop over contexts and files areas, deleting all files. - $fs = get_file_storage(); - foreach ($contextids as $contextid => $notused) { - foreach ($fileareas as $filearea) { - upgrade_set_timeout(300); - $fs->delete_area_files_select($contextid, 'question', $filearea, - "IN (SELECT qas.id - FROM {question_attempt_steps} qas - JOIN {question_attempts} qa ON qa.id = qas.questionattemptid - JOIN {quiz_attempts} quiza ON quiza.uniqueid = qa.questionusageid - WHERE quiza.preview = 1)"); - } - } - - // Now delete the question data associated with the previews. - $DB->delete_records_select('question_attempt_step_data', "attemptstepid IN ( - SELECT qas.id - FROM {question_attempt_steps} qas - JOIN {question_attempts} qa ON qa.id = qas.questionattemptid - JOIN {quiz_attempts} quiza ON quiza.uniqueid = qa.questionusageid - WHERE quiza.preview = 1)"); - - $DB->delete_records_select('question_attempt_steps', "questionattemptid IN ( - SELECT qa.id - FROM {question_attempts} qa - JOIN {quiz_attempts} quiza ON quiza.uniqueid = qa.questionusageid - WHERE quiza.preview = 1)"); - - $DB->delete_records_select('question_attempts', "{question_attempts}.questionusageid IN ( - SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); - - $DB->delete_records_select('question_usages', "{question_usages}.id IN ( - SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); - - // Finally delete the previews. - $DB->delete_records('quiz_attempts', array('preview' => 1)); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040198, 'quiz'); - } - - if ($oldversion < 2012040199) { - // This step was added later. In MDL-32727, it was found that adding the - // unique index on quiz-userid-attempt sometimes failed because of - // duplicate entries {quizid}-{userid}-{attempt}. - // Here, if there are still duplicate entires, we renumber the values in - // the attempt column. - - // Load all the problem quiz attempts. - $problems = $DB->get_recordset_sql(' - SELECT qa.id, qa.quiz, qa.userid, qa.attempt - FROM {quiz_attempts} qa - JOIN ( - SELECT DISTINCT quiz, userid - FROM {quiz_attempts} - GROUP BY quiz, userid, attempt - HAVING COUNT(1) > 1 - ) problems_view ON problems_view.quiz = qa.quiz AND - problems_view.userid = qa.userid - ORDER BY qa.quiz, qa.userid, qa.attempt, qa.id'); - - // Renumber them. - $currentquiz = null; - $currentuserid = null; - $attempt = 1; - foreach ($problems as $problem) { - if ($problem->quiz !== $currentquiz || $problem->userid !== $currentuserid) { - $currentquiz = $problem->quiz; - $currentuserid = $problem->userid; - $attempt = 1; - } - if ($attempt != $problem->attempt) { - $DB->set_field('quiz_attempts', 'attempt', $attempt, array('id' => $problem->id)); - } - $attempt += 1; - } - - $problems->close(); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040199, 'quiz'); - } - - if ($oldversion < 2012040200) { - // Define index userid to be dropped form quiz_attempts. - $table = new xmldb_table('quiz_attempts'); - $index = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); - - // Conditionally launch drop index quiz-userid-attempt. - if ($dbman->index_exists($table, $index)) { - $dbman->drop_index($table, $index); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040200, 'quiz'); - } - - if ($oldversion < 2012040201) { - - // Define key userid (foreign) to be added to quiz_attempts. - $table = new xmldb_table('quiz_attempts'); - $key = new xmldb_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - - // Launch add key userid. - $dbman->add_key($table, $key); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040201, 'quiz'); - } - - if ($oldversion < 2012040202) { - - // Define index quiz-userid-attempt (unique) to be added to quiz_attempts. - $table = new xmldb_table('quiz_attempts'); - $index = new xmldb_index('quiz-userid-attempt', XMLDB_INDEX_UNIQUE, array('quiz', 'userid', 'attempt')); - - // Conditionally launch add index quiz-userid-attempt. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040202, 'quiz'); - } - - if ($oldversion < 2012040203) { - - // Define field state to be added to quiz_attempts. - $table = new xmldb_table('quiz_attempts'); - $field = new xmldb_field('state', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, 'inprogress', 'preview'); - - // Conditionally launch add field state. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040203, 'quiz'); - } - - if ($oldversion < 2012040204) { - - // Update quiz_attempts.state for finished attempts. - $DB->set_field_select('quiz_attempts', 'state', 'finished', 'timefinish > 0'); - - // Other, more complex transitions (basically abandoned attempts), will - // be handled by cron later. - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040204, 'quiz'); - } - - if ($oldversion < 2012040205) { - - // Define field overduehandling to be added to quiz. - $table = new xmldb_table('quiz'); - $field = new xmldb_field('overduehandling', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, 'autoabandon', 'timelimit'); - - // Conditionally launch add field overduehandling. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040205, 'quiz'); - } - - if ($oldversion < 2012040206) { - - // Define field graceperiod to be added to quiz. - $table = new xmldb_table('quiz'); - $field = new xmldb_field('graceperiod', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'overduehandling'); - - // Conditionally launch add field graceperiod. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012040206, 'quiz'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - if ($oldversion < 2012061702) { - - // MDL-32791 somebody reported having nonsense rows in their - // quiz_question_instances which caused various problems. These rows - // are meaningless, hence this upgrade step to clean them up. - $DB->delete_records('quiz_question_instances', array('question' => 0)); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012061702, 'quiz'); - } - - if ($oldversion < 2012061703) { - - // MDL-34702 the questiondecimalpoints column was created with default -2 - // when it should have been -1, and no-one has noticed in the last 2+ years! - - // Changing the default of field questiondecimalpoints on table quiz to -1. - $table = new xmldb_table('quiz'); - $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '-1', 'decimalpoints'); - - // Launch change of default for field questiondecimalpoints. - $dbman->change_field_default($table, $field); - - // Correct any wrong values. - $DB->set_field('quiz', 'questiondecimalpoints', -1, array('questiondecimalpoints' => -2)); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2012061703, 'quiz'); - } - - if ($oldversion < 2012100801) { - - // Define field timecheckstate to be added to quiz_attempts. - $table = new xmldb_table('quiz_attempts'); - $field = new xmldb_field('timecheckstate', XMLDB_TYPE_INTEGER, '10', null, null, null, '0', 'timemodified'); - - // Conditionally launch add field timecheckstate. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define index state-timecheckstate (not unique) to be added to quiz_attempts. - $table = new xmldb_table('quiz_attempts'); - $index = new xmldb_index('state-timecheckstate', XMLDB_INDEX_NOTUNIQUE, array('state', 'timecheckstate')); - - // Conditionally launch add index state-timecheckstate. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Overdue cron no longer needs these. - unset_config('overduelastrun', 'quiz'); - unset_config('overduedoneto', 'quiz'); - - // Update timecheckstate on all open attempts. - require_once($CFG->dirroot . '/mod/quiz/locallib.php'); - quiz_update_open_attempts(array()); - - // quiz savepoint reached - upgrade_mod_savepoint(true, 2012100801, 'quiz'); - } - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - if ($oldversion < 2013031900) { - // Quiz manual grading UI should be controlled by mod/quiz:grade, not :viewreports. - $DB->set_field('quiz_reports', 'capability', 'mod/quiz:grade', array('name' => 'grading')); - - // Mod quiz savepoint reached. - upgrade_mod_savepoint(true, 2013031900, 'quiz'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2014011300) { - - // Define key quiz (foreign) to be dropped form quiz_question_instances. - $table = new xmldb_table('quiz_question_instances'); - $key = new xmldb_key('quiz', XMLDB_KEY_FOREIGN, array('quiz'), 'quiz', array('id')); - - // Launch drop key quiz. - $dbman->drop_key($table, $key); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014011300, 'quiz'); - } - - if ($oldversion < 2014011301) { - - // Rename field quiz on table quiz_question_instances to quizid. - $table = new xmldb_table('quiz_question_instances'); - $field = new xmldb_field('quiz', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - - // Launch rename field quiz. - $dbman->rename_field($table, $field, 'quizid'); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014011301, 'quiz'); - } - - if ($oldversion < 2014011302) { - - // Define key quizid (foreign) to be added to quiz_question_instances. - $table = new xmldb_table('quiz_question_instances'); - $key = new xmldb_key('quizid', XMLDB_KEY_FOREIGN, array('quizid'), 'quiz', array('id')); - - // Launch add key quizid. - $dbman->add_key($table, $key); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014011302, 'quiz'); - } - - if ($oldversion < 2014011303) { - - // Define key question (foreign) to be dropped form quiz_question_instances. - $table = new xmldb_table('quiz_question_instances'); - $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - - // Launch drop key question. - $dbman->drop_key($table, $key); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014011303, 'quiz'); - } - - if ($oldversion < 2014011304) { - - // Rename field question on table quiz_question_instances to questionid. - $table = new xmldb_table('quiz_question_instances'); - $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'quiz'); - - // Launch rename field question. - $dbman->rename_field($table, $field, 'questionid'); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014011304, 'quiz'); - } - - if ($oldversion < 2014011305) { - - // Define key questionid (foreign) to be added to quiz_question_instances. - $table = new xmldb_table('quiz_question_instances'); - $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id')); - - // Launch add key questionid. - $dbman->add_key($table, $key); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014011305, 'quiz'); - } - - if ($oldversion < 2014011306) { - - // Rename field grade on table quiz_question_instances to maxmark. - $table = new xmldb_table('quiz_question_instances'); - $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question'); - - // Launch rename field grade. - $dbman->rename_field($table, $field, 'maxmark'); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014011306, 'quiz'); - } - - if ($oldversion < 2014021300) { - - // Define field needsupgradetonewqe to be dropped from quiz_attempts. - $table = new xmldb_table('quiz_attempts'); - $field = new xmldb_field('needsupgradetonewqe'); - - // Conditionally launch drop field needsupgradetonewqe. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014021300, 'quiz'); - } - - if ($oldversion < 2014022000) { - - // Define table quiz_question_instances to be renamed to quiz_slots. - $table = new xmldb_table('quiz_question_instances'); - - // Launch rename table for quiz_question_instances. - $dbman->rename_table($table, 'quiz_slots'); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022000, 'quiz'); - } - - if ($oldversion < 2014022001) { - - // Define field slot to be added to quiz_slots. - $table = new xmldb_table('quiz_slots'); - $field = new xmldb_field('slot', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'id'); - - // Conditionally launch add field slot. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022001, 'quiz'); - } - - if ($oldversion < 2014022002) { - - // Define field page to be added to quiz_slots. - $table = new xmldb_table('quiz_slots'); - $field = new xmldb_field('page', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'quizid'); - - // Conditionally launch add field page. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022002, 'quiz'); - } - - if ($oldversion < 2014022003) { - - // Use the information in the old quiz.questions column to fill in the - // new slot and page columns. - $numquizzes = $DB->count_records('quiz'); - if ($numquizzes > 0) { - $pbar = new progress_bar('quizquestionstoslots', 500, true); - $transaction = $DB->start_delegated_transaction(); - - $numberdone = 0; - $quizzes = $DB->get_recordset('quiz', null, 'id', 'id,questions,sumgrades'); - foreach ($quizzes as $quiz) { - if ($quiz->questions === '') { - $questionsinorder = array(); - } else { - $questionsinorder = explode(',', $quiz->questions); - } - - $questionidtoslotrowid = $DB->get_records_menu('quiz_slots', - array('quizid' => $quiz->id), '', 'id, questionid'); - - $problemfound = false; - $currentpage = 1; - $slot = 1; - foreach ($questionsinorder as $questionid) { - if ($questionid === '0') { - // Page break. - $currentpage++; - continue; - } - - if ($questionid === '') { - // This can happen as the result of old restore bugs. - // There can be a missing number in the list of ids. - // All we can do about this is ignore it, which is what - // the quiz system used to do. See MDL-45321. - continue; - } - - $key = array_search($questionid, $questionidtoslotrowid); - if ($key !== false) { - // Normal case. quiz_slots entry is present. - // Just need to add slot and page. - $quizslot = new stdClass(); - $quizslot->id = $key; - $quizslot->slot = $slot; - $quizslot->page = $currentpage; - $DB->update_record('quiz_slots', $quizslot); - - unset($questionidtoslotrowid[$key]); // So we can do a sanity check later. - $slot++; - continue; - - } else { - // This should not happen. The question was listed in - // quiz.questions, but there was not an entry for it in - // quiz_slots (formerly quiz_question_instances). - // Previously, if such question ids were found, then - // starting an attempt at the quiz would throw an exception. - // Here, we try to add the missing data. - $problemfound = true; - $defaultmark = $DB->get_field('question', 'defaultmark', - array('id' => $questionid), IGNORE_MISSING); - if ($defaultmark === false) { - debugging('During upgrade, detected that question ' . - $questionid . ' was listed as being part of quiz ' . - $quiz->id . ' but this question no longer exists. Ignoring it.', DEBUG_NORMAL); - - // Non-existent question. Ignore it completely. - continue; - } - - debugging('During upgrade, detected that question ' . - $questionid . ' was listed as being part of quiz ' . - $quiz->id . ' but there was not entry for it in ' . - 'quiz_question_instances/quiz_slots. Creating an entry with default mark.', DEBUG_NORMAL); - $quizslot = new stdClass(); - $quizslot->quizid = $quiz->id; - $quizslot->slot = $slot; - $quizslot->page = $currentpage; - $quizslot->questionid = $questionid; - $quizslot->maxmark = $defaultmark; - $DB->insert_record('quiz_slots', $quizslot); - - $slot++; - continue; - } - - } - - // Now, as a sanity check, ensure we have done all the - // quiz_slots rows linked to this quiz. - if (!empty($questionidtoslotrowid)) { - debugging('During upgrade, detected that questions ' . - implode(', ', array_values($questionidtoslotrowid)) . - ' had instances in quiz ' . $quiz->id . ' but were not actually used. ' . - 'The instances have been removed.', DEBUG_NORMAL); - - $DB->delete_records_list('quiz_slots', 'id', array_keys($questionidtoslotrowid)); - $problemfound = true; - } - - // If there were problems found, we probably need to re-compute - // quiz.sumgrades. - if ($problemfound) { - // C/f the quiz_update_sumgrades function in locallib.php, - // but note that what we do here is a bit simpler. - $newsumgrades = $DB->get_field_sql( - "SELECT SUM(maxmark) - FROM {quiz_slots} - WHERE quizid = ?", - array($quiz->id)); - if (!$newsumgrades) { - $newsumgrades = 0; - } - if (abs($newsumgrades - $quiz->sumgrades) > 0.000005) { - debugging('Because of the previously mentioned problems, ' . - 'sumgrades for quiz ' . $quiz->id . - ' was changed from ' . $quiz->sumgrades . ' to ' . - $newsumgrades . ' You should probably check that this quiz is still working: ' . - $CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id . '.', DEBUG_NORMAL); - $DB->set_field('quiz', 'sumgrades', $newsumgrades, array('id' => $quiz->id)); - } - } - - // Done with this quiz. Update progress bar. - $numberdone++; - $pbar->update($numberdone, $numquizzes, - "Upgrading quiz structure - {$numberdone}/{$numquizzes}."); - } - - $transaction->allow_commit(); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022003, 'quiz'); - } - - if ($oldversion < 2014022004) { - - // If, for any reason, there were any quiz_slots missed, then try - // to do something about that now before we add the NOT NULL constraints. - // In fact, becuase of the sanity check at the end of the above check, - // any such quiz_slots rows must refer to a non-existent quiz id, so - // delete them. - $DB->delete_records_select('quiz_slots', - 'NOT EXISTS (SELECT 1 FROM {quiz} q WHERE q.id = quizid)'); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022004, 'quiz'); - - // Now, if any quiz_slots rows are left with slot or page NULL, something - // is badly wrong. - if ($DB->record_exists_select('quiz_slots', 'slot IS NULL OR page IS NULL')) { - throw new coding_exception('Something went wrong in the quiz upgrade step for MDL-43749. ' . - 'Some quiz_slots still contain NULLs which will break the NOT NULL constraints we need to add. ' . - 'Please report this problem at http://tracker.moodle.org/ so that it can be investigated. Thank you.'); - } - } - - if ($oldversion < 2014022005) { - - // Changing nullability of field slot on table quiz_slots to not null. - $table = new xmldb_table('quiz_slots'); - $field = new xmldb_field('slot', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); - - // Launch change of nullability for field slot. - $dbman->change_field_notnull($table, $field); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022005, 'quiz'); - } - - if ($oldversion < 2014022006) { - - // Changing nullability of field page on table quiz_slots to not null. - $table = new xmldb_table('quiz_slots'); - $field = new xmldb_field('page', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'quizid'); - - // Launch change of nullability for field page. - $dbman->change_field_notnull($table, $field); - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022006, 'quiz'); - } - - if ($oldversion < 2014022007) { - - // Define index quizid-slot (unique) to be added to quiz_slots. - $table = new xmldb_table('quiz_slots'); - $index = new xmldb_index('quizid-slot', XMLDB_INDEX_UNIQUE, array('quizid', 'slot')); - - // Conditionally launch add index quizid-slot. - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022007, 'quiz'); - } - - if ($oldversion < 2014022008) { - - // Define field questions to be dropped from quiz. - $table = new xmldb_table('quiz'); - $field = new xmldb_field('questions'); - - // Conditionally launch drop field questions. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Quiz savepoint reached. - upgrade_mod_savepoint(true, 2014022008, 'quiz'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014052800) { // Define field completionattemptsexhausted to be added to quiz. diff --git a/mod/quiz/report/overview/db/upgrade.php b/mod/quiz/report/overview/db/upgrade.php index 73ed1de86d1b0..ad1e1b41e1ab6 100644 --- a/mod/quiz/report/overview/db/upgrade.php +++ b/mod/quiz/report/overview/db/upgrade.php @@ -22,39 +22,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Quiz overview report upgrade function. * @param number $oldversion */ function xmldb_quiz_overview_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/quiz/report/statistics/db/upgrade.php b/mod/quiz/report/statistics/db/upgrade.php index b589b21920339..6664071528f36 100644 --- a/mod/quiz/report/statistics/db/upgrade.php +++ b/mod/quiz/report/statistics/db/upgrade.php @@ -28,113 +28,7 @@ * Quiz statistics report upgrade code. */ function xmldb_quiz_statistics_upgrade($oldversion) { - global $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013092000) { - - // Define table question_statistics to be dropped. - $table = new xmldb_table('quiz_question_statistics'); - - // Conditionally launch drop table for question_statistics. - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - // Define table question_response_analysis to be dropped. - $table = new xmldb_table('quiz_question_response_stats'); - - // Conditionally launch drop table for question_response_analysis. - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - $table = new xmldb_table('quiz_statistics'); - $field = new xmldb_field('quizid'); - - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('groupid'); - - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - $field = new xmldb_field('hashcode', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id'); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_plugin_savepoint(true, 2013092000, 'quiz', 'statistics'); - } - - if ($oldversion < 2013093000) { - // Define table quiz_statistics to be dropped. - $table = new xmldb_table('quiz_statistics'); - - // Conditionally launch drop table for quiz_statistics. - if ($dbman->table_exists($table)) { - $dbman->drop_table($table); - } - - // Define table quiz_statistics to be created. - $table = new xmldb_table('quiz_statistics'); - - // Adding fields to table quiz_statistics. - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('hashcode', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); - $table->add_field('whichattempts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('firstattemptscount', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('highestattemptscount', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('lastattemptscount', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('allattemptscount', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_field('firstattemptsavg', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('highestattemptsavg', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('lastattemptsavg', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('allattemptsavg', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('median', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('standarddeviation', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('skewness', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); - $table->add_field('kurtosis', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); - $table->add_field('cic', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); - $table->add_field('errorratio', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); - $table->add_field('standarderror', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); - - // Adding keys to table quiz_statistics. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - - // Conditionally launch create table for quiz_statistics. - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // Statistics savepoint reached. - upgrade_plugin_savepoint(true, 2013093000, 'quiz', 'statistics'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -147,4 +41,3 @@ function xmldb_quiz_statistics_upgrade($oldversion) { return true; } - diff --git a/mod/resource/db/upgrade.php b/mod/resource/db/upgrade.php index 972d232c58f9a..f490b910ca7cc 100644 --- a/mod/resource/db/upgrade.php +++ b/mod/resource/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/scorm/db/upgrade.php b/mod/scorm/db/upgrade.php index 7d51db1dc3249..c92643034ce02 100644 --- a/mod/scorm/db/upgrade.php +++ b/mod/scorm/db/upgrade.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); /** * @global moodle_database $DB @@ -33,252 +34,6 @@ function xmldb_scorm_upgrade($oldversion) { $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012032100) { - unset_config('updatetime', 'scorm'); - upgrade_mod_savepoint(true, 2012032100, 'scorm'); - } - - // Adding completion fields to scorm table - if ($oldversion < 2012032101) { - $table = new xmldb_table('scorm'); - - $field = new xmldb_field('completionstatusrequired', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, 'timemodified'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('completionscorerequired', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, null, 'completionstatusrequired'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint(true, 2012032101, 'scorm'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - //rename config var from maxattempts to maxattempt - if ($oldversion < 2012061701) { - $maxattempts = get_config('scorm', 'maxattempts'); - $maxattempts_adv = get_config('scorm', 'maxattempts_adv'); - set_config('maxattempt', $maxattempts, 'scorm'); - set_config('maxattempt_adv', $maxattempts_adv, 'scorm'); - - unset_config('maxattempts', 'scorm'); //remove old setting. - unset_config('maxattempts_adv', 'scorm'); //remove old setting. - upgrade_mod_savepoint(true, 2012061701, 'scorm'); - } - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Remove old imsrepository type - convert any existing records to external type to help prevent major errors. - if ($oldversion < 2013081301) { - require_once($CFG->dirroot . '/mod/scorm/lib.php'); - $scorms = $DB->get_recordset('scorm', array('scormtype' => 'imsrepository')); - foreach ($scorms as $scorm) { - $scorm->scormtype = SCORM_TYPE_EXTERNAL; - if (!empty($CFG->repository)) { // Fix path to imsmanifest if $CFG->repository is set. - $scorm->reference = $CFG->repository.substr($scorm->reference, 1).'/imsmanifest.xml'; - $scorm->sha1hash = sha1($scorm->reference); - } - $scorm->revision++; - $DB->update_record('scorm', $scorm); - } - upgrade_mod_savepoint(true, 2013081301, 'scorm'); - } - - // Fix AICC parent/child relationships (MDL-37394). - if ($oldversion < 2013081302) { - // Get all AICC packages. - $aiccpackages = $DB->get_recordset('scorm', array('version' => 'AICC'), '', 'id'); - foreach ($aiccpackages as $aicc) { - $sql = "UPDATE {scorm_scoes} - SET parent = organization - WHERE scorm = ? - AND " . $DB->sql_isempty('scorm_scoes', 'manifest', false, false) . " - AND " . $DB->sql_isnotempty('scorm_scoes', 'organization', false, false) . " - AND parent = '/'"; - $DB->execute($sql, array($aicc->id)); - } - $aiccpackages->close(); - upgrade_mod_savepoint(true, 2013081302, 'scorm'); - } - - if ($oldversion < 2013081303) { - - // Define field sortorder to be added to scorm_scoes. - $table = new xmldb_table('scorm_scoes'); - $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'title'); - - // Conditionally launch add field sortorder. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Scorm savepoint reached. - upgrade_mod_savepoint(true, 2013081303, 'scorm'); - } - - if ($oldversion < 2013090100) { - global $CFG; - $table = new xmldb_table('scorm'); - - $field = new xmldb_field('nav', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, true, null, 1, 'hidetoc'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('navpositionleft', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, -100, 'nav'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('navpositiontop', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, -100, 'navpositionleft'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('hidenav'); - if ($dbman->field_exists($table, $field)) { - // Update nav setting to show floating navigation buttons under TOC. - $DB->set_field('scorm', 'nav', 2, array('hidenav' => 0)); - $DB->set_field('scorm', 'navpositionleft', 215, array('hidenav' => 2)); - $DB->set_field('scorm', 'navpositiontop', 300, array('hidenav' => 2)); - - // Update nav setting to disable navigation buttons. - $DB->set_field('scorm', 'nav', 0, array('hidenav' => 1)); - // Drop hidenav field. - $dbman->drop_field($table, $field); - } - - $hide = get_config('scorm', 'hidenav'); - unset_config('hidenav', 'scorm'); - if (!empty($hide)) { - require_once($CFG->dirroot . '/mod/scorm/lib.php'); - set_config('nav', SCORM_NAV_DISABLED, 'scorm'); - } - - $hideadv = get_config('scorm', 'hidenav_adv'); - unset_config('hidenav_adv', 'scorm'); - set_config('nav_adv', $hideadv, 'scorm'); - - upgrade_mod_savepoint(true, 2013090100, 'scorm'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013110501) { - // Fix invalid $scorm->launch records. - // Get all scorms that have a launch value that references a sco from a different scorm. - $sql = "SELECT s.* - FROM {scorm} s - LEFT JOIN {scorm_scoes} c ON s.launch = c.id - WHERE c.id IS null OR s.id <> c.scorm"; - $scorms = $DB->get_recordset_sql($sql); - foreach ($scorms as $scorm) { - // Find the first launchable sco for this SCORM. - // This scorm has an invalid launch param - we need to calculate it and get the first launchable sco. - $sqlselect = 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true); - // We use get_records here as we need to pass a limit in the query that works cross db. - $scoes = $DB->get_records_select('scorm_scoes', $sqlselect, array($scorm->id), 'sortorder', 'id', 0, 1); - if (!empty($scoes)) { - $sco = reset($scoes); // We only care about the first record - the above query only returns one. - $scorm->launch = $sco->id; - $DB->update_record('scorm', $scorm); - } - } - $scorms->close(); - - upgrade_mod_savepoint(true, 2013110501, 'scorm'); - } - - if ($oldversion < 2014031700) { - // Define field displayactivityname to be added to scorm. - $table = new xmldb_table('scorm'); - $field = new xmldb_field( - 'displayactivityname', - XMLDB_TYPE_INTEGER, - '4', - null, - XMLDB_NOTNULL, - null, - '1', - 'completionscorerequired' - ); - - // Conditionally launch add field displayactivityname. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Scorm savepoint reached. - upgrade_mod_savepoint(true, 2014031700, 'scorm'); - } - - if ($oldversion < 2014040200) { - // Fix invalid $scorm->launch records that launch an org sco instead of a real sco. - $sql = "SELECT s.*, c.identifier - FROM {scorm} s - LEFT JOIN {scorm_scoes} c ON s.launch = c.id - WHERE ".$DB->sql_isempty('scorm_scoes', 'c.launch', false, true); - $scorms = $DB->get_recordset_sql($sql); - foreach ($scorms as $scorm) { - upgrade_set_timeout(60); // Increase execution time just in case. (60 sec is minimum but prob excessive here). - $originallaunch = $scorm->launch; - // Find the first sco using the current identifier as it's parent - // we use get records here as we need to pass a limit in the query that works cross db. - $firstsco = $DB->get_records('scorm_scoes', - array('scorm' => $scorm->id, 'parent' => $scorm->identifier), 'sortorder', '*', 0, 1); - if (!empty($firstsco)) { - $firstsco = reset($firstsco); - } - if (!empty($firstsco->launch)) { - // Usual behavior - this is a valid sco with a launch param so use it. - $scorm->launch = $firstsco->id; - } else { - // The firstsco found is not launchable - find the first launchable sco after this sco. - $sqlselect = 'scorm = ? AND sortorder > ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true); - // We use get_records here as we need to pass a limit in the query that works cross db. - $scoes = $DB->get_records_select('scorm_scoes', $sqlselect, - array($scorm->id, $firstsco->sortorder), 'sortorder', 'id', 0, 1); - if (!empty($scoes)) { - $sco = reset($scoes); // We only care about the first record - the above query only returns one. - $scorm->launch = $sco->id; - } else { - // This is an invalid package - it has a default org that doesn't contain a launchable sco. - // Check for any valid sco with a launch param. - $sqlselect = 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true); - // We use get_records here as we need to pass a limit in the query that works cross db. - $scoes = $DB->get_records_select('scorm_scoes', $sqlselect, array($scorm->id), 'sortorder', 'id', 0, 1); - if (!empty($scoes)) { - $sco = reset($scoes); // We only care about the first record - the above query only returns one. - $scorm->launch = $sco->id; - } - } - } - if ($originallaunch != $scorm->launch) { - $DB->update_record('scorm', $scorm); - } - } - $scorms->close(); - - upgrade_mod_savepoint(true, 2014040200, 'scorm'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014072500) { // Define field autocommit to be added to scorm. @@ -340,5 +95,3 @@ function xmldb_scorm_upgrade($oldversion) { return true; } - - diff --git a/mod/survey/db/upgrade.php b/mod/survey/db/upgrade.php index 1af7efc9937ff..53686fd630013 100644 --- a/mod/survey/db/upgrade.php +++ b/mod/survey/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - +defined('MOODLE_INTERNAL') || die(); - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_survey_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -58,5 +35,3 @@ function xmldb_survey_upgrade($oldversion) { return true; } - - diff --git a/mod/url/db/upgrade.php b/mod/url/db/upgrade.php index ea2470e41f775..6e7a7d330f7b1 100644 --- a/mod/url/db/upgrade.php +++ b/mod/url/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/wiki/db/upgrade.php b/mod/wiki/db/upgrade.php index 2b1f1d00a5259..2614baa0349b9 100644 --- a/mod/wiki/db/upgrade.php +++ b/mod/wiki/db/upgrade.php @@ -1,5 +1,4 @@ . +// along with Moodle. If not, see . /** * This file keeps track of upgrades to the wiki module @@ -36,53 +35,10 @@ * */ -function xmldb_wiki_upgrade($oldversion) { - global $CFG, $DB, $OUTPUT; - - $dbman = $DB->get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012061701) { - // Drop all legacy upgrade tables, not used anymore. - - $table = new xmldb_table('wiki_entries_old'); - if ($dbman->table_exists('wiki_entries_old')) { - $dbman->drop_table($table); - } - - $table = new xmldb_table('wiki_locks_old'); - if ($dbman->table_exists('wiki_locks_old')) { - $dbman->drop_table($table); - } - - $table = new xmldb_table('wiki_pages_old'); - if ($dbman->table_exists('wiki_pages_old')) { - $dbman->drop_table($table); - } - - upgrade_plugin_savepoint(true, 2012061701, 'mod', 'wiki'); - } +defined('MOODLE_INTERNAL') || die(); - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. +function xmldb_wiki_upgrade($oldversion) { + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/workshop/db/upgrade.php b/mod/workshop/db/upgrade.php index 168f980fe6bd2..99acfbd7eae07 100644 --- a/mod/workshop/db/upgrade.php +++ b/mod/workshop/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - // Moodle v2.2.0 release upgrade line - - if ($oldversion < 2012033100) { - // add the field 'phaseswitchassessment' to the 'workshop' table - $table = new xmldb_table('workshop'); - $field = new xmldb_field('phaseswitchassessment', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'assessmentend'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_mod_savepoint(true, 2012033100, 'workshop'); - } - - /** - * Remove all workshop calendar events - */ - if ($oldversion < 2012041700) { - require_once($CFG->dirroot . '/calendar/lib.php'); - $events = $DB->get_records('event', array('modulename' => 'workshop')); - foreach ($events as $event) { - $event = calendar_event::load($event); - $event->delete(); - } - upgrade_mod_savepoint(true, 2012041700, 'workshop'); - } - - /** - * Recreate all workshop calendar events - */ - if ($oldversion < 2012041701) { - require_once(dirname(dirname(__FILE__)) . '/lib.php'); - - $sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart, - w.submissionend, w.assessmentstart, w.assessmentend, - cm.id AS cmid - FROM {workshop} w - JOIN {modules} m ON m.name = 'workshop' - JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)"; - - $rs = $DB->get_recordset_sql($sql); - - foreach ($rs as $workshop) { - $cmid = $workshop->cmid; - unset($workshop->cmid); - workshop_calendar_update($workshop, $cmid); - } - $rs->close(); - upgrade_mod_savepoint(true, 2012041701, 'workshop'); - } - - // Moodle v2.3.0 release upgrade line - - /** - * Add new fields conclusion and conclusionformat - */ - if ($oldversion < 2012102400) { - $table = new xmldb_table('workshop'); - - $field = new xmldb_field('conclusion', XMLDB_TYPE_TEXT, null, null, null, null, null, 'phaseswitchassessment'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('conclusionformat', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '1', 'conclusion'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint(true, 2012102400, 'workshop'); - } - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - /** - * Add overall feedback related fields into the workshop table. - */ - if ($oldversion < 2013032500) { - $table = new xmldb_table('workshop'); - - $field = new xmldb_field('overallfeedbackmode', XMLDB_TYPE_INTEGER, '3', null, null, null, '1', 'conclusionformat'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('overallfeedbackfiles', XMLDB_TYPE_INTEGER, '3', null, null, null, '0', 'overallfeedbackmode'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('overallfeedbackmaxbytes', XMLDB_TYPE_INTEGER, '10', null, null, null, '100000', 'overallfeedbackfiles'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint(true, 2013032500, 'workshop'); - } - - /** - * Add feedbackauthorattachment field into the workshop_assessments table. - */ - if ($oldversion < 2013032501) { - $table = new xmldb_table('workshop_assessments'); - $field = new xmldb_field('feedbackauthorattachment', XMLDB_TYPE_INTEGER, '3', null, null, null, '0', 'feedbackauthorformat'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_mod_savepoint(true, 2013032501, 'workshop'); - } - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/workshop/form/accumulative/db/upgrade.php b/mod/workshop/form/accumulative/db/upgrade.php index 7ea0333de73b4..b1cf88410fc1c 100644 --- a/mod/workshop/form/accumulative/db/upgrade.php +++ b/mod/workshop/form/accumulative/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/workshop/form/comments/db/upgrade.php b/mod/workshop/form/comments/db/upgrade.php index 3f417b02e97dd..d83a254f50971 100644 --- a/mod/workshop/form/comments/db/upgrade.php +++ b/mod/workshop/form/comments/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/workshop/form/numerrors/db/upgrade.php b/mod/workshop/form/numerrors/db/upgrade.php index f62e7350bd407..89b9d8762eaba 100644 --- a/mod/workshop/form/numerrors/db/upgrade.php +++ b/mod/workshop/form/numerrors/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/mod/workshop/form/rubric/db/upgrade.php b/mod/workshop/form/rubric/db/upgrade.php index a011f325a5d51..4bb5d599e5912 100644 --- a/mod/workshop/form/rubric/db/upgrade.php +++ b/mod/workshop/form/rubric/db/upgrade.php @@ -1,5 +1,4 @@ get_manager(); - - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/portfolio/boxnet/db/upgrade.php b/portfolio/boxnet/db/upgrade.php index 9bc76b85a0de4..af98aefa5386b 100644 --- a/portfolio/boxnet/db/upgrade.php +++ b/portfolio/boxnet/db/upgrade.php @@ -31,38 +31,7 @@ * @return bool result */ function xmldb_portfolio_boxnet_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - if ($oldversion < 2013110602) { - require_once($CFG->libdir . '/portfoliolib.php'); - require_once($CFG->dirroot . '/portfolio/boxnet/db/upgradelib.php'); - - $existing = $DB->get_record('portfolio_instance', array('plugin' => 'boxnet'), '*', IGNORE_MULTIPLE); - if ($existing) { - - // Only disable or message the admins when the portfolio hasn't been set for APIv2. - $instance = portfolio_instance($existing->id, $existing); - if ($instance->get_config('clientid') === null && $instance->get_config('clientsecret') === null) { - - // Disable Box.net. - $instance->set('visible', 0); - $instance->save(); - - // Message the admins. - portfolio_boxnet_admin_upgrade_notification(); - } - } - - upgrade_plugin_savepoint(true, 2013110602, 'portfolio', 'boxnet'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/portfolio/googledocs/db/upgrade.php b/portfolio/googledocs/db/upgrade.php index 0e2a8824a93ac..603961d80c629 100644 --- a/portfolio/googledocs/db/upgrade.php +++ b/portfolio/googledocs/db/upgrade.php @@ -14,49 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_portfolio_googledocs_upgrade($oldversion) { - global $CFG, $DB; - require_once(__DIR__.'/upgradelib.php'); - - $dbman = $DB->get_manager(); - - if ($oldversion < 2012053000) { - // Delete old user preferences containing authsub tokens. - $DB->delete_records('user_preferences', array('name' => 'google_authsub_sesskey')); - upgrade_plugin_savepoint(true, 2012053000, 'portfolio', 'googledocs'); - } - - if ($oldversion < 2012053001) { - $existing = $DB->get_record('portfolio_instance', array('plugin' => 'googledocs'), '*', IGNORE_MULTIPLE); - - if ($existing) { - portfolio_googledocs_admin_upgrade_notification(); - } - - upgrade_plugin_savepoint(true, 2012053001, 'portfolio', 'googledocs'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/portfolio/picasa/db/upgrade.php b/portfolio/picasa/db/upgrade.php index 8b960c6284f65..a0efd950faf8e 100644 --- a/portfolio/picasa/db/upgrade.php +++ b/portfolio/picasa/db/upgrade.php @@ -14,49 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_portfolio_picasa_upgrade($oldversion) { - global $CFG, $DB; - require_once(__DIR__.'/upgradelib.php'); - - $dbman = $DB->get_manager(); - - if ($oldversion < 2012053000) { - // Delete old user preferences containing authsub tokens. - $DB->delete_records('user_preferences', array('name' => 'google_authsub_sesskey_picasa')); - upgrade_plugin_savepoint(true, 2012053000, 'portfolio', 'picasa'); - } - - if ($oldversion < 2012053001) { - $existing = $DB->get_record('portfolio_instance', array('plugin' => 'picasa'), '*', IGNORE_MISSING); - - if ($existing) { - portfolio_picasa_admin_upgrade_notification(); - } - - upgrade_plugin_savepoint(true, 2012053001, 'portfolio', 'picasa'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/question/behaviour/manualgraded/db/upgrade.php b/question/behaviour/manualgraded/db/upgrade.php index 36884f39be6fc..50cce8de23f1f 100644 --- a/question/behaviour/manualgraded/db/upgrade.php +++ b/question/behaviour/manualgraded/db/upgrade.php @@ -22,79 +22,13 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Manual graded question behaviour upgrade code. */ function xmldb_qbehaviour_manualgraded_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2013050200) { - // Hide the manualgraded behaviour from the list of behaviours that users - // can select in the user-interface. If a user accidentally chooses manual - // graded behaviour for a quiz, there is no way to get the questions automatically - // graded after the student has answered them. If teachers really want to do - // this they can ask their admin to enable it on the manage behaviours - // screen in the UI. - $disabledbehaviours = get_config('question', 'disabledbehaviours'); - if (!empty($disabledbehaviours)) { - $disabledbehaviours = explode(',', $disabledbehaviours); - } else { - $disabledbehaviours = array(); - } - if (array_search('manualgraded', $disabledbehaviours) === false) { - $disabledbehaviours[] = 'manualgraded'; - set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question'); - } - - // Manual graded question behaviour savepoint reached. - upgrade_plugin_savepoint(true, 2013050200, 'qbehaviour', 'manualgraded'); - } - - if ($oldversion < 2013050800) { - // Also, fix any other admin settings that currently select manualgraded behaviour. - - // Work out a sensible default alternative to manualgraded. - require_once($CFG->libdir . '/questionlib.php'); - $behaviours = question_engine::get_behaviour_options(''); - if (array_key_exists('deferredfeedback', $behaviours)) { - $defaultbehaviour = 'deferredfeedback'; - } else { - reset($behaviours); - $defaultbehaviour = key($behaviours); - } - - // Fix the question preview default. - if (get_config('question_preview', 'behaviour') == 'manualgraded') { - set_config('behaviour', $defaultbehaviour, 'question_preview'); - } - - // Fix the quiz settings default. - if (get_config('quiz', 'preferredbehaviour') == 'manualgraded') { - set_config('preferredbehaviour', $defaultbehaviour, 'quiz'); - } - - // Manual graded question behaviour savepoint reached. - upgrade_plugin_savepoint(true, 2013050800, 'qbehaviour', 'manualgraded'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -107,4 +41,3 @@ function xmldb_qbehaviour_manualgraded_upgrade($oldversion) { return true; } - diff --git a/question/type/calculated/db/upgrade.php b/question/type/calculated/db/upgrade.php index 4ad8a0fd381cd..92f27606f5897 100644 --- a/question/type/calculated/db/upgrade.php +++ b/question/type/calculated/db/upgrade.php @@ -23,37 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the calculated question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_calculated_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -66,5 +43,3 @@ function xmldb_qtype_calculated_upgrade($oldversion) { return true; } - - diff --git a/question/type/essay/db/upgrade.php b/question/type/essay/db/upgrade.php index f990fb3ead378..a33fd4b884f0f 100644 --- a/question/type/essay/db/upgrade.php +++ b/question/type/essay/db/upgrade.php @@ -23,156 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the essay question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_essay_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this. - - if ($oldversion < 2011102701) { - $sql = " - FROM {question} q - JOIN {question_answers} qa ON qa.question = q.id - - WHERE q.qtype = 'essay' - AND " . $DB->sql_isnotempty('question_answers', 'feedback', false, true); - // In Moodle <= 2.0 essay had both question.generalfeedback and question_answers.feedback - // This was silly, and in Moodel >= 2.1 only question.generalfeedback. To avoid - // dataloss, we concatenate question_answers.feedback onto the end of question.generalfeedback. - $count = $DB->count_records_sql(" - SELECT COUNT(1) $sql"); - if ($count) { - $progressbar = new progress_bar('essay23', 500, true); - $done = 0; - - $toupdate = $DB->get_recordset_sql(" - SELECT q.id, - q.generalfeedback, - q.generalfeedbackformat, - qa.feedback, - qa.feedbackformat - $sql"); - - foreach ($toupdate as $data) { - $progressbar->update($done, $count, "Updating essay feedback ({$done}/{$count})."); - upgrade_set_timeout(60); - if ($data->generalfeedbackformat == $data->feedbackformat) { - $DB->set_field('question', 'generalfeedback', - $data->generalfeedback . $data->feedback, - array('id' => $data->id)); - - } else { - $newdata = new stdClass(); - $newdata->id = $data->id; - $newdata->generalfeedback = - qtype_essay_convert_to_html($data->generalfeedback, $data->generalfeedbackformat) . - qtype_essay_convert_to_html($data->feedback, $data->feedbackformat); - $newdata->generalfeedbackformat = FORMAT_HTML; - $DB->update_record('question', $newdata); - } - } - - $progressbar->update($count, $count, "Updating essay feedback complete!"); - $toupdate->close(); - } - - // Essay savepoint reached. - upgrade_plugin_savepoint(true, 2011102701, 'qtype', 'essay'); - } - - if ($oldversion < 2011102702) { - // Then we delete the old question_answers rows for essay questions. - $DB->delete_records_select('question_answers', - "question IN (SELECT id FROM {question} WHERE qtype = 'essay')"); - - // Essay savepoint reached. - upgrade_plugin_savepoint(true, 2011102702, 'qtype', 'essay'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - if ($oldversion < 2013011800) { - // Then we delete the old question_answers rows for essay questions. - $DB->delete_records_select('qtype_essay_options', "NOT EXISTS ( - SELECT 1 FROM {question} WHERE qtype = 'essay' AND - {question}.id = {qtype_essay_options}.questionid)"); - - // Essay savepoint reached. - upgrade_plugin_savepoint(true, 2013011800, 'qtype', 'essay'); - } - - if ($oldversion < 2013021700) { - // Create new fields responsetemplate and responsetemplateformat in qtyep_essay_options table. - $table = new xmldb_table('qtype_essay_options'); - $field = new xmldb_field('responsetemplate', XMLDB_TYPE_TEXT, null, null, - null, null, null, 'graderinfoformat'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $field = new xmldb_field('responsetemplateformat', XMLDB_TYPE_INTEGER, '4', - null, XMLDB_NOTNULL, null, '0', 'responsetemplate'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $DB->execute("UPDATE {qtype_essay_options} SET responsetemplate = '', - responsetemplateformat = " . FORMAT_HTML . " WHERE responsetemplate IS NULL"); - - // Essay savepoint reached. - upgrade_plugin_savepoint(true, 2013021700, 'qtype', 'essay'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2014011300) { - - // Create new field responserequired (indicates whether inline response is required). - - $table = new xmldb_table('qtype_essay_options'); - $field = new xmldb_field('responserequired', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1', 'responseformat'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Essay savepoint reached. - upgrade_plugin_savepoint(true, 2014011300, 'qtype', 'essay'); - } - - if ($oldversion < 2014011301) { - - // Create new field attachmentsrequired (indicates whether attachments should be required). - - $table = new xmldb_table('qtype_essay_options'); - $field = new xmldb_field('attachmentsrequired', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'attachments'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Essay savepoint reached. - upgrade_plugin_savepoint(true, 2014011301, 'qtype', 'essay'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. @@ -185,33 +43,3 @@ function xmldb_qtype_essay_upgrade($oldversion) { return true; } - -/** - * Convert some content to HTML. - * @param string $text the content to convert to HTML - * @param int $oldformat One of the FORMAT_... constants. - */ -function qtype_essay_convert_to_html($text, $oldformat) { - switch ($oldformat) { - // Similar to format_text. - - case FORMAT_PLAIN: - $text = s($text); - $text = str_replace(' ', '  ', $text); - $text = nl2br($text); - return $text; - - case FORMAT_MARKDOWN: - return markdown_to_html($text); - - case FORMAT_MOODLE: - return text_to_html($text); - - case FORMAT_HTML: - return $text; - - default: - throw new coding_exception( - 'Unexpected text format when upgrading essay questions.'); - } -} diff --git a/question/type/match/db/upgrade.php b/question/type/match/db/upgrade.php index e2f10042e4030..0254001ddc726 100644 --- a/question/type/match/db/upgrade.php +++ b/question/type/match/db/upgrade.php @@ -22,190 +22,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the matching question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_match_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013012099) { - // Find duplicate rows before they break the 2013012103 step below. - $problemids = $DB->get_recordset_sql(" - SELECT question, MIN(id) AS recordidtokeep - FROM {question_match} - GROUP BY question - HAVING COUNT(1) > 1 - "); - foreach ($problemids as $problem) { - $DB->delete_records_select('question_match', - 'question = ? AND id > ?', - array($problem->question, $problem->recordidtokeep)); - } - $problemids->close(); - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013012099, 'qtype', 'match'); - } - - if ($oldversion < 2013012100) { - - // Define table question_match to be renamed to qtype_match_options. - $table = new xmldb_table('question_match'); - - // Launch rename table for qtype_match_options. - $dbman->rename_table($table, 'qtype_match_options'); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012100, 'qtype', 'match'); - } - - if ($oldversion < 2013012101) { - - // Define key question (foreign) to be dropped form qtype_match_options. - $table = new xmldb_table('qtype_match_options'); - $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - - // Launch drop key question. - $dbman->drop_key($table, $key); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012101, 'qtype', 'match'); - } - - if ($oldversion < 2013012102) { - - // Rename field question on table qtype_match_options to questionid. - $table = new xmldb_table('qtype_match_options'); - $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - - // Launch rename field question. - $dbman->rename_field($table, $field, 'questionid'); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012102, 'qtype', 'match'); - } - - if ($oldversion < 2013012103) { - - // Define key questionid (foreign-unique) to be added to qtype_match_options. - $table = new xmldb_table('qtype_match_options'); - $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id')); - - // Launch add key questionid. - $dbman->add_key($table, $key); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012103, 'qtype', 'match'); - } - - if ($oldversion < 2013012104) { - - // Define field subquestions to be dropped from qtype_match_options. - $table = new xmldb_table('qtype_match_options'); - $field = new xmldb_field('subquestions'); - - // Conditionally launch drop field subquestions. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012104, 'qtype', 'match'); - } - - if ($oldversion < 2013012105) { - - // Define table question_match_sub to be renamed to qtype_match_subquestions. - $table = new xmldb_table('question_match_sub'); - - // Launch rename table for qtype_match_subquestions. - $dbman->rename_table($table, 'qtype_match_subquestions'); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012105, 'qtype', 'match'); - } - - if ($oldversion < 2013012106) { - - // Define key question (foreign) to be dropped form qtype_match_subquestions. - $table = new xmldb_table('qtype_match_subquestions'); - $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - - // Launch drop key question. - $dbman->drop_key($table, $key); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012106, 'qtype', 'match'); - } - - if ($oldversion < 2013012107) { - - // Rename field question on table qtype_match_subquestions to questionid. - $table = new xmldb_table('qtype_match_subquestions'); - $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - - // Launch rename field question. - $dbman->rename_field($table, $field, 'questionid'); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012107, 'qtype', 'match'); - } - - if ($oldversion < 2013012108) { - - // Define key questionid (foreign) to be added to qtype_match_subquestions. - $table = new xmldb_table('qtype_match_subquestions'); - $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id')); - - // Launch add key questionid. - $dbman->add_key($table, $key); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012108, 'qtype', 'match'); - } - - if ($oldversion < 2013012109) { - - // Define field code to be dropped from qtype_match_subquestions. - // The field code has not been needed since the new question engine in - // Moodle 2.1. It should be safe to drop it now. - $table = new xmldb_table('qtype_match_subquestions'); - $field = new xmldb_field('code'); - - // Conditionally launch drop field code. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013012109, 'qtype', 'match'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/question/type/multianswer/db/upgrade.php b/question/type/multianswer/db/upgrade.php index 0ea12ad5a2018..25b67f89bf500 100644 --- a/question/type/multianswer/db/upgrade.php +++ b/question/type/multianswer/db/upgrade.php @@ -23,7 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); /** @@ -35,25 +34,6 @@ function xmldb_qtype_multianswer_upgrade($oldversion) { $dbman = $DB->get_manager(); - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/question/type/multichoice/db/upgrade.php b/question/type/multichoice/db/upgrade.php index 4d99e12e2090d..e93815731a92e 100644 --- a/question/type/multichoice/db/upgrade.php +++ b/question/type/multichoice/db/upgrade.php @@ -23,121 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the multiple choice question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_multichoice_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013092300) { - // Find duplicate rows before they break the 2013092304 step below. - $problemids = $DB->get_recordset_sql(" - SELECT question, MIN(id) AS recordidtokeep - FROM {question_multichoice} - GROUP BY question - HAVING COUNT(1) > 1 - "); - foreach ($problemids as $problem) { - $DB->delete_records_select('question_multichoice', - 'question = ? AND id > ?', - array($problem->question, $problem->recordidtokeep)); - } - $problemids->close(); - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013092300, 'qtype', 'multichoice'); - } - - if ($oldversion < 2013092301) { - - // Define table question_multichoice to be renamed to qtype_multichoice_options. - $table = new xmldb_table('question_multichoice'); - - // Launch rename table for question_multichoice. - $dbman->rename_table($table, 'qtype_multichoice_options'); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013092301, 'qtype', 'multichoice'); - } - - if ($oldversion < 2013092302) { - - // Define key question (foreign) to be dropped form qtype_multichoice_options. - $table = new xmldb_table('qtype_multichoice_options'); - $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - - // Launch drop key question. - $dbman->drop_key($table, $key); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013092302, 'qtype', 'multichoice'); - } - - if ($oldversion < 2013092303) { - - // Rename field question on table qtype_multichoice_options to questionid. - $table = new xmldb_table('qtype_multichoice_options'); - $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - - // Launch rename field question. - $dbman->rename_field($table, $field, 'questionid'); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013092303, 'qtype', 'multichoice'); - } - - if ($oldversion < 2013092304) { - - // Define key questionid (foreign-unique) to be added to qtype_multichoice_options. - $table = new xmldb_table('qtype_multichoice_options'); - $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id')); - - // Launch add key questionid. - $dbman->add_key($table, $key); - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013092304, 'qtype', 'multichoice'); - } - - if ($oldversion < 2013092305) { - - // Define field answers to be dropped from qtype_multichoice_options. - $table = new xmldb_table('qtype_multichoice_options'); - $field = new xmldb_field('answers'); - - // Conditionally launch drop field answers. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Record that qtype_match savepoint was reached. - upgrade_plugin_savepoint(true, 2013092305, 'qtype', 'multichoice'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/question/type/numerical/db/upgrade.php b/question/type/numerical/db/upgrade.php index c13ded8489577..20f8ea9c6a3bf 100644 --- a/question/type/numerical/db/upgrade.php +++ b/question/type/numerical/db/upgrade.php @@ -23,34 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the numerical question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_numerical_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/question/type/random/db/upgrade.php b/question/type/random/db/upgrade.php index f88efa9d414df..4d354095afac2 100644 --- a/question/type/random/db/upgrade.php +++ b/question/type/random/db/upgrade.php @@ -22,10 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the random question type. * @param int $oldversion the version we are upgrading from. @@ -33,26 +31,6 @@ function xmldb_qtype_random_upgrade($oldversion) { global $CFG, $DB; - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this. - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - if ($oldversion < 2014060200) { $sql = "UPDATE {question} SET questiontext = '0' diff --git a/question/type/randomsamatch/db/upgrade.php b/question/type/randomsamatch/db/upgrade.php index decbd36e4e8ce..890b2bf8362ae 100644 --- a/question/type/randomsamatch/db/upgrade.php +++ b/question/type/randomsamatch/db/upgrade.php @@ -22,173 +22,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the random short answer matching question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_randomsamatch_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.2.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.3.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013110501) { - - // Define table question_randomsamatch to be renamed to qtype_randomsamatch_options. - $table = new xmldb_table('question_randomsamatch'); - - // Launch rename table for qtype_randomsamatch_options. - if ($dbman->table_exists($table)) { - $dbman->rename_table($table, 'qtype_randomsamatch_options'); - } - - // Record that qtype_randomsamatch savepoint was reached. - upgrade_plugin_savepoint(true, 2013110501, 'qtype', 'randomsamatch'); - } - - if ($oldversion < 2013110502) { - - // Define key question (foreign) to be dropped form qtype_randomsamatch_options. - $table = new xmldb_table('qtype_randomsamatch_options'); - $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - - if ($dbman->field_exists($table, $field)) { - // Launch drop key question. - $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - $dbman->drop_key($table, $key); - - // Launch rename field question. - $dbman->rename_field($table, $field, 'questionid'); - - $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id')); - // Launch add key questionid. - $dbman->add_key($table, $key); - } - - // Record that qtype_randomsamatch savepoint was reached. - upgrade_plugin_savepoint(true, 2013110502, 'qtype', 'randomsamatch'); - } - - if ($oldversion < 2013110503) { - - // Add subcats field. - $table = new xmldb_table('qtype_randomsamatch_options'); - - // Define field subcats to be added to qtype_randomsamatch_options. - $field = new xmldb_field('subcats', XMLDB_TYPE_INTEGER, 2, null, - XMLDB_NOTNULL, null, '1', 'choose'); - - // Conditionally launch add field subcats. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Add combined feedback fields. - // Define field correctfeedback to be added to qtype_randomsamatch_options. - $field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'subcats'); - - // Conditionally launch add field correctfeedback. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - - // Now fill it with ''. - $DB->set_field('qtype_randomsamatch_options', 'correctfeedback', ''); - - // Now add the not null constraint. - $field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, - XMLDB_NOTNULL, null, null, 'subcats'); - $dbman->change_field_notnull($table, $field); - } - - // Define field correctfeedbackformat to be added to qtype_randomsamatch_options. - $field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'correctfeedback'); - - // Conditionally launch add field correctfeedbackformat. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field partiallycorrectfeedback to be added to qtype_randomsamatch_options. - $field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'correctfeedbackformat'); - - // Conditionally launch add field partiallycorrectfeedback. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - - // Now fill it with ''. - $DB->set_field('qtype_randomsamatch_options', 'partiallycorrectfeedback', ''); - - // Now add the not null constraint. - $field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - XMLDB_NOTNULL, null, null, 'correctfeedbackformat'); - $dbman->change_field_notnull($table, $field); - } - - // Define field partiallycorrectfeedbackformat to be added to qtype_randomsamatch_options. - $field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback'); - - // Conditionally launch add field partiallycorrectfeedbackformat. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field incorrectfeedback to be added to qtype_randomsamatch_options. - $field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'partiallycorrectfeedbackformat'); - - // Conditionally launch add field incorrectfeedback. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - - // Now fill it with ''. - $DB->set_field('qtype_randomsamatch_options', 'incorrectfeedback', ''); - - // Now add the not null constraint. - $field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - XMLDB_NOTNULL, null, null, 'partiallycorrectfeedbackformat'); - $dbman->change_field_notnull($table, $field); - } - - // Define field incorrectfeedbackformat to be added to qtype_randomsamatch_options. - $field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'incorrectfeedback'); - - // Conditionally launch add field incorrectfeedbackformat. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field shownumcorrect to be added to qtype_randomsamatch_options. - $field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'incorrectfeedbackformat'); - - // Conditionally launch add field shownumcorrect. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Record that qtype_randomsamatch savepoint was reached. - upgrade_plugin_savepoint(true, 2013110503, 'qtype', 'randomsamatch'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/question/type/shortanswer/db/upgrade.php b/question/type/shortanswer/db/upgrade.php index 0d330048f9419..e605fc83a0589 100644 --- a/question/type/shortanswer/db/upgrade.php +++ b/question/type/shortanswer/db/upgrade.php @@ -23,116 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * Upgrade code for the essay question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_shortanswer_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.4.0 release upgrade line. - // Put any upgrade step following this. - - if ($oldversion < 2013011799) { - // Find duplicate rows before they break the 2013011803 step below. - $problemids = $DB->get_recordset_sql(" - SELECT question, MIN(id) AS recordidtokeep - FROM {question_shortanswer} - GROUP BY question - HAVING COUNT(1) > 1 - "); - foreach ($problemids as $problem) { - $DB->delete_records_select('question_shortanswer', - 'question = ? AND id > ?', - array($problem->question, $problem->recordidtokeep)); - } - $problemids->close(); - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013011799, 'qtype', 'shortanswer'); - } - - if ($oldversion < 2013011800) { - - // Define field answers to be dropped from question_shortanswer. - $table = new xmldb_table('question_shortanswer'); - $field = new xmldb_field('answers'); - - // Conditionally launch drop field answers. - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013011800, 'qtype', 'shortanswer'); - } - - if ($oldversion < 2013011801) { - - // Define key question (foreign) to be dropped form question_shortanswer. - $table = new xmldb_table('question_shortanswer'); - $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - - // Launch drop key question. - $dbman->drop_key($table, $key); - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013011801, 'qtype', 'shortanswer'); - } - - if ($oldversion < 2013011802) { - - // Rename field question on table question_shortanswer to questionid. - $table = new xmldb_table('question_shortanswer'); - $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); - - // Launch rename field question. - $dbman->rename_field($table, $field, 'questionid'); - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013011802, 'qtype', 'shortanswer'); - } - - if ($oldversion < 2013011803) { - - // Define key questionid (foreign-unique) to be added to question_shortanswer. - $table = new xmldb_table('question_shortanswer'); - $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id')); - - // Launch add key questionid. - $dbman->add_key($table, $key); - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013011803, 'qtype', 'shortanswer'); - } - - if ($oldversion < 2013011804) { - - // Define table qtype_shortanswer_options to be renamed to qtype_shortanswer_options. - $table = new xmldb_table('question_shortanswer'); - - // Launch rename table for qtype_shortanswer_options. - $dbman->rename_table($table, 'qtype_shortanswer_options'); - - // Shortanswer savepoint reached. - upgrade_plugin_savepoint(true, 2013011804, 'qtype', 'shortanswer'); - } - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/repository/alfresco/db/upgrade.php b/repository/alfresco/db/upgrade.php index 7046b1e1ac8af..3b4f45ffd6693 100644 --- a/repository/alfresco/db/upgrade.php +++ b/repository/alfresco/db/upgrade.php @@ -31,30 +31,7 @@ * @return bool result */ function xmldb_repository_alfresco_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - if ($oldversion < 2014020301) { - require_once($CFG->dirroot . '/repository/lib.php'); - require_once($CFG->dirroot . '/repository/alfresco/db/upgradelib.php'); - - $params = array(); - $params['context'] = array(); - $params['onlyvisible'] = false; - $params['type'] = 'alfresco'; - $instances = repository::get_instances($params); - - // Notify the admin about the migration process if they are using the repo. - if (!empty($instances)) { - repository_alfresco_admin_security_key_notice(); - } - - upgrade_plugin_savepoint(true, 2014020301, 'repository', 'alfresco'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/repository/boxnet/db/upgrade.php b/repository/boxnet/db/upgrade.php index a85a7504da467..774e637ad0db7 100644 --- a/repository/boxnet/db/upgrade.php +++ b/repository/boxnet/db/upgrade.php @@ -31,51 +31,7 @@ * @return bool result */ function xmldb_repository_boxnet_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - if ($oldversion < 2013110503) { - // Delete old user preferences containing auth tokens. - $DB->delete_records('user_preferences', array('name' => 'boxnet__auth_token')); - upgrade_plugin_savepoint(true, 2013110503, 'repository', 'boxnet'); - } - - if ($oldversion < 2013110700) { - require_once($CFG->dirroot . '/repository/lib.php'); - require_once($CFG->dirroot . '/repository/boxnet/db/upgradelib.php'); - - $clientid = get_config('boxnet', 'clientid'); - $clientsecret = get_config('boxnet', 'clientsecret'); - - // Only proceed if the repository hasn't been set for APIv2 yet. - if ($clientid === false && $clientsecret === false) { - $params = array(); - $params['context'] = array(); - $params['onlyvisible'] = false; - $params['type'] = 'boxnet'; - $instances = repository::get_instances($params); - - // Notify the admin about the migration process if they are using the repo. - if (!empty($instances)) { - repository_boxnet_admin_upgrade_notification(); - } - - // Hide the repository. - $repositorytype = repository::get_type_by_typename('boxnet'); - if (!empty($repositorytype)) { - $repositorytype->update_visibility(false); - } - } - - upgrade_plugin_savepoint(true, 2013110700, 'repository', 'boxnet'); - } - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/repository/dropbox/db/upgrade.php b/repository/dropbox/db/upgrade.php index c51ea5c114b1e..3e25c1f5257ca 100644 --- a/repository/dropbox/db/upgrade.php +++ b/repository/dropbox/db/upgrade.php @@ -14,40 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_repository_dropbox_upgrade($oldversion) { - global $CFG, $DB; - - $dbman = $DB->get_manager(); - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - if ($oldversion < 2012080702) { - // Set the default value for dropbox_cachelimit - $value = get_config('dropbox', 'dropbox_cachelimit'); - if (empty($value)) { - set_config('dropbox_cachelimit', 1024*1024, 'dropbox'); - } - upgrade_plugin_savepoint(true, 2012080702, 'repository', 'dropbox'); - } - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/repository/googledocs/db/upgrade.php b/repository/googledocs/db/upgrade.php index 9a45f1b337fe2..65d9fa80acf46 100644 --- a/repository/googledocs/db/upgrade.php +++ b/repository/googledocs/db/upgrade.php @@ -14,52 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_repository_googledocs_upgrade($oldversion) { - global $CFG, $DB; - require_once(__DIR__.'/upgradelib.php'); - - $dbman = $DB->get_manager(); - - if ($oldversion < 2012051400) { - // Delete old user preferences containing authsub tokens. - $DB->delete_records('user_preferences', array('name' => 'google_authsub_sesskey')); - upgrade_plugin_savepoint(true, 2012051400, 'repository', 'googledocs'); - } - - if ($oldversion < 2012053000) { - require_once($CFG->dirroot.'/repository/lib.php'); - $existing = $DB->get_record('repository', array('type' => 'googledocs'), '*', IGNORE_MULTIPLE); - - if ($existing) { - $googledocsplugin = new repository_type('googledocs', array(), true); - $googledocsplugin->delete(); - repository_googledocs_admin_upgrade_notification(); - } - - upgrade_plugin_savepoint(true, 2012053000, 'repository', 'googledocs'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/repository/picasa/db/upgrade.php b/repository/picasa/db/upgrade.php index 2853786cdd00c..ec2fe8afc48e7 100644 --- a/repository/picasa/db/upgrade.php +++ b/repository/picasa/db/upgrade.php @@ -14,52 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** * @param int $oldversion the version we are upgrading from * @return bool result */ function xmldb_repository_picasa_upgrade($oldversion) { - global $CFG, $DB; - require_once(__DIR__.'/upgradelib.php'); - - $dbman = $DB->get_manager(); - - if ($oldversion < 2012051400) { - // Delete old user preferences storing authsub tokens. - $DB->delete_records('user_preferences', array('name' => 'google_authsub_sesskey_picasa')); - upgrade_plugin_savepoint(true, 2012051400, 'repository', 'picasa'); - } - - if ($oldversion < 2012053000) { - require_once($CFG->dirroot.'/repository/lib.php'); - $existing = $DB->get_record('repository', array('type' => 'picasa'), '*', IGNORE_MULTIPLE); - - if ($existing) { - $picasaplugin = new repository_type('picasa', array(), true); - $picasaplugin->delete(); - repository_picasa_admin_upgrade_notification(); - } - - upgrade_plugin_savepoint(true, 2012053000, 'repository', 'picasa'); - } - - // Moodle v2.3.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.4.0 release upgrade line - // Put any upgrade step following this - - - // Moodle v2.5.0 release upgrade line. - // Put any upgrade step following this. - - - // Moodle v2.6.0 release upgrade line. - // Put any upgrade step following this. - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. + global $CFG; // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this. diff --git a/theme/more/db/upgrade.php b/theme/more/db/upgrade.php index e9d043d3636c1..aa97060a713c1 100644 --- a/theme/more/db/upgrade.php +++ b/theme/more/db/upgrade.php @@ -33,46 +33,6 @@ function xmldb_theme_more_upgrade($oldversion) { global $CFG; - if ($oldversion < 2014032400) { - - // Set the default background. If an image is already there then ignore. - $fs = get_file_storage(); - $bg = $fs->get_area_files(context_system::instance()->id, 'theme_more', 'backgroundimage', 0); - - // Add default background image. - if (empty($bg)) { - $filerecord = new stdClass(); - $filerecord->component = 'theme_more'; - $filerecord->contextid = context_system::instance()->id; - $filerecord->userid = get_admin()->id; - $filerecord->filearea = 'backgroundimage'; - $filerecord->filepath = '/'; - $filerecord->itemid = 0; - $filerecord->filename = 'background.jpg'; - $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/theme/more/pix/background.jpg'); - } - - upgrade_plugin_savepoint(true, 2014032400, 'theme', 'more'); - - } - - if ($oldversion < 2014032401) { - - // Set the default settings as they might already be set. - set_config('textcolor', '#333366', 'theme_more'); - set_config('linkcolor', '#FF6500', 'theme_more'); - set_config('backgroundrepeat', 'repeat', 'theme_more'); - set_config('contentbackground', '#FFFFFF', 'theme_more'); - set_config('secondarybackground', '#FFFFFF', 'theme_more'); - set_config('invert', 1, 'theme_more'); - set_config('backgroundimage', '/background.jpg', 'theme_more'); - - upgrade_plugin_savepoint(true, 2014032401, 'theme', 'more'); - } - - // Moodle v2.7.0 release upgrade line. - // Put any upgrade step following this. - // Moodle v2.8.0 release upgrade line. // Put any upgrade step following this.