]> git.mjollnir.org Git - moodle.git/commitdiff
Delegate to the isNameInUse() function the request to
authorstronk7 <stronk7>
Sat, 27 Jan 2007 01:12:18 +0000 (01:12 +0000)
committerstronk7 <stronk7>
Sat, 27 Jan 2007 01:12:18 +0000 (01:12 +0000)
see if one object name is in use in the DB (to avoid
duplicates 100%) MDL-7376 (the rest will come tomorrow)

lib/xmldb/classes/generators/XMLDBGenerator.class.php

index 8d4eca2f7c556ab79059235815a695bd4efc1871..b5e66bb4af5bc332dc63bafbc9da24ed38bd98dd 100644 (file)
@@ -921,8 +921,8 @@ class XMLDBgenerator {
             $namewithsuffix = $namewithsuffix . '_' . $suffix;
         }
 
-    /// If the calculated name is in the cache, let's modify if
-        if (in_array($namewithsuffix, $used_names)) {
+    /// 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)) {
             $counter = 2;
         /// If have free space, we add 2
             if (strlen($namewithsuffix) < $this->names_max_length) {
@@ -936,7 +936,7 @@ class XMLDBgenerator {
                 $newnamewithsuffix = $newnamewithsuffix . '_' . $suffix;
             }
         /// Now iterate until not used name is found, incrementing the counter
-            while (in_array($newnamewithsuffix, $used_names)) {
+            while (in_array($newnamewithsuffix, $used_names) || $this->isNameInUse($newnamewithsuffix, $suffix)) {
                 $newname = substr($name, 0, strlen($newname)-1) . $counter;
                 $newnamewithsuffix = $newname;
                 if ($suffix) {
@@ -1074,6 +1074,17 @@ class XMLDBgenerator {
         return false;
     }
 
+    /**
+     * Given one object name and it's type (pk, uk, fk, ix, uix, seq, trg)
+     * return if such name is currently in use (true) or no (false)
+     * (invoked from getNameForObject()
+     * Only some DB have this implemented
+     */
+    function isNameInUse($object_name, $type) {
+        return false; //For generators not implementing introspecion, 
+                      //we always return with the name being free to be used
+    }
+
 
 /// ALL THESE FUNCTION MUST BE CUSTOMISED BY ALL THE XMLDGenerator classes