replaced trigger_error calls by Logger methods

This commit is contained in:
Steffen Schröder 2014-08-03 13:29:54 +02:00
parent 53ccd70b45
commit c246568f95
9 changed files with 33 additions and 30 deletions

View File

@ -66,35 +66,35 @@ class Database implements TimerListener {
private function loadConfig() { private function loadConfig() {
$databaseElements = $this->maniaControl->getConfig()->xpath('database'); $databaseElements = $this->maniaControl->getConfig()->xpath('database');
if (!$databaseElements) { if (!$databaseElements) {
trigger_error('No Database configured!', E_USER_ERROR); Logger::logError('No Database configured!', E_USER_ERROR);
} }
$databaseElement = $databaseElements[0]; $databaseElement = $databaseElements[0];
// Host // Host
$hostElements = $databaseElement->xpath('host'); $hostElements = $databaseElement->xpath('host');
if (!$hostElements) { if (!$hostElements) {
trigger_error("Invalid database configuration (Host).", E_USER_ERROR); Logger::logError("Invalid database configuration (Host).", E_USER_ERROR);
} }
$host = (string)$hostElements[0]; $host = (string)$hostElements[0];
// Port // Port
$portElements = $databaseElement->xpath('port'); $portElements = $databaseElement->xpath('port');
if (!$portElements) { if (!$portElements) {
trigger_error("Invalid database configuration (Port).", E_USER_ERROR); Logger::logError("Invalid database configuration (Port).", E_USER_ERROR);
} }
$port = (string)$portElements[0]; $port = (string)$portElements[0];
// User // User
$userElements = $databaseElement->xpath('user'); $userElements = $databaseElement->xpath('user');
if (!$userElements) { if (!$userElements) {
trigger_error("Invalid database configuration (User).", E_USER_ERROR); Logger::logError("Invalid database configuration (User).", E_USER_ERROR);
} }
$user = (string)$userElements[0]; $user = (string)$userElements[0];
// Pass // Pass
$passElements = $databaseElement->xpath('pass'); $passElements = $databaseElement->xpath('pass');
if (!$passElements) { if (!$passElements) {
trigger_error("Invalid database configuration (Pass).", E_USER_ERROR); Logger::logError("Invalid database configuration (Pass).", E_USER_ERROR);
} }
$pass = (string)$passElements[0]; $pass = (string)$passElements[0];
@ -104,7 +104,7 @@ class Database implements TimerListener {
$nameElements = $databaseElement->xpath('db_name'); $nameElements = $databaseElement->xpath('db_name');
} }
if (!$nameElements) { if (!$nameElements) {
trigger_error("Invalid database configuration (Name).", E_USER_ERROR); Logger::logError("Invalid database configuration (Name).", E_USER_ERROR);
} }
$name = (string)$nameElements[0]; $name = (string)$nameElements[0];
@ -157,7 +157,7 @@ class Database implements TimerListener {
$showQuery = 'SHOW TABLES;'; $showQuery = 'SHOW TABLES;';
$result = $this->getMysqli()->query($showQuery); $result = $this->getMysqli()->query($showQuery);
if ($error = $this->getMysqli()->error) { if ($error = $this->getMysqli()->error) {
trigger_error($error); Logger::logError($error);
return false; return false;
} }
$count = $result->num_rows; $count = $result->num_rows;
@ -179,7 +179,7 @@ class Database implements TimerListener {
$optimizeQuery .= ';'; $optimizeQuery .= ';';
$this->getMysqli()->query($optimizeQuery); $this->getMysqli()->query($optimizeQuery);
if ($error = $this->getMysqli()->error) { if ($error = $this->getMysqli()->error) {
trigger_error($error); Logger::logError($error);
return false; return false;
} }
return true; return true;

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Files; namespace ManiaControl\Files;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
/** /**
@ -26,7 +27,7 @@ abstract class BackupUtil {
$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d_H-i') . '_' . time() . '.zip'; $backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d_H-i') . '_' . time() . '.zip';
$backupZip = new \ZipArchive(); $backupZip = new \ZipArchive();
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) { if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
trigger_error("Couldn't create backup zip!"); Logger::logError("Couldn't create backup zip!");
return false; return false;
} }
$excludes = array(); $excludes = array();
@ -47,11 +48,11 @@ abstract class BackupUtil {
private static function getBackupFolder() { private static function getBackupFolder() {
$backupFolder = ManiaControlDir . 'backup' . DIRECTORY_SEPARATOR; $backupFolder = ManiaControlDir . 'backup' . DIRECTORY_SEPARATOR;
if (!is_dir($backupFolder) && !mkdir($backupFolder)) { if (!is_dir($backupFolder) && !mkdir($backupFolder)) {
trigger_error("Couldn't create backup folder!"); Logger::logError("Couldn't create backup folder!");
return false; return false;
} }
if (!is_writeable($backupFolder)) { if (!is_writeable($backupFolder)) {
trigger_error("ManiaControl doesn't have the necessary write rights for the backup folder!"); Logger::logError("ManiaControl doesn't have the necessary write rights for the backup folder!");
return false; return false;
} }
return $backupFolder; return $backupFolder;
@ -71,7 +72,7 @@ abstract class BackupUtil {
array $baseFileNames = array()) { array $baseFileNames = array()) {
$folderHandle = opendir($folderName); $folderHandle = opendir($folderName);
if (!is_resource($folderHandle)) { if (!is_resource($folderHandle)) {
trigger_error("Couldn't open folder '{$folderName}' for backup!"); Logger::logError("Couldn't open folder '{$folderName}' for backup!");
return false; return false;
} }
$useBaseFileNames = !empty($baseFileNames); $useBaseFileNames = !empty($baseFileNames);
@ -117,7 +118,7 @@ abstract class BackupUtil {
$backupFileName = $backupFolder . 'backup_plugins_' . ManiaControl::VERSION . date('y-m-d_H-i') . '_' . time() . '.zip'; $backupFileName = $backupFolder . 'backup_plugins_' . ManiaControl::VERSION . date('y-m-d_H-i') . '_' . time() . '.zip';
$backupZip = new \ZipArchive(); $backupZip = new \ZipArchive();
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) { if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
trigger_error("Couldn't create backup zip!"); Logger::logError("Couldn't create backup zip!");
return false; return false;
} }
$directory = ManiaControlDir . 'plugins'; $directory = ManiaControlDir . 'plugins';

View File

@ -47,11 +47,11 @@ abstract class Logger {
public static function getLogsFolder() { public static function getLogsFolder() {
$logsFolder = ManiaControlDir . 'logs' . DIRECTORY_SEPARATOR; $logsFolder = ManiaControlDir . 'logs' . DIRECTORY_SEPARATOR;
if (!is_dir($logsFolder) && !mkdir($logsFolder)) { if (!is_dir($logsFolder) && !mkdir($logsFolder)) {
trigger_error("Couldn't create the logs folder!"); self::logError("Couldn't create the logs folder!");
return false; return false;
} }
if (!is_writeable($logsFolder)) { if (!is_writeable($logsFolder)) {
trigger_error("ManiaControl doesn't have the necessary write rights for the logs folder!"); self::logError("ManiaControl doesn't have the necessary write rights for the logs folder!");
return false; return false;
} }
return $logsFolder; return $logsFolder;

View File

@ -223,8 +223,7 @@ class MapManager implements CallbackListener {
$this->updateMapTimestamp($uid); $this->updateMapTimestamp($uid);
if (!isset($uid) || !isset($this->maps[$uid])) { if (!isset($uid) || !isset($this->maps[$uid])) {
trigger_error("Error while updating Map, unknown UID: " . $uid); $this->maniaControl->getChat()->sendError("Error updating Map: Unknown UID '{$uid}'!", $admin);
$this->maniaControl->getChat()->sendError("Error while updating Map.", $admin);
return; return;
} }
@ -385,8 +384,7 @@ class MapManager implements CallbackListener {
if ($this->maniaControl->getServer()->checkAccess($mapDir)) { if ($this->maniaControl->getServer()->checkAccess($mapDir)) {
// Create download directory if necessary // Create download directory if necessary
if (!is_dir($downloadDirectory) && !mkdir($downloadDirectory) || !is_writable($downloadDirectory)) { if (!is_dir($downloadDirectory) && !mkdir($downloadDirectory) || !is_writable($downloadDirectory)) {
trigger_error("ManiaControl doesn't have to rights to save maps in '{$downloadDirectory}'."); $this->maniaControl->getChat()->sendError("ManiaControl doesn't have to rights to save maps in '{$downloadDirectory}'.", $login);
$this->maniaControl->getChat()->sendError("ManiaControl doesn't have the rights to save maps.", $login);
return; return;
} }
@ -586,9 +584,7 @@ class MapManager implements CallbackListener {
$mapArray = array(); $mapArray = array();
foreach ($shuffledMaps as $map) { foreach ($shuffledMaps as $map) {
/** /** @var Map $map */
* @var Map $map
*/
$mapArray[] = $map->fileName; $mapArray[] = $map->fileName;
} }
@ -668,7 +664,7 @@ class MapManager implements CallbackListener {
try { try {
$this->maniaControl->getClient()->chooseNextMapList($mapArray); $this->maniaControl->getClient()->chooseNextMapList($mapArray);
} catch (Exception $e) { } catch (Exception $e) {
trigger_error("Error while restructuring the Maplist. " . $e->getMessage()); trigger_error("Error restructuring the Maplist. " . $e->getMessage());
return false; return false;
} }
return true; return true;

View File

@ -5,6 +5,7 @@ namespace ManiaControl\Plugins;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
@ -288,7 +289,7 @@ class PluginManager {
} }
$success = include_once $filePath; $success = include_once $filePath;
if (!$success) { if (!$success) {
trigger_error("Error loading File '{$filePath}'!"); Logger::logError("Couldn't load file '{$filePath}'!");
} }
continue; continue;
} }

View File

@ -8,6 +8,7 @@ use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Files\BackupUtil; use ManiaControl\Files\BackupUtil;
use ManiaControl\Files\FileUtil; use ManiaControl\Files\FileUtil;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Plugins\InstallMenu; use ManiaControl\Plugins\InstallMenu;
@ -268,7 +269,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
trigger_error($message); Logger::logError($message);
return; return;
} }
@ -279,7 +280,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
trigger_error($message); Logger::logError($message);
return; return;
} }

View File

@ -2,6 +2,8 @@
namespace ManiaControl\Utils; namespace ManiaControl\Utils;
use ManiaControl\Logger;
/** /**
* Class offering Methods to format Texts and Values * Class offering Methods to format Texts and Values
* *
@ -153,7 +155,7 @@ abstract class Formatter {
return $nations[$country]; return $nations[$country];
} }
if ($country) { if ($country) {
trigger_error("Couldn't map Country: '{$country}'!"); Logger::logWarning("Couldn't map Country: '{$country}'!");
} }
return 'OTH'; return 'OTH';
} }

View File

@ -15,6 +15,7 @@ use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Files\AsynchronousFileReader; use ManiaControl\Files\AsynchronousFileReader;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
@ -399,7 +400,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
private function getGameModeString() { private function getGameModeString() {
$gameMode = $this->maniaControl->getServer()->getGameMode(); $gameMode = $this->maniaControl->getServer()->getGameMode();
if ($gameMode === null) { if ($gameMode === null) {
trigger_error("Couldn't retrieve game mode."); Logger::logError("Couldn't retrieve game mode.");
return null; return null;
} }
switch ($gameMode) { switch ($gameMode) {
@ -753,7 +754,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
// Called method response // Called method response
if (!$methodResponse[0]) { if (!$methodResponse[0]) {
trigger_error("Records Plugin: Submitting dedimania records failed."); Logger::logError("Records Plugin: Submitting dedimania records failed.");
} }
if (self::DEDIMANIA_DEBUG) { if (self::DEDIMANIA_DEBUG) {

View File

@ -15,6 +15,7 @@ use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\Models\RecordCallback; use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
@ -223,7 +224,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$records = $this->getLocalRecords($map); $records = $this->getLocalRecords($map);
if (!is_array($records)) { if (!is_array($records)) {
trigger_error("Couldn't fetch player records."); Logger::logError("Couldn't fetch player records.");
return null; return null;
} }