From: stronk7 <stronk7>
Date: Thu, 30 Jul 2009 18:48:42 +0000 (+0000)
Subject: MDL-19701, MDL-19695 ddl stuff - review upgrade to enforce dependencies on every... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=da750a51823a93250d22ffb96b7c5dce799196d2;p=moodle.git

MDL-19701, MDL-19695 ddl stuff - review upgrade to enforce dependencies on every field operation
---

diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index b7a4c5b544..dea7578a07 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -1077,9 +1077,25 @@ function xmldb_main_upgrade($oldversion) {
         $table = new xmldb_table('course_request');
         $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
 
+    /// Before changing the field, drop dependent indexes
+    /// Define index shortname (not unique) to be dropped form course_request
+        $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
+    /// Conditionally launch drop index shortname
+        if ($dbman->index_exists($table, $index)) {
+            $dbman->drop_index($table, $index);
+        }
+
     /// Launch change of precision for field shortname
         $dbman->change_field_precision($table, $field);
 
+    /// After changing the field, recreate dependent indexes
+    /// Define index shortname (not unique) to be added to course_request
+        $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
+    /// Conditionally launch add index shortname
+        if (!$dbman->index_exists($table, $index)) {
+            $dbman->add_index($table, $index);
+        }
+
     /// Main savepoint reached
         upgrade_main_savepoint($result, 2008120700);
     }