diff --git a/application/core/AutoLoader.php b/application/core/AutoLoader.php index 370a2cce..7260c92d 100644 --- a/application/core/AutoLoader.php +++ b/application/core/AutoLoader.php @@ -9,7 +9,7 @@ namespace ManiaControl; * @copyright 2014 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class AutoLoader { +abstract class AutoLoader { /** * Register the Auto Loader @@ -17,6 +17,7 @@ class AutoLoader { public static function register() { spl_autoload_register(array(get_class(), 'autoload')); } + /** * Try to autoload the Class with the given Name * diff --git a/application/core/Files/BackupUtil.php b/application/core/Files/BackupUtil.php index 9449d3be..784113a9 100644 --- a/application/core/Files/BackupUtil.php +++ b/application/core/Files/BackupUtil.php @@ -12,10 +12,6 @@ use ManiaControl\ManiaControl; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ abstract class BackupUtil { - /* - * Constants - */ - const FOLDER_NAME_BACKUP = 'backup'; /** * Perform a Full Backup of ManiaControl @@ -30,7 +26,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!"); + trigger_error("Couldn't create backup zip!"); return false; } $excludes = array(); @@ -46,16 +42,16 @@ abstract class BackupUtil { /** * Get the Backup Folder Path and create it if necessary * - * @return string + * @return string|bool */ private static function getBackupFolder() { - $backupFolder = ManiaControlDir . self::FOLDER_NAME_BACKUP . DIRECTORY_SEPARATOR; + $backupFolder = ManiaControlDir . 'backup' . DIRECTORY_SEPARATOR; if (!is_dir($backupFolder) && !mkdir($backupFolder)) { - trigger_error("Couldn't create Backup Folder!"); + trigger_error("Couldn't create backup folder!"); return false; } if (!is_writeable($backupFolder)) { - trigger_error("ManiaControl doesn't have the necessary Writing Rights for the Backup Folder!"); + trigger_error("ManiaControl doesn't have the necessary write rights for the backup folder!"); return false; } return $backupFolder; @@ -71,10 +67,11 @@ abstract class BackupUtil { * @param array $baseFileNames * @return bool */ - private static function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array(), array $baseFileNames = array()) { + private static function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array(), + array $baseFileNames = array()) { $folderHandle = opendir($folderName); if (!is_resource($folderHandle)) { - trigger_error("Couldn't open Folder '{$folderName}' for Backup!"); + trigger_error("Couldn't open folder '{$folderName}' for backup!"); return false; } $useBaseFileNames = !empty($baseFileNames); @@ -120,7 +117,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!"); + trigger_error("Couldn't create backup zip!"); return false; } $directory = ManiaControlDir . 'plugins'; diff --git a/application/core/Files/FileUtil.php b/application/core/Files/FileUtil.php index eaf31e03..ec27a9f5 100644 --- a/application/core/Files/FileUtil.php +++ b/application/core/Files/FileUtil.php @@ -70,7 +70,7 @@ abstract class FileUtil { } /** - * Load config xml-file + * Load Config XML File * * @param string $fileName * @return \SimpleXMLElement @@ -78,11 +78,11 @@ abstract class FileUtil { public static function loadConfig($fileName) { $fileLocation = ManiaControlDir . 'configs' . DIRECTORY_SEPARATOR . $fileName; if (!file_exists($fileLocation)) { - Logger::log("Config File doesn't exist! ({$fileName})"); + Logger::log("Config file doesn't exist! ({$fileName})"); return null; } if (!is_readable($fileLocation)) { - Logger::log("Config File isn't readable! Please check the File Permissions. ({$fileName})"); + Logger::log("Config file isn't readable! Please check the file permissions. ({$fileName})"); return null; } $configXml = @simplexml_load_file($fileLocation); @@ -112,20 +112,24 @@ abstract class FileUtil { * @return bool */ public static function removeTempFolder() { - $tempFolder = self::getTempFolder(false); + $tempFolder = self::getTempFolder(); return @rmdir($tempFolder); } /** * Get the Temporary Folder and create it if necessary * - * @param bool $createIfNecessary - * @return string + * @return string|bool */ - public static function getTempFolder($createIfNecessary = true) { + public static function getTempFolder() { $tempFolder = ManiaControlDir . 'temp' . DIRECTORY_SEPARATOR; - if ($createIfNecessary && !is_dir($tempFolder)) { - mkdir($tempFolder); + if (!is_dir($tempFolder) && !mkdir($tempFolder)) { + trigger_error("Couldn't create the temp folder!"); + return false; + } + if (!is_writeable($tempFolder)) { + trigger_error("ManiaControl doesn't have the necessary write rights for the temp folder!"); + return false; } return $tempFolder; } @@ -140,7 +144,6 @@ abstract class FileUtil { if (!is_array($directories)) { $directories = array($directories); } - foreach ($directories as $directory) { $dir = new \RecursiveDirectoryIterator(ManiaControlDir . $directory); foreach (new \RecursiveIteratorIterator($dir) as $fileName => $file) { @@ -148,8 +151,7 @@ abstract class FileUtil { continue; } if (!is_writable($fileName)) { - $message = "Write-Access missing for File '{$fileName}'!"; - Logger::log($message); + Logger::log("Write access missing for file '{$fileName}'!"); return false; } } @@ -165,7 +167,7 @@ abstract class FileUtil { * @return bool */ public static function deleteOldLogFiles($maxFileAgeInDays = 10.) { - $logsFolderPath = Logger::getLogsFolderPath(); + $logsFolderPath = Logger::getLogsFolder(); if (!is_readable($logsFolderPath)) { return false; } diff --git a/application/core/Logger.php b/application/core/Logger.php index f6d36ef1..41976b7a 100644 --- a/application/core/Logger.php +++ b/application/core/Logger.php @@ -37,39 +37,21 @@ class Logger { } /** - * Create the Logs Folder and return its Path if successful + * Get the Logs Folder and create it if necessary * - * @return bool|string + * @return string|bool */ - private static function createLogsFolder() { - $logsFolderPath = self::getLogsFolderPath(); - if (!is_dir($logsFolderPath) && !mkdir($logsFolderPath)) { - self::output("Couldn't create Logs Folder, please check the File Permissions!"); + public static function getLogsFolder() { + $logsFolder = ManiaControlDir . 'logs' . DIRECTORY_SEPARATOR; + if (!is_dir($logsFolder) && !mkdir($logsFolder)) { + trigger_error("Couldn't create the logs folder!"); return false; } - return $logsFolderPath; - } - - /** - * Build the Logs Folder Path - * - * @return string - */ - public static function getLogsFolderPath() { - return ManiaControlDir . 'logs' . DIRECTORY_SEPARATOR; - } - - /** - * Echo the given Message - * - * @param string $message - * @param bool $eol - */ - public static function output($message, $eol = true) { - if ($eol) { - $message = '[' . date('d-M-Y H:i:s e') . '] ' . $message . PHP_EOL; + if (!is_writeable($logsFolder)) { + trigger_error("ManiaControl doesn't have the necessary write rights for the logs folder!"); + return false; } - echo $message; + return $logsFolder; } /** @@ -98,6 +80,19 @@ class Logger { } } + /** + * Echo the given Message + * + * @param string $message + * @param bool $eol + */ + public static function output($message, $eol = true) { + if ($eol) { + $message = '[' . date('d-M-Y H:i:s e') . '] ' . $message . PHP_EOL; + } + echo $message; + } + /** * Log and echo the given Info Message *