From: stronk7 Date: Sat, 27 Jan 2007 01:12:18 +0000 (+0000) Subject: Delegate to the isNameInUse() function the request to X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f2daac4e6275c1c14070466d70c9a6ea5c9dab9f;p=moodle.git Delegate to the isNameInUse() function the request to see if one object name is in use in the DB (to avoid duplicates 100%) MDL-7376 (the rest will come tomorrow) --- diff --git a/lib/xmldb/classes/generators/XMLDBGenerator.class.php b/lib/xmldb/classes/generators/XMLDBGenerator.class.php index 8d4eca2f7c..b5e66bb4af 100644 --- a/lib/xmldb/classes/generators/XMLDBGenerator.class.php +++ b/lib/xmldb/classes/generators/XMLDBGenerator.class.php @@ -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