Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

database module MDL-24470 change 'notification' column ('data' table)…

… default and NOT NULL. Update code for restore operation to support old backup with NULL value into 'notification'.
  • Loading branch information...
commit a3ed90bb6c31007fe054ea608a354458fbe3c239 1 parent 00067c1
Jérôme Mouneyrac mouneyrac authored
4 mod/data/db/install.xml
View
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/data/db" VERSION="20080226" COMMENT="XMLDB file for Moodle mod/data"
+<XMLDB PATH="mod/data/db" VERSION="20101001" COMMENT="XMLDB file for Moodle mod/data"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -35,7 +35,7 @@
<FIELD NAME="defaultsort" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="assessed" NEXT="defaultsortdir"/>
<FIELD NAME="defaultsortdir" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="defaultsort" NEXT="editany"/>
<FIELD NAME="editany" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="defaultsortdir" NEXT="notification"/>
- <FIELD NAME="notification" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" ENUM="false" COMMENT="Notify people when things change" PREVIOUS="editany"/>
+ <FIELD NAME="notification" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Notify people when things change" PREVIOUS="editany"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
14 mod/data/db/upgrade.php
View
@@ -132,6 +132,20 @@ function xmldb_data_upgrade($oldversion=0) {
}
}
+ if ($result && $oldversion < 2007101515) {
+ // Upgrade all the data->notification currently being
+ // NULL to 0
+ $sql = "UPDATE {$CFG->prefix}data SET notification=0 WHERE notification IS NULL";
+ $result = execute_sql($sql);
+ $table = new XMLDBTable('data');
+ $field = new XMLDBField('notification');
+ // First step, Set NOT NULL
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'editany');
+ $result = $result && change_field_notnull($table, $field);
+ // Second step, Set default to 0
+ $result = $result && change_field_default($table, $field);
+ }
+
return $result;
}
6 mod/data/restorelib.php
View
@@ -97,6 +97,12 @@ function data_restore_mods($mod,$restore) {
$database->defaultsortdir = backup_todb($info['MOD']['#']['DEFAULTSORTDIR']['0']['#']);
$database->editany = backup_todb($info['MOD']['#']['EDITANY']['0']['#']);
$database->notification = backup_todb($info['MOD']['#']['NOTIFICATION']['0']['#']);
+
+ //fix related to MDL-24470: if someone restore a backup previous to this fix it would fail
+ //if notification = NULL as the column can not be NULL anymore
+ if (empty($database->notification)) {
+ $database->notification = 0;
+ }
// We have to recode the scale field if it's <0 (positive is a grade, not a scale)
if ($database->scale < 0) {
2  mod/data/version.php
View
@@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2007101514;
+$module->version = 2007101515;
$module->requires = 2007101509; // Requires this Moodle version
$module->cron = 60;
Please sign in to comment.
Something went wrong with that request. Please try again.