mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
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.
This commit is contained in:
parent
7c1c94872e
commit
af999b9095
@ -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)) {
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user