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

View File

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

View File

@ -47,11 +47,11 @@ abstract class Logger {
public static function getLogsFolder() {
$logsFolder = ManiaControlDir . 'logs' . DIRECTORY_SEPARATOR;
if (!is_dir($logsFolder) && !mkdir($logsFolder)) {
trigger_error("Couldn't create the logs folder!");
self::logError("Couldn't create the logs folder!");
return false;
}
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 $logsFolder;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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