Skip to content

Commit

Permalink
Updates to compliment 1ea4d07
Browse files Browse the repository at this point in the history
  • Loading branch information
xerora committed Oct 14, 2013
1 parent 1ea4d07 commit 00c9cac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
6 changes: 4 additions & 2 deletions modules/page/setup/patch_0.9.14.inc
Expand Up @@ -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);
}
}
8 changes: 5 additions & 3 deletions plugins/tags/setup/patch_0.9.14.inc
@@ -1,11 +1,13 @@
<?php defined('COT_CODE') or die('Wrong URL');

if(!(bool)$db->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`");
}
6 changes: 4 additions & 2 deletions setup/siena/patch_0.9.14-01.inc
Expand Up @@ -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);
}
}
10 changes: 3 additions & 7 deletions system/database.php
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit 00c9cac

Please sign in to comment.