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); } }
/** * 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); }
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(); } }
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(); }
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; }
/** * Return name of database for database connection. * @return String */ public static function getDb() { return LudoDBRegistry::get('DB_NAME'); }
private function getTempPath($filename) { $extension = $this->getExtension($filename); return LudoDBRegistry::get(self::FILE_UPLOAD_KEY) . "/uploaded" . date("YmdHis") . '-' . rand(10000, 99999) . "." . $extension; }
/** * Set instance name for Oracle connection * @param $instance */ public function setInstanceName($instance) { LudoDBRegistry::set('DB_INSTANCE', $instance); }
<?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);