]> git.mjollnir.org Git - moodle.git/commitdiff
Another fix for metacourses (lost auto_increment). This will preserve data.
authormjollnir_ <mjollnir_>
Tue, 1 Feb 2005 04:47:04 +0000 (04:47 +0000)
committermjollnir_ <mjollnir_>
Tue, 1 Feb 2005 04:47:04 +0000 (04:47 +0000)
lib/db/mysql.php
version.php

index da7a30a046f899248a1667db13e107128bd5ccc8..bb9cb72940f7d8464dc36084d18c8998fdd8e817 100644 (file)
@@ -1146,6 +1146,40 @@ function main_upgrade($oldversion=0) {
         fix_course_sortorder(0, 1, 1);
     }   
 
+
+    if ($oldversion < 2005020101) {
+        // hopefully this is the LAST TIME we need to do this ;)
+        if ($rows = count_records("course_meta")) {
+            // we need to upgrade
+            modify_database("","CREATE TABLE `prefix_course_meta_tmp` (
+            `parent_course` int(10) NOT NULL default 0,
+            `child_course` int(10) NOT NULL default 0);");
+            
+            execute_sql("INSERT INTO {$CFG->prefix}course_meta_tmp (parent_course,child_course) 
+               SELECT {$CFG->prefix}course_meta.parent_course, {$CFG->prefix}course_meta.child_course
+               FROM {$CFG->prefix}course_meta");
+            $insertafter = true;
+        }
+
+        execute_sql("DROP TABLE {$CFG->prefix}course_meta");
+
+        modify_database("","CREATE TABLE `prefix_course_meta` (
+            `id` int(10) unsigned NOT NULL auto_increment,
+            `parent_course` int(10) unsigned NOT NULL default 0,
+            `child_course` int(10) unsigned NOT NULL default 0,
+            PRIMARY KEY (`id`),
+            KEY `parent_course` (parent_course),
+            KEY `child_course` (child_course));");
+
+        if (!empty($insertafter)) {
+            execute_sql("INSERT INTO {$CFG->prefix}course_meta (parent_course,child_course) 
+               SELECT {$CFG->prefix}course_meta_tmp.parent_course, {$CFG->prefix}course_meta_tmp.child_course
+               FROM {$CFG->prefix}course_meta_tmp");
+
+            execute_sql("DROP TABLE {$CFG->prefix}course_meta_tmp");
+        }
+    }
+
     return $result;
 }
 
index b85ed65cb61c1b7d3b73a62f68a8ecce9b13bb76..2136dac4429df705babe9795d8c7caca12fd857e 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine 
 // whether upgrades should be performed (see lib/db/*.php)
 
-   $version = 2005020100;  // YYYYMMDD = date of first major branch release 1.4
+   $version = 2005020101;  // YYYYMMDD = date of first major branch release 1.4
                            //       XY = increments within a single day
 
    $release = '1.5 UNSTABLE DEVELOPMENT';    // Human-friendly version name