예제 #1
0
 private function validateDBConnection()
 {
     try {
         ob_start();
         $dbName = LudoDBRegistry::get('DB_NAME');
         LudoDB::setDb("information_schema");
         LudoDB::getInstance()->connect();
         LudoDB::setDb($dbName);
         LudoDB::createDatabase($dbName);
         LudoDB::getInstance()->connect();
         ob_end_clean();
     } catch (Exception $e) {
         throw new LudoDBException("Cannot connect to database, error message: " . $e->getMessage(), 400);
     }
 }
예제 #2
0
 /**
  * Start profiling.
  * @param array $data
  * @return array
  * @throws LudoDBException
  */
 public function profile($data = array())
 {
     $inDevelop = LudoDBRegistry::get('DEVELOP_MODE');
     if (!isset($inDevelop) || !$inDevelop) {
         throw new LudoDBException("Profiling can only be executed in develop mode. Use LudoDBRegistry::set('DEVELOP_MODE', true) to activate develop mode");
     }
     $request = implode("/", $this->arguments);
     $name = preg_replace("/[^0-9a-z]/si", "", $request);
     $this->start($name);
     $handler = new LudoDBRequestHandler();
     $result = json_decode($handler->handle(array('request' => $request, 'data' => $data)), true);
     if (!$result['success']) {
         throw new LudoDBException($result['message']);
     }
     $url = $this->end();
     return array("result" => $url, "request" => $request, "data" => $data);
 }
예제 #3
0
 public function setUp()
 {
     parent::setUp();
     LudoDBRegistry::set('FILE_UPLOAD_PATH', '/tmp/');
     $mv = new MetadataValue();
     $mv->drop()->yesImSure();
     $m = new Move();
     $m->drop()->yesImSure();
     $g = new Game();
     $g->drop()->yesImSure();
     $g->createTable();
     $m->createTable();
     $mv->createTable();
     $db = new Database(1);
     if (!$db->getId()) {
         $db->setTitle('My database');
         $db->commit();
     }
 }
예제 #4
0
 public function setUp()
 {
     if (!self::$connected) {
         date_default_timezone_set('Europe/Berlin');
         LudoDB::setHost('localhost');
         LudoDB::setUser('root');
         LudoDB::setPassword('administrator');
         LudoDB::setDb('PHPUnit');
         self::$connected = true;
         LudoDBRegistry::set('FILE_UPLOAD_PATH', '/tmp/');
     }
     if (!self::$logCleared) {
         self::$logCleared = true;
         $this->clearLog();
     }
     $classes = array('Game', 'Move', 'Database', 'Folder', 'Metadata', 'MetadataValue', 'Session', 'Seek', 'Chat', 'ChatMessage', 'ChatMessages', 'Fen', 'Player', 'TimeControl', 'ChessFileUpload', 'Elo', 'PasswordLookup');
     $util = new LudoDBUtility();
     $util->dropAndCreate($classes);
     $this->createAdminUserAndSignIn();
 }
예제 #5
0
 private function sanitize($filePath)
 {
     $extension = $this->getExtension($filePath);
     if ($extension != 'pgn') {
         return null;
     }
     if (class_exists("LudoDBRegistry")) {
         $tempPath = LudoDBRegistry::get('FILE_UPLOAD_PATH');
     } else {
         $tempPath = null;
     }
     if (isset($tempPath) && substr($filePath, 0, strlen($tempPath)) == $tempPath) {
     } else {
         if (substr($filePath, 0, 1) === "/") {
             return null;
         }
     }
     $filePath = preg_replace("/[^0-9\\.a-z_\\-\\/]/si", "", $filePath);
     if (!file_exists($filePath)) {
         return null;
     }
     return $filePath;
 }
예제 #6
0
 /**
  * Return name of database for database connection.
  * @return String
  */
 public static function getDb()
 {
     return LudoDBRegistry::get('DB_NAME');
 }
예제 #7
0
 private function getTempPath($filename)
 {
     $extension = $this->getExtension($filename);
     return LudoDBRegistry::get(self::FILE_UPLOAD_KEY) . "/uploaded" . date("YmdHis") . '-' . rand(10000, 99999) . "." . $extension;
 }
예제 #8
0
 /**
  * Set instance name for Oracle connection
  * @param $instance
  */
 public function setInstanceName($instance)
 {
     LudoDBRegistry::set('DB_INSTANCE', $instance);
 }
예제 #9
0
<?php

require_once dirname(__FILE__) . "/autoload.php";
require_once "php/jsonwrapper/jsonwrapper.php";
date_default_timezone_set("Europe/Berlin");
ini_set('display_errors', 'on');
if (file_exists("connection.php")) {
    require "connection.php";
}
LudoDBRegistry::set('FILE_UPLOAD_PATH', '/tmp/');
LudoDBRegistry::set('DEVELOP_MODE', true);
LudoDB::enableLogging();
// For static(No db) installations
ChessRegistry::setPgnFolder("pgn");
ChessRegistry::setCacheFolder("cache");
// Path to cache
$request = isset($_GET['request']) ? $_GET['request'] : $_POST['request'];
$requestData = isset($_POST['data']) ? $_POST['data'] : null;
$handler = new LudoDBRequestHandler();
echo $handler->handle($request, $requestData);