Permalink
Browse files

MDL-26361 scorm - fix upgrade on change to not null

Every time one column is changed from null to not null
we must ensure that there aren't nulls at all or the
DDL statement will fail, as was reported here. The
simplest way, just apply for the default when the column is null.
  • Loading branch information...
1 parent 99faefb commit 3b3e2cecf3a2f4d2130e4a675402e33a69cb5c61 @stronk7 stronk7 committed Feb 17, 2011
Showing with 16 additions and 11 deletions.
  1. +16 −11 mod/scorm/db/upgrade.php
View
@@ -478,49 +478,54 @@ function xmldb_scorm_upgrade($oldversion) {
/// scorm savepoint reached
upgrade_mod_savepoint(true, 2010092400, 'scorm');
}
-
+
if ($oldversion < 2011011400) {
// Fix scorm in the post table after upgrade from 1.9
$table = new xmldb_table('scorm');
$columns = $DB->get_columns('scorm');
- // forcecompleted should be bigint(1) NOT NULL DEFAULT '1'
- // Fixed in earlier upgrade code
+ // forcecompleted should be int(1) not null default 1
+ // Changing to NOT NULL, let's fill the current nulls with default 1
+ $DB->set_field('scorm', 'forcecompleted', 1, array('forcecompleted' => null));
$field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'maxattempt');
if ($dbman->field_exists($table, $field)) {
$dbman->change_field_precision($table, $field);
}
if (array_key_exists('forcenewattempt', $columns) && empty($columns['forcenewattempt']->not_null)) {
- // forcenewattempt should be NOT NULL
- // Fixed in earlier upgrade code
+ // forcenewattempt should be int(1) not null default 0
+ // Changing to NOT NULL, let's fill the current nulls with default 0
+ $DB->set_field('scorm', 'forcenewattempt', 0, array('forcenewattempt' => null));
$field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcecompleted');
if ($dbman->field_exists($table, $field)) {
$dbman->change_field_notnull($table, $field);
}
}
if (array_key_exists('lastattemptlock', $columns) && empty($columns['lastattemptlock']->not_null)) {
- // lastattemptlock should be NOT NULL
- // Fixed in earlier upgrade code
+ // lastattemptlock should be int(1) not null default 0
+ // Changing to NOT NULL, let's fill the current nulls with default 0
+ $DB->set_field('scorm', 'lastattemptlock', 0, array('lastattemptlock' => null));
$field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcenewattempt');
if ($dbman->field_exists($table, $field)) {
$dbman->change_field_notnull($table, $field);
}
}
if (array_key_exists('displayattemptstatus', $columns) && empty($columns['displayattemptstatus']->not_null)) {
- // displayattemptstatus should be NOT NULL
- // Fixed in earlier upgrade code
+ // displayattemptstatus should be int(1) not null default 1
+ // Changing to NOT NULL, let's fill the current nulls with default 1
+ $DB->set_field('scorm', 'displayattemptstatus', 1, array('displayattemptstatus' => null));
$field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'lastattemptlock');
if ($dbman->field_exists($table, $field)) {
$dbman->change_field_notnull($table, $field);
}
}
if (array_key_exists('displaycoursestructure', $columns) && empty($columns['displaycoursestructure']->not_null)) {
- // displaycoursestructure should be NOT NULL
- // Fixed in earlier upgrade code
+ // displaycoursestructure should be int(1) not null default 1
+ // Changing to NOT NULL, let's fill the current nulls with default 1
+ $DB->set_field('scorm', 'displaycoursestructure', 1, array('displaycoursestructure' => null));
$field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'displayattemptstatus');
if ($dbman->field_exists($table, $field)) {
$dbman->change_field_notnull($table, $field);

0 comments on commit 3b3e2ce

Please sign in to comment.