Merged MDL-29254 with conflict resolution
authorSam Hemelryk <sam@moodle.com>
Mon, 20 Feb 2012 05:07:13 +0000 (18:07 +1300)
committerSam Hemelryk <sam@moodle.com>
Mon, 20 Feb 2012 05:07:13 +0000 (18:07 +1300)
1  2 
lib/db/upgrade.php

@@@ -145,18 -145,36 +145,48 @@@ function xmldb_main_upgrade($oldversion
          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);
+     }
      return true;
  }