diff --git a/modules/page/setup/patch_0.9.14.inc b/modules/page/setup/patch_0.9.14.inc index 55ed715cc..f25d713d8 100644 --- a/modules/page/setup/patch_0.9.14.inc +++ b/modules/page/setup/patch_0.9.14.inc @@ -7,10 +7,12 @@ $page_add_indexes = array( 'page_title' ); +require_once cot_incfile('page', 'module'); + foreach($page_add_indexes as $index) { - if(!(bool)$db->query("SHOW INDEXES FROM `cot_pages` WHERE `Key_name`='".$index."'")->fetch()) + if(!$db->indexExists($db_pages, $index, $index)) { - $db->query("ALTER TABLE `cot_pages` ADD INDEX `".$index."` (`".$index."`)"); + $db->addIndex($db_pages, $index); } } \ No newline at end of file diff --git a/plugins/tags/setup/patch_0.9.14.inc b/plugins/tags/setup/patch_0.9.14.inc index ce650c8dd..6691f16f1 100644 --- a/plugins/tags/setup/patch_0.9.14.inc +++ b/plugins/tags/setup/patch_0.9.14.inc @@ -1,11 +1,13 @@ query("SHOW INDEXES FROM `cot_tag_references` WHERE `Key_name`='tag_area_item'")->fetch()) +require_once cot_incfile('tags', 'plug'); + +if(!$db->indexExists($db_tag_references, 'tag_area_item', array('tag_area', 'tag_item'))) { - $db->query("ALTER TABLE `cot_tag_references` ADD INDEX `tag_area_item` (`tag_area`, `tag_item`)"); + $db->addIndex($db_tag_references, 'tag_area_item', array('tag_area', 'tag_item')); } -if((bool)$db->query("SHOW INDEXES FROM `cot_tag_references` WHERE `Key_name`='tag_item'")->fetch()) +if($db->indexExists($db_tag_references, 'tag_item')) { $db->query("ALTER TABLE `cot_tag_references` DROP INDEX `tag_item`"); } \ No newline at end of file diff --git a/setup/siena/patch_0.9.14-01.inc b/setup/siena/patch_0.9.14-01.inc index 0c7ce47c3..16ec45d81 100644 --- a/setup/siena/patch_0.9.14-01.inc +++ b/setup/siena/patch_0.9.14-01.inc @@ -8,10 +8,12 @@ $users_add_indexes = array( 'user_lostpass' ); +global $db_users; + foreach($users_add_indexes as $index) { - if(!(bool)$db->query("SHOW INDEXES FROM `cot_users` WHERE `Key_name`='".$index."'")->fetch()) + if(!$db->indexExists($db_users, $index, $index)) { - $db->query("ALTER TABLE `cot_users` ADD INDEX `".$index."` (`".$index."`)"); + $db->addIndex($db_users, $index); } } \ No newline at end of file diff --git a/system/database.php b/system/database.php index ac55c9f8f..9161bfa3c 100644 --- a/system/database.php +++ b/system/database.php @@ -284,17 +284,13 @@ function fieldExists($table_name, $field_name) * * @param string $table_name Table name * @param string $index_name Index/Key name - * @param mixed $index_columns Either a string for a single column name or an array for single/multiple columns. $index_name will be used if empty. + * @param mixed $index_columns Either a string for a single column name or an array for single/multiple columns. No column check will be preformed if left empty. * @return bool TRUE if the index name or column order exists, FALSE otherwise */ function indexExists($table_name, $index_name, $index_columns = array()) { $existing_indexes = $this->query("SHOW INDEXES FROM `$table_name`")->fetchAll(); - if(empty($index_columns)) - { - $index_columns = array($index_name); - } - if(!is_array($index_columns)) + if(!empty($index_columns) && !is_array($index_columns)) { $index_columns = array($index_columns); } @@ -311,7 +307,7 @@ function indexExists($table_name, $index_name, $index_columns = array()) $exists = true; break; } - if(count(array_diff_assoc($index_columns, $list_columns)) === 0 && count($index_columns) === count($list_columns)) + if(!empty($index_columns) && count(array_diff_assoc($index_columns, $list_columns)) === 0 && count($index_columns) === count($list_columns)) { $exists = true; break;