From af999b909531568a727464358870c9484f7d4493 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 17 Aug 2007 09:59:54 +0000 Subject: [PATCH] Temporary fix for MDL-9356 becuase it was blocking a bug I needed to fix. Eloy, please review carefully when you get back from holiday. --- .../generators/XMLDBGenerator.class.php | 48 ++++++++++++------- .../generators/postgres7/postgres7.class.php | 2 +- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/xmldb/classes/generators/XMLDBGenerator.class.php b/lib/xmldb/classes/generators/XMLDBGenerator.class.php index fe41d2db1a..75084d73ce 100644 --- a/lib/xmldb/classes/generators/XMLDBGenerator.class.php +++ b/lib/xmldb/classes/generators/XMLDBGenerator.class.php @@ -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)) { diff --git a/lib/xmldb/classes/generators/postgres7/postgres7.class.php b/lib/xmldb/classes/generators/postgres7/postgres7.class.php index dbf2e2eb46..7e75a9f1c2 100644 --- a/lib/xmldb/classes/generators/postgres7/postgres7.class.php +++ b/lib/xmldb/classes/generators/postgres7/postgres7.class.php @@ -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')); } /** -- 2.39.5