]> git.mjollnir.org Git - moodle.git/commitdiff
Temporary fix for MDL-9356 becuase it was blocking a bug I needed to fix. Eloy, pleas...
authortjhunt <tjhunt>
Fri, 17 Aug 2007 09:59:54 +0000 (09:59 +0000)
committertjhunt <tjhunt>
Fri, 17 Aug 2007 09:59:54 +0000 (09:59 +0000)
lib/xmldb/classes/generators/XMLDBGenerator.class.php
lib/xmldb/classes/generators/postgres7/postgres7.class.php

index fe41d2db1acc8d44e39ad706a0b14668c8aac674..75084d73ceae8ed8ebf8ec5eed8d912a2535366b 100644 (file)
@@ -888,27 +888,15 @@ class XMLDBgenerator {
     }
 
     /**
-     * Given three strings (table name, list of fields (comma separated) and suffix), 
-     * create the proper object name quoting it if necessary.
+     * Get the name for an object, irrespective of whether it is in use or not.
      * 
-     * IMPORTANT: This function must be used to calculate names of objects to be created, 
-     *            never to guess names of existing objects!
+     * You should probably use getNameForObject instead of this method. I just
+     * made this method as a temporary work-around for MDL-9356 at a time
+     * when Eloy was not around to help. 
      */
-    function getNameForObject($tablename, $fields, $suffix='') {
-
+    function getStandardNameForObject($tablename, $fields, $suffix='') {
         $name = '';
 
-    /// Implement one basic cache to avoid object name duplication
-    /// and to speed up repeated queries for the same objects
-        if (!isset($used_names)) {
-            static $used_names = array();
-        }
-
-    /// If this exact object has been requested, return it
-        if (array_key_exists($tablename.'-'.$fields.'-'.$suffix, $used_names)) {
-            return $used_names[$tablename.'-'.$fields.'-'.$suffix];
-        }
-
     /// Use standard naming. See http://docs.moodle.org/en/XMLDB_key_and_index_naming
         $tablearr = explode ('_', $tablename);
         foreach ($tablearr as $table) {
@@ -929,6 +917,32 @@ class XMLDBgenerator {
         if ($suffix) {
             $namewithsuffix = $namewithsuffix . '_' . $suffix;
         }
+        
+        return $namewithsuffix;
+    }
+
+    /**
+     * Given three strings (table name, list of fields (comma separated) and suffix), 
+     * create the proper object name quoting it if necessary.
+     * 
+     * IMPORTANT: This function must be used to calculate names of objects to be created, 
+     *            never to guess names of existing objects!
+     */
+    function getNameForObject($tablename, $fields, $suffix='') {
+
+    /// Implement one basic cache to avoid object name duplication
+    /// and to speed up repeated queries for the same objects
+        if (!isset($used_names)) {
+            static $used_names = array();
+        }
+
+    /// If this exact object has been requested, return it
+        if (array_key_exists($tablename.'-'.$fields.'-'.$suffix, $used_names)) {
+            return $used_names[$tablename.'-'.$fields.'-'.$suffix];
+        }
+
+        $name = $this->getStandardNameForObject($tablename, $fields); 
+        $namewithsuffix = $this->getStandardNameForObject($tablename, $fields, $suffix);
 
     /// If the calculated name is in the cache, or if we detect it by introspecting the DB let's modify if
         if (in_array($namewithsuffix, $used_names) || $this->isNameInUse($namewithsuffix, $suffix, $tablename)) {
index dbf2e2eb46f22a4fa4226033c200168a1543f83c..7e75a9f1c21a3403c41f14d57719c800d458fa15 100644 (file)
@@ -398,7 +398,7 @@ class XMLDBpostgres7 extends XMLDBgenerator {
     function getDropEnumSQL($xmldb_table, $xmldb_field) {
     /// All we have to do is to drop the check constraint
         return array('ALTER TABLE ' . $this->getTableName($xmldb_table) .
-                     ' DROP CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'));
+                     ' DROP CONSTRAINT ' . $this->getStandardNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'));
     }
 
     /**