Finished install script

Updated configuration data loading
Added Website and Game models

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2011-12-27 19:37:28 +01:00
commit dfa3dfb086
34 changed files with 362 additions and 510 deletions

View file

@ -69,6 +69,8 @@ SQL_EOF;
protected function _save()
{
$database = $this->getWriteConnection();
if ($this->getId() !== null) {
$fields = array();
$values = array();
@ -76,7 +78,7 @@ SQL_EOF;
if ($field == self::getIdFieldName()) {
continue;
}
$fields[] = "{$field}=:{$field}";
$fields[] = "{$database->quoteIdentifier($field)}=:{$field}";
$values[$field] = $value;
}
@ -84,7 +86,6 @@ SQL_EOF;
$idFieldName = self::getIdFieldName();
$values[$idFieldName] = $this->getId();
$database = $this->getWriteConnection();
if ($database === null) {
throw new Wootook_Core_Exception_DataAccessException('Could not load data: no write connection configured.');
}
@ -99,8 +100,8 @@ SQL_EOF;
$statement->execute($values);
} else {
$datas = $this->getAllDatas();
$fieldsImploded = implode(', ', array_keys($datas));
$fields = array();
$tokens = array();
$values = array();
foreach ($datas as $field => $value) {
@ -108,24 +109,27 @@ SQL_EOF;
continue;
}
$tokens[] = ":{$field}";
$values[$field] = $value;
$fields[] = $database->quoteIdentifier($field);
$values[$field] = strval($value);
}
$tokensImploded = implode(', ', $tokens);
$fieldsImploded = implode(', ', $fields);
$database = $this->getWriteConnection();
if ($database === null) {
throw new Wootook_Core_Exception_DataAccessException('Could not load data: no write connection configured.');
}
$table = $database->getTable($this->getTableName());
$sql =<<<SQL_EOF
INSERT INTO {$database->getTable($this->getTableName())} ($fieldsImploded)
VALUES ({$tokensImploded})
INSERT INTO {$database->quoteIdentifier($table)} ({$database->quoteIdentifier($this->getIdFieldName())}, $fieldsImploded)
VALUES (NULL, {$tokensImploded})
SQL_EOF;
$statement = $database->prepare($sql);
$statement->execute($values);
$this->setId($database->lastInsertId());
$id = $database->lastInsertId($table);
$this->setId($id);
}
return $this;

View file

@ -90,6 +90,11 @@ class Wootook_Core_ErrorProfiler
return true;
}
public function addException($exception)
{
$this->_exceptions[] = $exception;
}
public function exceptionManager($exception)
{
if (!$this->_listen) {

View file

@ -0,0 +1,7 @@
<?php
class Wootook_Core_Exception_Deprecated
extends Wootook_Core_Exception_RuntimeException
{
}

View file

@ -0,0 +1,7 @@
<?php
class Wootook_Core_Exception_GameError
extends Wootook_Core_Exception_RuntimeException
{
}

View file

@ -0,0 +1,7 @@
<?php
class Wootook_Core_Exception_WebsiteError
extends Wootook_Core_Exception_RuntimeException
{
}

View file

@ -21,6 +21,10 @@ class Wootook_Core_Model_Session
protected static $_levels = null;
const COOKIE_LIFETIME_CONFIG_KEY = 'web/session/time';
const COOKIE_DOMAIN_CONFIG_KEY = 'web/session/domain';
const COOKIE_PATH_CONFIG_KEY = 'web/session/path';
public static function factory($namespace)
{
$namespace = (string) $namespace;
@ -43,6 +47,7 @@ class Wootook_Core_Model_Session
public function __construct($namespace)
{
if (session_id() == '') {
session_set_cookie_params($this->getCookieLifetime(), $this->getCookiePath(), $this->getCookieDomain(), false, true);
session_start();
}
@ -56,6 +61,26 @@ class Wootook_Core_Model_Session
}
}
public function getCookieLifetime()
{
$lifetime = Wootook::getWebsiteConfig(self::COOKIE_LIFETIME_CONFIG_KEY);
if ($lifetime <= 0) {
return 900;
}
return $lifetime;
}
public function getCookieDomain()
{
return Wootook::getWebsiteConfig(self::COOKIE_DOMAIN_CONFIG_KEY);
}
public function getCookiePath()
{
return Wootook::getWebsiteConfig(self::COOKIE_PATH_CONFIG_KEY);
}
public function getMessages($clear = true)
{
$messages = $this->_data['messages'];

View file

@ -166,6 +166,12 @@ INSERT IGNORE INTO {$this->getTableName('core_config')} (`website_id`, `game_id`
(0, 0, 'web/cookie/domain', ''),
(0, 0, 'web/cookie/path', ''),
(1, 1, 'web/cookie/name', '__wtk_1_1'),
(0, 0, 'web/session/time', '900'),
(0, 0, 'web/session/domain', '.wootook.org'),
(0, 0, 'web/session/path', '/'),
(0, 0, 'engine/options/bbcode', '1'),
(0, 0, 'engine/options/ga', '1'),
(0, 0, 'engine/options/announces', '0'),
@ -184,12 +190,18 @@ INSERT IGNORE INTO {$this->getTableName('core_config')} (`website_id`, `game_id`
(0, 0, 'engine/bot/name', 'Woot'),
(0, 0, 'engine/bot/email', 'contact@wootook.org');
SQL_EOF;
/**
* TODO: change these paths
* (0, 0, 'BuildLabWhileRun', '0')
* (0, 0, 'ExtCopyFrame', '0')
* (0, 0, 'ExtCopyOwner', '')
* (0, 0, 'ExtCopyFunct', '')
*/
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('errors')} (
`error_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`error_sender` VARCHAR(32) NOT NULL,
`error_time` TIMESTAMP NOT NULL,
`error_type` VARCHAR(32) NOT NULL DEFAULT 'unknown',
`error_text` TEXT,
PRIMARY KEY (`error_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);

View file

@ -40,7 +40,7 @@
*
*/
$this->setSetupConnection('legacies_setup');
$this->setSetupConnection('core_setup');
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('core_website')};
@ -65,3 +65,9 @@ DROP TABLE {$this->getTableName('core_config')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('errors')};
SQL_EOF;
$this->query($sql);