Skip to content

Commit

Permalink
[443] Use Armory::Log() method instead of $this->logHandler in Armory…
Browse files Browse the repository at this point in the history
…DatabaseHandler class
  • Loading branch information
Shadez committed Jan 3, 2011
1 parent 3fbd548 commit d00b02a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 46 deletions.
4 changes: 2 additions & 2 deletions character-select-submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 440
* @revision 443
* @copyright (c) 2009-2011 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -45,7 +45,7 @@
continue;
}
$realm_info = Armory::$realmData[$realm_id];
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
if(!$db) {
// Error message will appear in ArmoryDatabaseHandler::ArmoryDatabaseHandler();
continue;
Expand Down
8 changes: 4 additions & 4 deletions includes/classes/class.arenateams.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 442
* @revision 443
* @copyright (c) 2009-2011 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -241,7 +241,7 @@ public function BuildArenaLadderList($type, $page, $num = false, $order = 'ratin
if($num == true) {
$summary = 0;
foreach(Armory::$realmData as $realm_info) {
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
$current_count = $db->selectCell("SELECT COUNT(`arena_team`.`arenateamid`) FROM `arena_team` AS `arena_team` LEFT JOIN `arena_team_stats` AS `arena_team_stats` ON `arena_team_stats`.`arenateamid` = `arena_team`.`arenateamid` WHERE `arena_team`.`type` = %d AND `arena_team_stats`.`rank` > 0", $type);
$summary = $current_count+$summary;
}
Expand All @@ -250,7 +250,7 @@ public function BuildArenaLadderList($type, $page, $num = false, $order = 'ratin
$result_areanteams = array();
$i = 0;
foreach(Armory::$realmData as $realm_info) {
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
if($order == 'lose') {
// Special sorting
switch($realm_info['type']) {
Expand Down Expand Up @@ -404,7 +404,7 @@ public function GetArenaTeamEmblem($teamId = 0, $db = null) {
public function CountArenaTeams($type) {
$summary = 0;
foreach(Armory::$realmData as $realm_info) {
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
$current_count = $db->selectCell("SELECT COUNT(`arenateamid`) FROM `arena_team` WHERE `type`=%d", $type);
$summary += $current_count;
}
Expand Down
14 changes: 7 additions & 7 deletions includes/classes/class.armory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 440
* @revision 443
* @copyright (c) 2009-2011 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -80,8 +80,8 @@ public static function InitializeArmory() {
self::$armoryconfig = $ArmoryConfig['settings'];
self::$debugHandler = new ArmoryDebug(array('useDebug' => self::$armoryconfig['useDebug'], 'logLevel' => self::$armoryconfig['logLevel']));
self::$realmData = $ArmoryConfig['multiRealm'];
self::$aDB = new ArmoryDatabaseHandler(self::$mysqlconfig['host_armory'], self::$mysqlconfig['user_armory'], self::$mysqlconfig['pass_armory'], self::$mysqlconfig['name_armory'], self::$mysqlconfig['charset_armory'], self::Log(), self::$armoryconfig['db_prefix']);
self::$rDB = new ArmoryDatabaseHandler(self::$mysqlconfig['host_realmd'], self::$mysqlconfig['user_realmd'], self::$mysqlconfig['pass_realmd'], self::$mysqlconfig['name_realmd'], self::$mysqlconfig['charset_realmd'], self::Log());
self::$aDB = new ArmoryDatabaseHandler(self::$mysqlconfig['host_armory'], self::$mysqlconfig['user_armory'], self::$mysqlconfig['pass_armory'], self::$mysqlconfig['name_armory'], self::$mysqlconfig['charset_armory'], self::$armoryconfig['db_prefix']);
self::$rDB = new ArmoryDatabaseHandler(self::$mysqlconfig['host_realmd'], self::$mysqlconfig['user_realmd'], self::$mysqlconfig['pass_realmd'], self::$mysqlconfig['name_realmd'], self::$mysqlconfig['charset_realmd']);
if(isset($_GET['r'])) {
if(preg_match('/,/', $_GET['r'])) {
// Achievements/statistics comparison cases
Expand All @@ -94,19 +94,19 @@ public static function InitializeArmory() {
$realm_info = self::$aDB->selectRow("SELECT `id`, `version` FROM `ARMORYDBPREFIX_realm_data` WHERE `name`='%s'", $realmName);
if(isset(self::$realmData[$realm_info['id']])) {
self::$connectionData = self::$realmData[$realm_info['id']];
self::$cDB = new ArmoryDatabaseHandler(self::$connectionData['host_characters'], self::$connectionData['user_characters'], self::$connectionData['pass_characters'], self::$connectionData['name_characters'], self::$connectionData['charset_characters'], self::Log());
self::$cDB = new ArmoryDatabaseHandler(self::$connectionData['host_characters'], self::$connectionData['user_characters'], self::$connectionData['pass_characters'], self::$connectionData['name_characters'], self::$connectionData['charset_characters']);
self::$currentRealmInfo = array('name' => self::$connectionData['name'], 'id' => $realm_info['id'], 'type' => self::$connectionData['type'], 'connected' => true);
if(isset(self::$connectionData['name_world'])) {
self::$wDB = new ArmoryDatabaseHandler(self::$connectionData['host_world'], self::$connectionData['user_world'], self::$connectionData['pass_world'], self::$connectionData['name_world'], self::$connectionData['charset_world'], self::Log());
self::$wDB = new ArmoryDatabaseHandler(self::$connectionData['host_world'], self::$connectionData['user_world'], self::$connectionData['pass_world'], self::$connectionData['name_world'], self::$connectionData['charset_world']);
}
}
}
$realm_info = self::$realmData[1];
if(self::$cDB == null) {
self::$cDB = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], self::Log());
self::$cDB = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
}
if(self::$wDB == null) {
self::$wDB = new ArmoryDatabaseHandler($realm_info['host_world'], $realm_info['user_world'], $realm_info['pass_world'], $realm_info['name_world'], $realm_info['charset_world'], self::Log());
self::$wDB = new ArmoryDatabaseHandler($realm_info['host_world'], $realm_info['user_world'], $realm_info['pass_world'], $realm_info['name_world'], $realm_info['charset_world']);
}
if(!self::$currentRealmInfo) {
self::$currentRealmInfo = array('name' => $realm_info['name'], 'id' => 1, 'type' => $realm_info['type'], 'connected' => true);
Expand Down
4 changes: 2 additions & 2 deletions includes/classes/class.characters.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 441
* @revision 443
* @copyright (c) 2009-2011 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -276,7 +276,7 @@ public function BuildCharacter($name, $realmId = 1, $full = true, $initialBuild
return false;
}
$realm_info = Armory::$realmData[$realmId];
$this->db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$this->db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
if(!$this->db || !$this->db->TestLink()) {
Armory::Log()->writeError('%s : unable to connect to MySQL server (error: %s; realmId: %d). Check your configs.', __METHOD__, mysql_error(), $realmId);
return false;
Expand Down
23 changes: 8 additions & 15 deletions includes/classes/class.dbhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 420
* @revision 443
* @copyright (c) 2009-2011 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -43,7 +43,6 @@
/** Queries counter **/
private $queryCount = 0;
private $queryTimeGeneration = 0.0;
private $logHandler = null;
private $armory_prefix = null;

/** Error messages **/
Expand All @@ -61,26 +60,20 @@
* @param string $password
* @param string $dbName
* @param string $charset = null
* @param string $logHandler = null
* @param string $prefix = null
* @return bool
**/
public function ArmoryDatabaseHandler($host, $user, $password, $dbName, $charset = null, $logHandler = null, $prefix = null) {
$this->logHandler = $logHandler;
public function ArmoryDatabaseHandler($host, $user, $password, $dbName, $charset = null, $prefix = null) {
$this->connectionLink = @mysql_connect($host, $user, $password, true);
if(!$this->connectionLink) {
$this->errmsg = @mysql_error($this->connectionLink);
$this->errno = @mysql_errno($this->connectionLink);
if(is_object($this->logHandler)) {
$this->logHandler->writeError('%s : unable to connect to MySQL Server (host: "%s", dbName: "%s"). Error: %s. Check your configs.', __METHOD__, $host, $dbName, $this->errmsg ? $this->errmsg : 'none');
}
Armory::Log()->writeError('%s : unable to connect to MySQL Server (host: "%s", dbName: "%s"). Error: %s. Check your configs.', __METHOD__, $host, $dbName, $this->errmsg ? $this->errmsg : 'none');
return false;
}
$this->dbLink = @mysql_select_db($dbName, $this->connectionLink);
if(!$this->dbLink) {
if(is_object($this->logHandler)) {
$this->logHandler->writeError('%s : unable to switch to database "%s"!', __METHOD__, $dbName);
}
Armory::Log()->writeError('%s : unable to switch to database "%s"!', __METHOD__, $dbName);
return false;
}
if($charset == null) {
Expand Down Expand Up @@ -140,8 +133,8 @@ private function _query($safe_sql, $queryType) {
$this->errmsg = @mysql_error($this->connectionLink);
$this->errno = @mysql_errno($this->connectionLink);
if($performed_query == false) {
if($this->logHandler != null && is_object($this->logHandler) && !$this->disableNextError) {
$this->logHandler->writeLog('%s : unable to execute SQL query (%s). MySQL error: %s', __METHOD__, $safe_sql, $this->errmsg ? sprintf('"%s" (Error #%d)', $this->errmsg, $this->errno) : 'none');
if(!$this->disableNextError) {
Armory::Log()->writeLog('%s : unable to execute SQL query (%s). MySQL error: %s', __METHOD__, $safe_sql, $this->errmsg ? sprintf('"%s" (Error #%d)', $this->errmsg, $this->errno) : 'none');
}
if($this->disableNextError) {
$this->disableNextError = false;
Expand Down Expand Up @@ -214,7 +207,7 @@ private function _prepareQuery($funcArgs, $numArgs, $query_type) {
$safe_sql = call_user_func_array('sprintf', $funcArgs);
if(preg_match('/ARMORYDBPREFIX/', $safe_sql)) {
if($this->armory_prefix == null) {
$this->logHandler->writeError('%s : fatal error: armory database prefix is not defined, unable to execute SQL query (%s)!', __METHOD__, $safe_sql);
Armory::Log()->writeError('%s : fatal error: armory database prefix is not defined, unable to execute SQL query (%s)!', __METHOD__, $safe_sql);
return false;
}
$safe_sql = str_replace('ARMORYDBPREFIX', $this->armory_prefix, $safe_sql);
Expand Down Expand Up @@ -267,7 +260,7 @@ public function selectObject($query) {
**/
private function ConvertArray($source) {
if(!is_array($source)) {
$this->logHandler->writeError('%s : source must have array type!', __METHOD__);
Armory::Log()->writeError('%s : source must have array type!', __METHOD__);
return null;
}
$returnString = null;
Expand Down
14 changes: 7 additions & 7 deletions includes/classes/class.search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 441
* @revision 443
* @copyright (c) 2009-2011 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -494,14 +494,14 @@ public function PerformArenaTeamsSearch($num = false) {
if($num == true) {
foreach(Armory::$realmData as $realm_info) {
$count_results_currrent_realm = 0;
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
$count_results_currrent_realm = $db->selectCell("SELECT COUNT(`arenateamid`) FROM `arena_team` WHERE `name` LIKE '%s' LIMIT 200", '%'.$this->searchQuery.'%');
$count_results = $count_results + $count_results_currrent_realm;
}
return $count_results;
}
foreach(Armory::$realmData as $realm_info) {
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
$current_realm = $db->select("
SELECT `arena_team`.`name`, `arena_team`.`type` AS `size`, `arena_team_stats`.`rating`, `characters`.`race`
FROM `arena_team` AS `arena_team`
Expand Down Expand Up @@ -541,14 +541,14 @@ public function PerformGuildsSearch($num = false) {
if($num == true) {
foreach(Armory::$realmData as $realm_info) {
$count_results_currrent_realm = 0;
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
$count_results_currrent_realm = $db->selectCell("SELECT COUNT(`guildid`) FROM `guild` WHERE `name` LIKE '%s' LIMIT 200", '%'.$this->searchQuery.'%');
$count_results = $count_results + $count_results_currrent_realm;
}
return $count_results;
}
foreach(Armory::$realmData as $realm_info) {
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
$current_realm = $db->select("SELECT `guild`.`name`, `characters`.`race` FROM `guild` AS `guild` LEFT JOIN `characters` AS `characters` ON `guild`.`leaderguid`=`characters`.`guid` WHERE `guild`.`name` LIKE '%s' LIMIT 200", '%'.$this->searchQuery.'%');
if(!$current_realm) {
continue;
Expand Down Expand Up @@ -585,7 +585,7 @@ public function PerformCharactersSearch($num = false) {
if($num == true) {
foreach(Armory::$realmData as $realm_info) {
$count_results_currrent_realm = 0;
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
$characters_data[] = $db->select("SELECT `guid`, `level`, `account` FROM `characters` WHERE `name`='%s' AND `level` >= %d LIMIT 200", $this->searchQuery, Armory::$armoryconfig['minlevel']);
}
for($ii = 0; $ii < $countRealmData; $ii++) {
Expand All @@ -600,7 +600,7 @@ public function PerformCharactersSearch($num = false) {
}
$accounts_cache = array(); // For relevance calculation
foreach(Armory::$realmData as $realm_info) {
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], Armory::Log());
$db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
if(!$db) {
continue;
}
Expand Down
Loading

0 comments on commit d00b02a

Please sign in to comment.