MDL-38003 upgrade: ensure specific columns are set to not null during upgrade from < 1.7 to 2.x
This commit is contained in:
+29
-10
@@ -51,34 +51,32 @@ function xmldb_label_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2009042200) {
|
||||
|
||||
/// Rename field content on table label to intro
|
||||
// Rename field content on table label to intro.
|
||||
$table = new xmldb_table('label');
|
||||
$field = new xmldb_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
|
||||
|
||||
/// Launch rename field content
|
||||
// Launch rename field content.
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
/// label savepoint reached
|
||||
// Label savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2009042200, 'label');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042201) {
|
||||
|
||||
/// Define field introformat to be added to label
|
||||
// Define field introformat to be added to label.
|
||||
$table = new xmldb_table('label');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
// Launch add field introformat.
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
// all existing lables in 1.9 are in HTML format
|
||||
// All existing labels in 1.9 are in HTML format.
|
||||
$DB->set_field('label', 'introformat', FORMAT_HTML, array());
|
||||
|
||||
/// label savepoint reached
|
||||
// Label savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2009042201, 'label');
|
||||
}
|
||||
|
||||
@@ -88,6 +86,27 @@ function xmldb_label_upgrade($oldversion) {
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
if ($oldversion < 2011112901) {
|
||||
// Alter the label table.
|
||||
$table = new xmldb_table('label');
|
||||
// Columns to change.
|
||||
$arrfields = array();
|
||||
$arrfields['name'] = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, '', 'course');
|
||||
$arrfields['intro'] = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, '', 'name');
|
||||
|
||||
// Loop through columns and update the fields.
|
||||
foreach ($arrfields as $fieldname => $field) {
|
||||
// Check the field exists.
|
||||
if ($dbman->field_exists($table, $fieldname)) {
|
||||
$DB->execute("UPDATE {label} SET {$fieldname} = ? WHERE {$fieldname} IS NULL", array($DB->sql_empty()));
|
||||
$dbman->change_field_precision($table, $field);
|
||||
}
|
||||
}
|
||||
|
||||
// Label savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2011112901, 'label');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->version = 2011112901; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2011112900; // Requires this Moodle version
|
||||
$module->component = 'mod_label'; // Full name of the plugin (used for diagnostics)
|
||||
$module->cron = 0;
|
||||
|
||||
@@ -210,11 +210,13 @@ function resource_20_prepare_migration() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// fix invalid NULL popup and options data in old mysql databases
|
||||
// Fix invalid NULL popup, options and reference data in old databases.
|
||||
$sql = "UPDATE {resource} SET popup = ? WHERE popup IS NULL";
|
||||
$DB->execute($sql, array($DB->sql_empty()));
|
||||
$sql = "UPDATE {resource} SET options = ? WHERE options IS NULL";
|
||||
$DB->execute($sql, array($DB->sql_empty()));
|
||||
$sql = "UPDATE {resource} SET reference = ? WHERE reference IS NULL";
|
||||
$DB->execute($sql, array($DB->sql_empty()));
|
||||
|
||||
// Adding fields to table resource_old
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
|
||||
@@ -25,20 +25,20 @@ function xmldb_survey_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2009042002) {
|
||||
|
||||
/// Define field introformat to be added to survey
|
||||
// Define field introformat to be added to survey.
|
||||
$table = new xmldb_table('survey');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Conditionally launch add field introformat
|
||||
// Conditionally launch add field introformat.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
// Conditionally migrate to html format in intro.
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('survey', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $s) {
|
||||
@@ -50,7 +50,7 @@ function xmldb_survey_upgrade($oldversion) {
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/// survey savepoint reached
|
||||
// Survey savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2009042002, 'survey');
|
||||
}
|
||||
|
||||
@@ -60,6 +60,42 @@ function xmldb_survey_upgrade($oldversion) {
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
if ($oldversion < 2011112901) {
|
||||
// Tables to change.
|
||||
$arrtables = array();
|
||||
$arrtables['survey'] = new xmldb_table('survey');
|
||||
$arrtables['survey_answers'] = new xmldb_table('survey_answers');
|
||||
$arrtables['survey_questions'] = new xmldb_table('survey_questions');
|
||||
// Columns to change.
|
||||
$arrfields = array();
|
||||
$arrfields['survey']['intro'] = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, '', 'name');
|
||||
$arrfields['survey']['questions'] = new xmldb_field('questions', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, '', 'introformat');
|
||||
$arrfields['survey_answers']['time'] = new xmldb_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'question');
|
||||
$arrfields['survey_answers']['answer1'] = new xmldb_field('answer1', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, '', 'time');
|
||||
$arrfields['survey_answers']['answer2'] = new xmldb_field('answer2', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, '', 'answer1');
|
||||
$arrfields['survey_questions']['intro'] = new xmldb_field('intro', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, '', 'multi');
|
||||
|
||||
// Loop through the tables.
|
||||
foreach ($arrtables as $tablename => $table) {
|
||||
// Loop through columns and update the fields.
|
||||
foreach ($arrfields[$tablename] as $fieldname => $field) {
|
||||
// Check the field exists.
|
||||
if ($dbman->field_exists($tablename, $fieldname)) {
|
||||
// If the field name is time, then we set to 0, not empty as SQL will fail.
|
||||
if ($fieldname == 'time') {
|
||||
$DB->execute("UPDATE " . $CFG->prefix . $tablename . " SET {$fieldname} = 0 WHERE {$fieldname} IS NULL", array($DB->sql_empty()));
|
||||
} else {
|
||||
$DB->execute("UPDATE " . $CFG->prefix . $tablename . " SET {$fieldname} = ? WHERE {$fieldname} IS NULL", array($DB->sql_empty()));
|
||||
}
|
||||
$dbman->change_field_precision($table, $field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Survey savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2011112901, 'survey');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->version = 2011112901; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2011112900; // Requires this Moodle version
|
||||
$module->component = 'mod_survey'; // Full name of the plugin (used for diagnostics)
|
||||
$module->cron = 0;
|
||||
|
||||
Reference in New Issue
Block a user