Exemplo n.º 1
0
 function onLoad()
 {
     parent::onLoad();
     $config = ManagerConfig::getInstance();
     $this->db = \ManiaLive\Database\Connection::getConnection($config->host, $config->username, $config->password, $config->database, $config->type, $config->port);
     $status = $this->connection->getStatus();
     $quotedHost = $this->db->quote(Config::getInstance()->host);
     $quotedLogin = $this->db->quote($this->storage->serverLogin);
     $quotedPassword = $this->db->quote(Config::getInstance()->password);
     $quotedStatus = $this->db->quote($status->name);
     $this->db->execute('INSERT INTO Servers (hostname, port, login, superAdminPassword, status) ' . 'VALUES (%s,%d,%s,%s,%s) ' . 'ON DUPLICATE KEY UPDATE login = VALUES(login), ' . 'superAdminPassword = VALUES(superAdminPassword), ' . 'status = VALUES(status)', $quotedHost, Config::getInstance()->port, $quotedLogin, $quotedPassword, $quotedStatus);
     $this->enableDedicatedEvents();
     $this->enableApplicationEvents();
     $this->enableTickerEvent();
 }
Exemplo n.º 2
0
 private function setUpDatabase()
 {
     $dbConfig = \ManiaLive\Database\Config::getInstance();
     $this->database = Connection::getConnection($dbConfig->host, $dbConfig->username, $dbConfig->password, $dbConfig->database, 'MySQL', $dbConfig->port);
     $this->database->execute('CREATE TABLE IF NOT EXISTS `ThreadingProcesses` (' . '`parentId` INT(10) UNSIGNED NOT NULL,' . '`lastLive` DATETIME NOT NULL,' . 'PRIMARY KEY (`parentId`)' . ')' . 'COLLATE=\'utf8_general_ci\'');
     $this->database->execute('CREATE TABLE IF NOT EXISTS `ThreadingData` (' . '`parentId` INT(10) UNSIGNED NOT NULL,' . '`name` VARCHAR(255) NOT NULL,' . '`value` TEXT NOT NULL,' . 'PRIMARY KEY (`parentId`, `name`)' . ')' . 'COLLATE=\'utf8_general_ci\'');
     $this->database->execute('CREATE TABLE IF NOT EXISTS `ThreadingCommands` (' . '`parentId` INT(10) UNSIGNED NOT NULL,' . '`commandId` INT(10) UNSIGNED NOT NULL,' . '`threadId` INT(10) UNSIGNED NOT NULL,' . '`task` TEXT NOT NULL,' . '`result` TEXT NULL DEFAULT NULL,' . '`timeTaken` FLOAT UNSIGNED NULL DEFAULT NULL,' . 'PRIMARY KEY (`parentId`, `commandId`),' . 'INDEX `threadId` (`threadId`)' . ')' . 'COLLATE=\'utf8_general_ci\'');
     $deadPids = $this->database->execute('SELECT parentId FROM ThreadingProcesses WHERE parentId=%d OR DATE_ADD(lastLive, INTERVAL 2 MINUTE) < NOW()', getmypid())->fetchArrayOfSingleValues();
     if ($deadPids) {
         $deadPids = implode(',', array_map('intval', $deadPids));
         $this->database->execute('DELETE FROM ThreadingProcesses WHERE parentId IN (%s)', $deadPids);
         $this->database->execute('DELETE FROM ThreadingData WHERE parentId IN (%s)', $deadPids);
         $this->database->execute('DELETE FROM ThreadingCommands WHERE parentId IN (%s)', $deadPids);
     }
     $this->database->execute('INSERT INTO ThreadingProcesses(parentId, lastLive) VALUES(%s, NOW())', getmypid());
 }
Exemplo n.º 3
0
 private function initDatabase()
 {
     $options = getopt(null, array('dbHost::', 'dbPort::', 'dbUsername::', 'dbPassword::', 'dbDatabase::'));
     $dbConfig = \ManiaLive\Database\Config::getInstance();
     foreach ($options as $key => $value) {
         $dbConfig->{lcfirst(substr($key, 2))} = $value;
     }
     $this->database = Connection::getConnection($dbConfig->host, $dbConfig->username, $dbConfig->password, $dbConfig->database, 'MySQL', $dbConfig->port);
     // load configs from DB
     $configs = array('config' => \ManiaLive\Config\Config::getInstance(), 'wsapi' => \ManiaLive\Features\WebServices\Config::getInstance(), 'manialive' => \ManiaLive\Application\Config::getInstance(), 'server' => \ManiaLive\DedicatedApi\Config::getInstance(), 'threading' => Config::getInstance());
     foreach ($configs as $dbName => $instance) {
         $data = $this->getData($dbName, array());
         foreach ((array) $data as $key => $value) {
             $instance->{$key} = $value;
         }
     }
 }
Exemplo n.º 4
0
 protected final function enableDatabase()
 {
     $config = \ManiaLive\Database\Config::getInstance();
     $this->db = DbConnection::getConnection($config->host, $config->username, $config->password, $config->database, $config->type, $config->port);
 }