MDL-63276 upgrade: clean < 3.2.0 upgrade steps

3.7 (min PHP 7.1) requires 3.2 (first version supporting PHP 7.1)

This just deletes all the upgrade steps previous to 3.2.0. Some
small adjustments, like adding missing MOODLE_INTERNAL or tweaking
globals can also be applied when needed.

Also includes an upgrade step to prevent upgrading from any
version < 2016120500 (v3.2.0) as anti-cheating measure.

Next commit will get rid of/deprecate all the upgradelib functions
not used anymore in codebase. (note there isn't any this time).
This commit is contained in:
Eloy Lafuente (stronk7)
2019-01-03 01:17:17 +01:00
parent f580d20adf
commit a12207be25
106 changed files with 13 additions and 1166 deletions
-19
View File
@@ -32,25 +32,6 @@ defined('MOODLE_INTERNAL') || die();
*/
function xmldb_antivirus_clamav_upgrade($oldversion) {
if ($oldversion < 2016101700) {
// Remove setting that has been deprecated long time ago at MDL-44260.
unset_config('quarantinedir', 'antivirus_clamav');
upgrade_plugin_savepoint(true, 2016101700, 'antivirus', 'clamav');
}
if ($oldversion < 2016102600) {
// Make command line a default running method for now. We depend on this
// config variable in antivirus scan running, it should be defined.
if (!get_config('antivirus_clamav', 'runningmethod')) {
set_config('runningmethod', 'commandline', 'antivirus_clamav');
}
upgrade_plugin_savepoint(true, 2016102600, 'antivirus', 'clamav');
}
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.
+4 -377
View File
@@ -92,388 +92,15 @@ function xmldb_main_upgrade($oldversion) {
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
// Always keep this upgrade step with version being the minimum
// allowed version to upgrade from (v3.1.0 right now).
if ($oldversion < 2016052300) {
// allowed version to upgrade from (v3.2.0 right now).
if ($oldversion < 2016120500) {
// Just in case somebody hacks upgrade scripts or env, we really can not continue.
echo("You need to upgrade to 3.1.x or higher first!\n");
echo("You need to upgrade to 3.2.x or higher first!\n");
exit(1);
// Note this savepoint is 100% unreachable, but needed to pass the upgrade checks.
upgrade_main_savepoint(true, 2016052300);
upgrade_main_savepoint(true, 2016120500);
}
if ($oldversion < 2016081700.00) {
// If someone is emotionally attached to it let's leave the config (basically the version) there.
if (!file_exists($CFG->dirroot . '/report/search/classes/output/form.php')) {
unset_all_config_for_plugin('report_search');
}
// Savepoint reached.
upgrade_main_savepoint(true, 2016081700.00);
}
if ($oldversion < 2016081700.02) {
// Default schedule values.
$hour = 0;
$minute = 0;
// Get the old settings.
if (isset($CFG->statsruntimestarthour)) {
$hour = $CFG->statsruntimestarthour;
}
if (isset($CFG->statsruntimestartminute)) {
$minute = $CFG->statsruntimestartminute;
}
// Retrieve the scheduled task record first.
$stattask = $DB->get_record('task_scheduled', array('component' => 'moodle', 'classname' => '\core\task\stats_cron_task'));
// Don't touch customised scheduling.
if ($stattask && !$stattask->customised) {
$nextruntime = mktime($hour, $minute, 0, date('m'), date('d'), date('Y'));
if ($nextruntime < $stattask->lastruntime) {
// Add 24 hours to the next run time.
$newtime = new DateTime();
$newtime->setTimestamp($nextruntime);
$newtime->add(new DateInterval('P1D'));
$nextruntime = $newtime->getTimestamp();
}
$stattask->nextruntime = $nextruntime;
$stattask->minute = $minute;
$stattask->hour = $hour;
$stattask->customised = 1;
$DB->update_record('task_scheduled', $stattask);
}
// These settings are no longer used.
unset_config('statsruntimestarthour');
unset_config('statsruntimestartminute');
unset_config('statslastexecution');
upgrade_main_savepoint(true, 2016081700.02);
}
if ($oldversion < 2016082200.00) {
// An upgrade step to remove any duplicate stamps, within the same context, in the question_categories table, and to
// add a unique index to (contextid, stamp) to avoid future stamp duplication. See MDL-54864.
// Extend the execution time limit of the script to 2 hours.
upgrade_set_timeout(7200);
// This SQL fetches the id of those records which have duplicate stamps within the same context.
// This doesn't return the original record within the context, from which the duplicate stamps were likely created.
$fromclause = "FROM (
SELECT min(id) AS minid, contextid, stamp
FROM {question_categories}
GROUP BY contextid, stamp
) minid
JOIN {question_categories} qc
ON qc.contextid = minid.contextid AND qc.stamp = minid.stamp AND qc.id > minid.minid";
// Get the total record count - used for the progress bar.
$countduplicatessql = "SELECT count(qc.id) $fromclause";
$total = $DB->count_records_sql($countduplicatessql);
// Get the records themselves.
$getduplicatessql = "SELECT qc.id $fromclause ORDER BY minid";
$rs = $DB->get_recordset_sql($getduplicatessql);
// For each duplicate, update the stamp to a new random value.
$i = 0;
$pbar = new progress_bar('updatequestioncategorystamp', 500, true);
foreach ($rs as $record) {
// Generate a new, unique stamp and update the record.
do {
$newstamp = make_unique_id_code();
} while (isset($usedstamps[$newstamp]));
$usedstamps[$newstamp] = 1;
$DB->set_field('question_categories', 'stamp', $newstamp, array('id' => $record->id));
// Update progress.
$i++;
$pbar->update($i, $total, "Updating duplicate question category stamp - $i/$total.");
}
$rs->close();
unset($usedstamps);
// The uniqueness of each (contextid, stamp) pair is now guaranteed, so add the unique index to stop future duplicates.
$table = new xmldb_table('question_categories');
$index = new xmldb_index('contextidstamp', XMLDB_INDEX_UNIQUE, array('contextid', 'stamp'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Savepoint reached.
upgrade_main_savepoint(true, 2016082200.00);
}
if ($oldversion < 2016091900.00) {
// Removing the themes from core.
$themes = array('base', 'canvas');
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]);
}
}
if (!empty($themes)) {
// Hacky emulation of plugin uninstallation.
foreach ($themes as $theme) {
unset_all_config_for_plugin('theme_' . $theme);
}
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016091900.00);
}
if ($oldversion < 2016091900.02) {
// Define index attemptstepid-name (unique) to be dropped from question_attempt_step_data.
$table = new xmldb_table('question_attempt_step_data');
$index = new xmldb_index('attemptstepid-name', XMLDB_INDEX_UNIQUE, array('attemptstepid', 'name'));
// Conditionally launch drop index attemptstepid-name.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016091900.02);
}
if ($oldversion < 2016100300.00) {
unset_config('enablecssoptimiser');
upgrade_main_savepoint(true, 2016100300.00);
}
if ($oldversion < 2016100501.00) {
// Define field enddate to be added to course.
$table = new xmldb_table('course');
$field = new xmldb_field('enddate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'startdate');
// Conditionally launch add field enddate.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016100501.00);
}
if ($oldversion < 2016101100.00) {
// Define field component to be added to message.
$table = new xmldb_table('message');
$field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'timeusertodeleted');
// Conditionally launch add field component.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field eventtype to be added to message.
$field = new xmldb_field('eventtype', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'component');
// Conditionally launch add field eventtype.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016101100.00);
}
if ($oldversion < 2016101101.00) {
// Define field component to be added to message_read.
$table = new xmldb_table('message_read');
$field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'timeusertodeleted');
// Conditionally launch add field component.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field eventtype to be added to message_read.
$field = new xmldb_field('eventtype', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'component');
// Conditionally launch add field eventtype.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016101101.00);
}
if ($oldversion < 2016101401.00) {
// Clean up repository_alfresco config unless plugin has been manually installed.
if (!file_exists($CFG->dirroot . '/repository/alfresco/lib.php')) {
// Remove capabilities.
capabilities_cleanup('repository_alfresco');
// Clean config.
unset_all_config_for_plugin('repository_alfresco');
}
// Savepoint reached.
upgrade_main_savepoint(true, 2016101401.00);
}
if ($oldversion < 2016101401.02) {
$table = new xmldb_table('external_tokens');
$field = new xmldb_field('privatetoken', XMLDB_TYPE_CHAR, '64', null, null, null, null);
// Conditionally add privatetoken field to the external_tokens table.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016101401.02);
}
if ($oldversion < 2016110202.00) {
// Force uninstall of deleted authentication plugin.
if (!file_exists("$CFG->dirroot/auth/radius")) {
// Leave settings inplace if there are radius users.
if (!$DB->record_exists('user', array('auth' => 'radius', 'deleted' => 0))) {
// Remove all other associated config.
unset_all_config_for_plugin('auth/radius');
// The version number for radius is in this format.
unset_all_config_for_plugin('auth_radius');
}
}
upgrade_main_savepoint(true, 2016110202.00);
}
if ($oldversion < 2016110300.00) {
// Remove unused admin email setting.
unset_config('emailonlyfromreplyaddress');
// Main savepoint reached.
upgrade_main_savepoint(true, 2016110300.00);
}
if ($oldversion < 2016110500.00) {
$oldplayers = [
'vimeo' => null,
'mp3' => ['.mp3'],
'html5video' => ['.mov', '.mp4', '.m4v', '.mpeg', '.mpe', '.mpg', '.ogv', '.webm'],
'flv' => ['.flv', '.f4v'],
'html5audio' => ['.aac', '.flac', '.mp3', '.m4a', '.oga', '.ogg', '.wav'],
'youtube' => null,
'swf' => null,
];
// Convert hardcoded media players to the settings of the new media player plugin type.
if (get_config('core', 'media_plugins_sortorder') === false) {
$enabledplugins = [];
$videoextensions = [];
$audioextensions = [];
foreach ($oldplayers as $oldplayer => $extensions) {
$settingname = 'core_media_enable_'.$oldplayer;
if (!empty($CFG->$settingname)) {
if ($extensions) {
// VideoJS will be used for all media files players that were used previously.
$enabledplugins['videojs'] = 'videojs';
if ($oldplayer === 'mp3' || $oldplayer === 'html5audio') {
$audioextensions += array_combine($extensions, $extensions);
} else {
$videoextensions += array_combine($extensions, $extensions);
}
} else {
// Enable youtube, vimeo and swf.
$enabledplugins[$oldplayer] = $oldplayer;
}
}
}
set_config('media_plugins_sortorder', join(',', $enabledplugins));
// Configure VideoJS to match the existing players set up.
if ($enabledplugins['videojs']) {
$enabledplugins[] = 'videojs';
set_config('audioextensions', join(',', $audioextensions), 'media_videojs');
set_config('videoextensions', join(',', $videoextensions), 'media_videojs');
$useflash = !empty($CFG->core_media_enable_flv) || !empty($CFG->core_media_enable_mp3);
set_config('useflash', $useflash, 'media_videojs');
if (empty($CFG->core_media_enable_youtube)) {
// Normally YouTube is enabled in videojs, but if youtube converter was disabled before upgrade
// disable it in videojs as well.
set_config('youtube', false, 'media_videojs');
}
}
}
// Unset old settings.
foreach ($oldplayers as $oldplayer => $extensions) {
unset_config('core_media_enable_' . $oldplayer);
}
// Preset defaults if CORE_MEDIA_VIDEO_WIDTH and CORE_MEDIA_VIDEO_HEIGHT are specified in config.php .
// After this upgrade step these constants will not be used any more.
if (defined('CORE_MEDIA_VIDEO_WIDTH')) {
set_config('media_default_width', CORE_MEDIA_VIDEO_WIDTH);
}
if (defined('CORE_MEDIA_VIDEO_HEIGHT')) {
set_config('media_default_height', CORE_MEDIA_VIDEO_HEIGHT);
}
// Savepoint reached.
upgrade_main_savepoint(true, 2016110500.00);
}
if ($oldversion < 2016110600.00) {
// Define a field 'deletioninprogress' in the 'course_modules' table, to background deletion tasks.
$table = new xmldb_table('course_modules');
$field = new xmldb_field('deletioninprogress', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'availability');
// Conditionally launch add field 'deletioninprogress'.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016110600.00);
}
if ($oldversion < 2016112200.01) {
// Define field requiredbytheme to be added to block_instances.
$table = new xmldb_table('block_instances');
$field = new xmldb_field('requiredbytheme', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showinsubcontexts');
// Conditionally launch add field requiredbytheme.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2016112200.01);
}
if ($oldversion < 2016112200.02) {
// Change the existing site level admin and settings blocks to be requiredbytheme which means they won't show in boost.
$context = context_system::instance();
$params = array('blockname' => 'settings', 'parentcontextid' => $context->id);
$DB->set_field('block_instances', 'requiredbytheme', 1, $params);
$params = array('blockname' => 'navigation', 'parentcontextid' => $context->id);
$DB->set_field('block_instances', 'requiredbytheme', 1, $params);
// Main savepoint reached.
upgrade_main_savepoint(true, 2016112200.02);
}
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2016122800.00) {
// Find all roles with the coursecreator archetype.
$coursecreatorroleids = $DB->get_records('role', array('archetype' => 'coursecreator'), '', 'id');
-3
View File
@@ -32,9 +32,6 @@ defined('MOODLE_INTERNAL') || die();
function xmldb_editor_atto_upgrade($oldversion) {
global $CFG;
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.
@@ -32,9 +32,6 @@ defined('MOODLE_INTERNAL') || die();
function xmldb_atto_equation_upgrade($oldversion) {
global $CFG;
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.
-3
View File
@@ -27,9 +27,6 @@ defined('MOODLE_INTERNAL') || die();
function xmldb_editor_tinymce_upgrade($oldversion) {
global $CFG;
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.
@@ -27,9 +27,6 @@ defined('MOODLE_INTERNAL') || die();
function xmldb_tinymce_spellchecker_upgrade($oldversion) {
global $CFG;
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.