MDL-24322 detecting duplicate keys/fields and indexes - this prevents infinite looks later in code

This commit is contained in:
Petr Skoda 2010-09-21 10:42:20 +00:00
parent f2a9be5f8a
commit 6496a019c9

View File

@ -48,6 +48,11 @@ class xmldb_table extends xmldb_object {
*/
function addField(&$field, $after=NULL) {
/// Detect duplicates first
if ($this->getField($field->getName())) {
throw new coding_exception('Duplicate field '.$field->getName().' specified in table '.$this->getName());
}
/// Calculate the previous and next fields
$prevfield = NULL;
$nextfield = NULL;
@ -95,6 +100,11 @@ class xmldb_table extends xmldb_object {
*/
function addKey(&$key, $after=NULL) {
/// Detect duplicates first
if ($this->getKey($key->getName())) {
throw new coding_exception('Duplicate key '.$key->getName().' specified in table '.$this->getName());
}
/// Calculate the previous and next keys
$prevkey = NULL;
$nextkey = NULL;
@ -140,6 +150,11 @@ class xmldb_table extends xmldb_object {
*/
function addIndex(&$index, $after=NULL) {
/// Detect duplicates first
if ($this->getIndex($index->getName())) {
throw new coding_exception('Duplicate index '.$index->getName().' specified in table '.$this->getName());
}
/// Calculate the previous and next indexes
$previndex = NULL;
$nextindex = NULL;