performed code formatting

This commit is contained in:
Steffen Schröder
2014-08-05 02:17:41 +02:00
parent 98b5f132dc
commit 28d2c08936
66 changed files with 4054 additions and 1901 deletions

View File

@ -49,13 +49,15 @@ class Database implements TimerListener {
$message = "Couldn't connect to Database: '{$connectError}'";
$this->maniaControl->quit($message, true);
}
$this->getMysqli()->set_charset("utf8");
$this->getMysqli()
->set_charset("utf8");
$this->initDatabase();
$this->optimizeTables();
// Register Method which checks the Database Connection every 5 seconds
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'checkConnection', 5000);
$this->maniaControl->getTimerManager()
->registerTimerListening($this, 'checkConnection', 5000);
// Children
$this->migrationHelper = new MigrationHelper($maniaControl);
@ -65,7 +67,8 @@ class Database implements TimerListener {
* Load the Database Config
*/
private function loadConfig() {
$databaseElements = $this->maniaControl->getConfig()->xpath('database');
$databaseElements = $this->maniaControl->getConfig()
->xpath('database');
if (!$databaseElements) {
$this->maniaControl->quit('No Database configured!', true);
}
@ -124,22 +127,26 @@ class Database implements TimerListener {
*/
private function initDatabase() {
// Try to connect
$result = $this->getMysqli()->select_db($this->config->name);
$result = $this->getMysqli()
->select_db($this->config->name);
if ($result) {
return true;
}
Logger::logInfo("Database '{$this->config->name}' doesn't exist! Trying to create it...");
// Create database
$databaseQuery = "CREATE DATABASE " . $this->getMysqli()->escape_string($this->config->name) . ";";
$this->getMysqli()->query($databaseQuery);
$databaseQuery = "CREATE DATABASE " . $this->getMysqli()
->escape_string($this->config->name) . ";";
$this->getMysqli()
->query($databaseQuery);
if ($this->getMysqli()->error) {
$this->maniaControl->quit($this->getMysqli()->error, true);
return false;
}
// Connect to new database
$this->getMysqli()->select_db($this->config->name);
$this->getMysqli()
->select_db($this->config->name);
if ($error = $this->getMysqli()->error) {
$message = "Couldn't select database '{$this->config->name}'. {$error}";
$this->maniaControl->quit($message, true);
@ -156,7 +163,8 @@ class Database implements TimerListener {
*/
private function optimizeTables() {
$showQuery = 'SHOW TABLES;';
$result = $this->getMysqli()->query($showQuery);
$result = $this->getMysqli()
->query($showQuery);
if ($error = $this->getMysqli()->error) {
Logger::logError($error);
return false;
@ -178,7 +186,8 @@ class Database implements TimerListener {
}
$result->free();
$optimizeQuery .= ';';
$this->getMysqli()->query($optimizeQuery);
$this->getMysqli()
->query($optimizeQuery);
if ($error = $this->getMysqli()->error) {
Logger::logError($error);
return false;
@ -217,7 +226,10 @@ class Database implements TimerListener {
* Check whether the Database Connection is still open
*/
public function checkConnection() {
if (!$this->getMysqli() || !$this->getMysqli()->ping()) {
if (!$this->getMysqli()
|| !$this->getMysqli()
->ping()
) {
$this->maniaControl->quit('The MySQL Server has gone away!', true);
}
}
@ -227,7 +239,8 @@ class Database implements TimerListener {
*/
public function __destruct() {
if ($this->getMysqli() && !$this->getMysqli()->connect_error) {
$this->getMysqli()->close();
$this->getMysqli()
->close();
}
}
}

View File

@ -40,7 +40,8 @@ class MigrationHelper {
$sourceClass = ClassUtil::getClass($sourceClass);
$targetClass = ClassUtil::getClass($targetClass);
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$mysqli = $this->maniaControl->getDatabase()
->getMysqli();
$query = "INSERT IGNORE INTO `" . SettingManager::TABLE_SETTINGS . "`
(`class`, `setting`, `type`, `value`, `default`)