1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

MySQL: Refactored 'db_Table_exists' to 'isTable' method. (BC compatible) and removed use of pref global.

This commit is contained in:
Cameron 2015-07-07 13:02:34 -07:00
parent a27dc90ca7
commit 483d43a829
6 changed files with 46 additions and 23 deletions

View File

@ -83,7 +83,7 @@ if (isset($_POST['del_existing']) && $_POST['lang_choices'] && getperms('0'))
foreach ($tabs as $del_table)
{
if ($sql->db_Table_exists($del_table, $lang))
if ($sql->isTable($del_table, $lang))
{
// echo $del_table." exists<br />";
$qry = "DROP TABLE ".$mySQLprefix."lan_".$lang."_".$del_table;
@ -140,7 +140,7 @@ if (isset($_POST['create_tables']) && $_POST['language'])
}
}
}
elseif ($sql->db_Table_exists($value,$_POST['language']))
elseif ($sql->isTable($value,$_POST['language']))
{
if ($_POST['remove'])
{
@ -464,7 +464,7 @@ if (varset($_GET['mode']) == 'db' && !empty($_GET['action']) && !empty($_GET['l
if (stristr($languageSelected, $installed) === FALSE)
{
$selected = ($sql->db_Table_exists($table_name,$languageSelected)) ? " checked='checked'" : "";
$selected = ($sql->isTable($table_name,$languageSelected)) ? " checked='checked'" : "";
$tableName = ucfirst(str_replace("_", " ", $table_name));
$tableLabel = ($selected) ? "<span class='label label-success'>".$tableName."</span>" : $tableName;
@ -768,7 +768,7 @@ function multilang_db()
foreach ($tabs as $tab_name)
{
if ($e_language != $pref['sitelanguage'] && $sql->db_Table_exists($tab_name,$e_language))
if ($e_language != $pref['sitelanguage'] && $sql->isTable($tab_name,$e_language))
{
$installed[] = $tab_name;
}

View File

@ -901,7 +901,7 @@ function update_706_to_800($type='')
// Next bit will be needed only by the brave souls who used an early CVS - probably delete before release
if ($sql->db_Table_exists('rl_history') && !$sql->db_Table_exists('dblog'))
if ($sql->isTable('rl_history') && !$sql->isTable('dblog'))
{
if ($just_check) return update_needed('Rename rl_history to dblog');
$sql->gen('ALTER TABLE `'.MPREFIX.'rl_history` RENAME `'.MPREFIX.'dblog`');
@ -913,7 +913,7 @@ function update_706_to_800($type='')
//---------------------------------
if ($sql->db_Table_exists('dblog') && !$sql->db_Table_exists('admin_log'))
if ($sql->isTable('dblog') && !$sql->isTable('admin_log'))
{
if ($just_check) return update_needed('Rename dblog to admin_log');
$sql->gen('ALTER TABLE `'.MPREFIX.'dblog` RENAME `'.MPREFIX.'admin_log`');
@ -929,7 +929,7 @@ function update_706_to_800($type='')
/*
foreach ($new_tables as $nt)
{
if (!$sql->db_Table_exists($nt))
if (!$sql->isTable($nt))
{
if ($just_check) return update_needed('Add table: '.$nt);
// Get the definition
@ -1074,7 +1074,7 @@ function update_706_to_800($type='')
$sql->mySQLtableList = false; // clear the cached table list.
foreach ($obs_tables as $ot)
{
if ($sql->db_Table_exists($ot))
if ($sql->isTable($ot))
{
if ($just_check) return update_needed("Delete table: ".$ot);
@ -1088,7 +1088,7 @@ function update_706_to_800($type='')
// Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
foreach ($ip_upgrade as $t => $f)
{
if ($sql->db_Table_exists($t))
if ($sql->isTable($t))
{ // Check for table - might add some core plugin tables in here
if ($field_info = ($sql->db_Field($t, $f, '', TRUE)))
{
@ -1876,7 +1876,7 @@ function update_needed($message='')
function addIndexToTable($target, $indexSpec, $just_check, &$updateMessages, $optionalTable=FALSE)
{
global $sql;
if (!$sql->db_Table_exists($target))
if (!$sql->isTable($target))
{
if ($optionalTable)
{

View File

@ -615,7 +615,7 @@ class db_table_admin
$debugLevel = E107_DBG_SQLDETAILS;
$tableName = $newStructure[1];
if (!$sql->db_Table_exists($tableName))
if (!$sql->isTable($tableName))
{
if ($makeNewifNotExist === FALSE)
{

View File

@ -1476,7 +1476,7 @@ class e_db_mysql
if($multiple == FALSE)
{
$mltable = "lan_".strtolower($this->mySQLlanguage.'_'.$table);
return ($this->db_Table_exists($table,$this->mySQLlanguage) ? $mltable : $table);
return ($this->isTable($table,$this->mySQLlanguage) ? $mltable : $table);
}
else // return an array of all matching language tables. eg [french]->e107_lan_news
{
@ -1832,43 +1832,66 @@ class e_db_mysql
}
/**
* Legacy Alias of isTable();
* @deprecated
* @param $table
* @param string $language
* @return bool
*/
public function db_Table_exists($table,$language='')
{
return $this->isTable($table, $language);
}
/**
* Verify whether a table exists, without causing an error
*
* @param string $table Table name without the prefix
* @param string $lanMode [optional] When set to TRUE, searches for multilanguage tables
* @param string $language (optional) leave blank to search for a regular table, or language-name to search for a language table.
* @example $sql->isTable('news','Spanish');
* @return boolean TRUE if exists
*
* NOTES: Slower (28ms) than "SELECT 1 FROM" (4-5ms), but doesn't produce MySQL errors.
* Multiple checks on a single page will only use 1 query. ie. faster on multiple calls.
*/
public function db_Table_exists($table,$language='')
public function isTable($table, $language='')
{
global $pref;
// global $pref;
$table = strtolower($table); // precaution for multilanguage
// it's lan table check
if($language)
if(!empty($language)) //ie. is it a language table?
{
// TODO - discuss this!!! Smells like mislogic - we ignore e.g. bulgarian_news when default language is Bulgarian!
if($language == $pref['sitelanguage']) return false;
$sitelanguage = $this->getConfig()->get('sitelanguage');
if($language == $sitelanguage)
{
return false;
}
if(!isset($this->mySQLtableListLanguage[$language]))
{
$this->mySQLtableListLanguage = $this->db_mySQLtableList($language);
}
return in_array('lan_'.strtolower($language)."_".$table,$this->mySQLtableListLanguage[$language]);
}
else
else // regular search
{
if(!$this->mySQLtableList)
{
$this->mySQLtableList = $this->db_mySQLtableList();
}
return in_array($table,$this->mySQLtableList);
}
}
/**
* Populate mySQLtableList and mySQLtableListLanguage
* TODO - better runtime cache - use e107::getRegistry() && e107::setRegistry()
@ -2045,7 +2068,7 @@ class e_db_mysql
return FALSE;
}
if(!$this->db_Table_exists($newtable))
if(!$this->isTable($newtable))
{
$result = $this->db_Query($qry);
}

View File

@ -86,7 +86,7 @@ class featurebox_setup
function upgrade_required()
{
if(!e107::getDb()->db_Table_exists('featurebox_category'))
if(!e107::getDb()->isTable('featurebox_category'))
{
return true; // true to trigger an upgrade alert, and false to not.
}

View File

@ -49,7 +49,7 @@ class forum_setup
*/
function upgrade_required()
{
if(!e107::getDb()->db_Table_exists('forum_thread'))
if(!e107::getDb()->isTable('forum_thread'))
{
return true;
}