示例#1
0
 protected function setUp()
 {
     self::$config['testdb']['dbname'] = null;
     $db = DriverManager::getConnection(self::$config['testdb']);
     $sm = $db->getSchemaManager();
     $sm->dropAndCreateDatabase(self::$database);
     $db->close();
     self::$config['testdb']['dbname'] = self::$database;
     $this->db = DriverManager::getConnection(self::$config['testdb']);
     $driver = str_replace('pdo_', '', self::$config['testdb']['driver']);
     $sqlFile = file_get_contents(Cerberus::getPath() . '/cerberus.' . $driver . '.sql');
     $sqlArray = explode(';', $sqlFile);
     foreach ($sqlArray as $sqlCommand) {
         $sqlCommand = trim($sqlCommand);
         if (empty($sqlCommand) === false) {
             $this->db->query($sqlCommand . ';');
         }
     }
     self::$config['db'] = self::$config['testdb'];
     $this->irc = new Irc(self::$config);
     $this->irc->setLanguage('en');
     $this->irc->getConsole()->disableOutput();
     $this->irc->init();
     $this->invokeMethod($this->irc, 'loadPlugin', 'test');
 }
示例#2
0
文件: Hades.php 项目: tronsha/hades
 /**
  * @param string $host
  */
 public function setHost($host)
 {
     if ($_GET['pw'] === md5($this->config['frontend']['password'])) {
         $path = Cerberus::getPath();
         $content = file_get_contents($path . '/config.ini');
         $content = preg_replace('/host\\ \\=\\ [0-9\\.]+/', 'host = ' . $host, $content);
         file_put_contents($path . '/config.ini', $content);
     }
 }
示例#3
0
    $bots = $db->getActiveBotList();
    $botCount = 0;
    if ($bots) {
        exec('ps -e | grep php', $output);
        $pidList = [];
        foreach ($output as $line) {
            $data = explode(' ', trim(preg_replace('/[ ]+/', ' ', $line)));
            if ($data[3] === 'php') {
                $pidList[] = $data[0];
            }
        }
        foreach ($bots as $bot) {
            if (in_array($bot['pid'], $pidList, true) === true) {
                $botCount++;
                Cerberus::sysinfo('Bot ' . $bot['id'] . ' is running. PID: ' . $bot['pid']);
            } else {
                $db->cleanupBot($bot['id']);
                $db->shutdownBot($bot['id']);
                Cerberus::sysinfo('Bot ' . $bot['id'] . ' is not running.');
            }
        }
    }
    if ($botCount === 0) {
        Cerberus::sysinfo('start a new bot.');
        $logDirectory = rtrim(trim($config['log']['directory']), '/');
        if (is_dir($logDirectory) === false) {
            mkdir($logDirectory);
        }
        exec(Cerberus::getPath() . '/bin/bot.php -noconsole > ' . $logDirectory . '/log.txt 2>&1 &');
    }
}
示例#4
0
 /**
  * @param string $file
  */
 public function loadTranslationFile($file)
 {
     $translationsFileStatus = Cerberus::getPath() . '/resources/translations/' . $this->language . '/' . $file . '.php';
     if (file_exists($translationsFileStatus) === true) {
         $this->addResource('file', $translationsFileStatus, $this->language);
     }
 }
示例#5
0
 /**
  * @param Event $event
  */
 protected static function runPhpUnit(Event $event)
 {
     $io = $event->getIO();
     if (file_exists(Cerberus::getPath() . '/vendor/bin/phpunit') === false) {
         $io->write('<error>Can\'t find "PHPUnit".</error>');
     } elseif (Cerberus::isExecAvailable() === false) {
         $io->write('<error>Can\'t run "PHPUnit", because "exec" is disabled.</error>');
     } else {
         $output = [];
         exec(Cerberus::getPath() . '/vendor/bin/phpunit', $output);
         foreach ($output as $line) {
             $io->write('<comment>' . $line . '</comment>');
         }
     }
 }