Updated install

Added Form manager
Added session messages display

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2011-11-18 08:05:42 +01:00
commit 5acde87794
220 changed files with 1962 additions and 1134 deletions

View file

@ -315,12 +315,12 @@ class Wootook
return $config;
}
public static function setConfig($path = null, $value)
public static function setConfig($path, $value)
{
self::_loadConfig();
if ($path === null || !is_string($path)) {
return self::$_config;
return self::$_config = $value;
}
$config = &self::$_config;
foreach (explode('/', $path) as $chunk) {
@ -334,6 +334,12 @@ class Wootook
return true;
}
public static function writeConfig(Array $config)
{
file_put_contents(ROOT_PATH . DIRECTORY_SEPARATOR . 'config.php',
'<' . '?p' . 'hp ' . var_export($config, true) . ';');
}
public static function getBaseUrl()
{
return self::getConfig('global/web/base_url');

View file

@ -17,7 +17,8 @@ class Wootook_Core_Block_Html_Navigation
),
'label' => $label,
'title' => $title,
'classes' => $classes
'classes' => $classes,
'attributes' => $attributes
));
$parent->setPartial($baseName, $child);

View file

@ -1,5 +1,39 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
interface Wootook_Core_EntityInterface
{
public function getId();

View file

@ -14,6 +14,8 @@ class Wootook_Core_ErrorProfiler
private static $_listen = true;
private $_mute = false;
public static function getSingleton()
{
if (self::$_singleton === null) {
@ -134,6 +136,10 @@ ERROR_EOF;
public function shutdownManager()
{
if ($this->_mute === true) {
return;
}
$index = 0;
echo '<div style="background:#FFF;border:1px solid #F00;color:#000;padding:10px;margin:20px;text-align:left;">';
echo '<h1>Debug profiler</h1>';
@ -173,6 +179,8 @@ ERROR_EOF;
set_error_handler(array(self::getSingleton(), 'errorManager'));
set_exception_handler(array(self::getSingleton(), 'exceptionManager'));
self::getSingleton()->_mute = false;
if (self::$_isTraceRegistered === false && defined('DEBUG')) {
self::$_isTraceRegistered = true;
register_shutdown_function(array(self::getSingleton(), 'shutdownManager'));
@ -184,8 +192,10 @@ ERROR_EOF;
restore_error_handler();
restore_exception_handler();
if ((self::$_isTraceRegistered && defined('DEBUG')) || $force) {
self::$_isTraceRegistered = false;
self::getSingleton()->_mute = true;
if ((self::$_isTraceRegistered === false && defined('DEBUG')) || $force) {
self::$_isTraceRegistered = true;
register_shutdown_function(array(self::getSingleton(), 'shutdownManager'));
}
}

View file

@ -59,8 +59,11 @@ class Wootook_Core_Form
public function validate()
{
foreach ($this->_fields as $field) {
$field->validate();
if (!$field->validate()) {
return false;
}
}
return true;
}
/**

View file

@ -424,7 +424,7 @@ class Wootook_Core_Layout
*
* @return Wootook_Core_Block_Messages
*/
public function getMessagesblock()
public function getMessagesBlock()
{
return $this->_messageBlock;
}

View file

@ -128,19 +128,26 @@ class Wootook_Core_Model_Session
return $this->addMessage(vsprintf($message, $args), self::DEBUG);
}
public function initFormKey()
{
$key = $this->getData('form_key');
$this->setData('form_key', uniqid());
return $key;
}
public function getFormKey($reset = true)
{
if (!$this->getData('form_key')) {
$this->setData('form_key', uniqid());
$this->initFormKey();
return $this->getData('form_key');
}
$key = $this->getData('form_key');
if ($reset !== true) {
$this->setData('form_key', uniqid());
if ($reset === true) {
$this->initFormKey();
}
return $key;
return $this->getData('form_key');
}
public function setFormData(Array $data = array())

View file

@ -0,0 +1,106 @@
<?php
class Wootook_Core_Setup_Updater
{
protected $_setupConnection = null;
/**
*
* Enter description here ...
* @param unknown_type $connection
* @return Wootook_Core_Setup_Updater
*/
public function setSetupConnection($connection)
{
if (is_string($connection)) {
$this->_setupConnection = Wootook_Database::getConnection($connection);
} else {
$this->_setupConnection = $connection;
}
return $this;
}
/**
*
* Enter description here ...
* @return Wootook_Database
*/
public function getSetupConnection()
{
if ($this->_setupConnection === null) {
return Wootook_Database::getSingleton();
}
return $this->_setupConnection;
}
public function getTable($tableName)
{
$this->getSetupConnection()->getTable($tableName);
}
public function grant($tableName, $connectionName, $perms = null)
{
$hostname = Wootook::getConfig("global/database/{$connectionName}/params/hostname");
$username = Wootook::getConfig("global/database/{$connectionName}/params/username");
$database = Wootook::getConfig("global/database/{$connectionName}/params/database");
$password = Wootook::getConfig("global/database/{$connectionName}/params/password");
if ($perms === null) {
$perms = 'ALL PRIVILEGES';
} else if (is_array($perms)) {
$perms = implode(' ', $perms);
}
$sql =<<<SQL_EOF
GRANT {$perms}
ON {$database}.{$this->getTable($tableName)}
TO '{$username}@{$hostname}' IDENTIFIED BY '$password'
SQL_EOF;
$this->getSetupConnection()->query($sql);
return $this;
}
public function revoke($tableName, $connectionName, $perms = null)
{
$hostname = Wootook::getConfig("global/database/{$connectionName}/params/hostname");
$username = Wootook::getConfig("global/database/{$connectionName}/params/username");
$database = Wootook::getConfig("global/database/{$connectionName}/params/database");
$password = Wootook::getConfig("global/database/{$connectionName}/params/password");
if ($perms === null) {
$perms = 'ALL PRIVILEGES';
} else if (is_array($perms)) {
$perms = implode(' ', $perms);
}
$sql =<<<SQL_EOF
REVOKE {$perms}
ON {$database}.{$this->getTable($tableName)}
FROM '{$username}@{$hostname}'
SQL_EOF;
$this->getSetupConnection()->query($sql);
return $this;
}
public function run($script)
{
include $script;
}
public function getConfig($path = null)
{
return Wootook::getConfig($path);
}
public function getGameConfig($path)
{
$config = Wootook_Core_Model_Config::getSingleton();
return $config->getData($path);
}
}

View file

@ -56,11 +56,16 @@ class Wootook_Core_View
}
}
protected function escape($unescaped)
public function escape($unescaped)
{
return htmlspecialchars($unescaped, ENT_QUOTES, 'UTF-8');
}
public function escapeJs($unescaped)
{
return addslashes($unescaped);
}
public function __($message, $_ = null)
{
$args = func_get_args();

View file

@ -2,45 +2,33 @@
/**
* This file is part of Wootook
*
* @license Modified BSD
* @see https://github.com/gplanchat/one.platform
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2009-2010, Grégory PLANCHAT <g.planchat at gmail.com>
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Grégory PLANCHAT nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing One.Platform.
* documentation for further information about customizing Wootook.
*
*/
$this->setSetupConnection('legacies_setup');
$this->setSetupConnection('core_setup');
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/aks')} (
@ -59,12 +47,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/aks', 'legacies_read', array('SELECT'))
->grant('legacies/aks', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/aks', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/alliance')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -88,12 +70,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/alliance', 'legacies_read', array('SELECT'))
->grant('legacies/alliance', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/alliance', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/annonce')} (
`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -112,12 +88,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/annonce', 'legacies_read', array('SELECT'))
->grant('legacies/annonce', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/annonce', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/banned')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -134,12 +104,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/banned', 'legacies_read', array('SELECT'))
->grant('legacies/banned', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/banned', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/buddy')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -153,12 +117,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/buddy', 'legacies_read', array('SELECT'))
->grant('legacies/buddy', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/buddy', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/chat')} (
`messageid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -171,12 +129,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/chat', 'legacies_read', array('SELECT'))
->grant('legacies/chat', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/chat', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/config')} (
`config_name` VARCHAR(64) NOT NULL,
@ -187,12 +139,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/config', 'legacies_read', array('SELECT'))
->grant('legacies/config', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/config', 'legacies_setup')
;
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('legacies/config')} (`config_name`, `config_value`) VALUES
('game_speed', '2500'),
@ -206,7 +152,7 @@ INSERT INTO {$this->getTableName('legacies/config')} (`config_name`, `config_val
('game_disable', '1'),
('close_reason', 'Le jeu est clos pour le moment!'),
('metal_basic_income', '20'),
('crystal_basic_income', '10'),
('cristal_basic_income', '10'),
('deuterium_basic_income', '0'),
('energy_basic_income', '0'),
('BuildLabWhileRun', '0'),
@ -259,12 +205,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/declared', 'legacies_read', array('SELECT'))
->grant('legacies/declared', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/declared', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/errors')} (
`error_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -278,12 +218,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/errors', 'legacies_read', array('SELECT'))
->grant('legacies/errors', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/errors', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/fleets')} (
`fleet_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -316,12 +250,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/fleets', 'legacies_read', array('SELECT'))
->grant('legacies/fleets', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/fleets', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/galaxy')} (
`galaxy` TINYINT UNSIGNED NOT NULL,
@ -341,12 +269,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/galaxy', 'legacies_read', array('SELECT'))
->grant('legacies/galaxy', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/galaxy', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/iraks')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -367,12 +289,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/iraks', 'legacies_read', array('SELECT'))
->grant('legacies/iraks', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/iraks', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/lunas')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -393,12 +309,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/lunas', 'legacies_read', array('SELECT'))
->grant('legacies/lunas', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/lunas', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/messages')} (
`message_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -415,12 +325,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/messages', 'legacies_read', array('SELECT'))
->grant('legacies/messages', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/messages', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/multi')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -433,12 +337,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/multi', 'legacies_read', array('SELECT'))
->grant('legacies/multi', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/multi', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/notes')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -453,12 +351,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/notes', 'legacies_read', array('SELECT'))
->grant('legacies/notes', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/notes', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/planets')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -489,16 +381,16 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/planets')} (
`metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`metal_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
`metal_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crystal_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crystal_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`cristal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`cristal_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
`cristal_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`deuterium` DECIMAL(65,0) NOT NULL DEFAULT 0,
`deuterium_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
`deuterium_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`energy_used` DECIMAL(65,0) NOT NULL DEFAULT 0,
`energy_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`metal_mine` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`crystal_mine` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`cristal_mine` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`deuterium_sintetizer` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`solar_plant` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`fusion_plant` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
@ -506,7 +398,7 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/planets')} (
`nano_factory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`hangar` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`metal_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`crystal_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`cristal_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`deuterium_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`laboratory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`terraformer` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
@ -540,7 +432,7 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/planets')} (
`interceptor_misil` SMALLINT NOT NULL DEFAULT 0,
`interplanetary_misil` SMALLINT NOT NULL DEFAULT 0,
`metal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
`crystal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
`cristal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
`deuterium_sintetizer_porcent` TINYINT NOT NULL DEFAULT 10,
`solar_plant_porcent` TINYINT NOT NULL DEFAULT 10,
`fusion_plant_porcent` TINYINT NOT NULL DEFAULT 10,
@ -552,12 +444,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/planets', 'legacies_read', array('SELECT'))
->grant('legacies/planets', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/planets', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/rw')} (
`id_owner1` BIGINT UNSIGNED NOT NULL,
@ -574,12 +460,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/rw', 'legacies_read', array('SELECT'))
->grant('legacies/rw', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/rw', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/statpoints')} (
`id_owner` BIGINT UNSIGNED NOT NULL,
@ -617,12 +497,6 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/statpoints', 'legacies_read', array('SELECT'))
->grant('legacies/statpoints', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/statpoints', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/users')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -736,57 +610,3 @@ SQL_EOF;
$this->query($sql);
$this
->grant('legacies/users', 'legacies_read', array('SELECT'))
->grant('legacies/users', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/users', 'legacies_setup')
;
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('legacies/alliance')} (
`id`, `ally_name`, `ally_tag`, `ally_owner`, `ally_register_time`, `ally_description`,
`ally_web`, `ally_text`, `ally_image`, `ally_request`, `ally_request_waiting`,
`ally_request_notallow`, `ally_owner_range`, `ally_ranks`, `ally_members`
)
VALUES
('1', 'Admin', 'Admin', 1, NOW(), 'Administrator alliance', 'http://www.xnova-ng.org/',
'', '', '', '', '', '', '', '')
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('legacies/users')} (
`id`, `username`, `password`, `email`, `email_2`, `lang`, `authlevel`, `sex`,
`avatar`, `sign`, `id_planet`, `galaxy`, `system`, `planet`, `current_planet`,
`user_lastip`, `ip_at_reg`, `user_agent`, `current_page`, `register_time`,
`onlinetime`, `dpath`, `design`, `noipcheck`, `planet_sort`, `planet_sort_order`,
`spio_anz`, `settings_tooltiptime`, `settings_fleetactions`, `settings_allylogo`,
`settings_esp`, `settings_wri`, `settings_bud`, `settings_mis`, `settings_rep`,
`urlaubs_modus`, `urlaubs_until`, `db_deaktjava`, `new_message`, `fleet_shortcut`,
`b_tech_planet`, `spy_tech`, `computer_tech`, `military_tech`, `defence_tech`,
`shield_tech`, `energy_tech`, `hyperspace_tech`, `combustion_tech`,
`impulse_motor_tech`, `hyperspace_motor_tech`, `laser_tech`, `ionic_tech`,
`buster_tech`, `intergalactic_tech`, `expedition_tech`, `graviton_tech`,
`ally_id`, `ally_name`, `ally_request`, `ally_request_text`, `ally_register_time`,
`ally_rank_id`, `current_luna`, `kolorminus`, `kolorplus`, `kolorpoziom`,
`rpg_geologue`, `rpg_amiral`, `rpg_ingenieur`, `rpg_technocrate`, `rpg_espion`,
`rpg_constructeur`, `rpg_scientifique`, `rpg_commandant`, `rpg_points`, `rpg_stockeur`,
`rpg_defenseur`, `rpg_destructeur`, `rpg_general`, `rpg_bunker`, `rpg_raideur`,
`rpg_empereur`, `lvl_minier`, `lvl_raid`, `xpraid`, `xpminier`, `raids`,
`p_infligees`, `mnl_alliance`, `mnl_joueur`, `mnl_attaque`, `mnl_spy`,
`mnl_exploit`, `mnl_transport`, `mnl_expedition`, `mnl_general`, `mnl_buildlist`,
`bana`, `multi_validated`, `banaday`, `raids1`, `raidswin`, `raidsloose`
)
VALUES
('1', 'Admin', '', '', '', 'fr', '3', NULL, '', '', '1', '1', '1', '1',
'1', '127.0.0.1', '', '', '', '1254743313', '1269391977', '', '1', '1', '0',
'0', '1', '5', '0', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '', '0',
'16', '20', '11', '11', '11', '12', '10', '14', '10', '9', '0', '0', '0', '0',
'0', '1', 1, 'Admin', '0', '', NOW(), '0', '0', 'red', '#00FF00', 'yellow', '20',
'20', '10', '10', '0', '3', '3', '0', '27', '2', '2', '0', '0', '0', '0', '0',
'98', '1', '0', '1133583738', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0')
SQL_EOF;
$this->query($sql);

View file

@ -3,9 +3,12 @@
class Wootook_Database
extends PDO
{
protected static $_singleton = null;
const DEFAULT_CONNECTION_NAME = 'default';
protected static $_prefix = null;
protected static $_connections = array();
protected static $_connectionAliases = array();
protected $_tablePrefix = null;
public static $options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
@ -13,39 +16,80 @@ class Wootook_Database
public static function getSingleton()
{
if (self::$_singleton === null) {
$config = include ROOT_PATH . 'config.php';
$hostname = $config['global']['database']['options']['hostname'];
$username = $config['global']['database']['options']['username'];
$password = $config['global']['database']['options']['password'];
$database = $config['global']['database']['options']['database'];
$port = 3306;
return self::getConnection(self::DEFAULT_CONNECTION_NAME);
}
if (isset($config['global']['database']['options']['port'])) {
$port = $config['global']['database']['options']['port'];
public static function getConnection($connectionName)
{
if (empty($connectionName) || $connectionName === null) {
return null;
}
if (!isset(self::$_connections[$connectionName])) {
if (isset(self::$_connectionAliases[$connectionName])) {
return self::$_connectionAliases[$connectionName];
}
$event = Wootook::dispatchEvent('database.prepare-options', array(
'options' => self::$options
));
if ($alias = Wootook::getConfig("global/database/{$connectionName}/use")) {
self::$_connectionAliases[$connectionName] = self::getConnection($alias);
}
self::$options = $event->getData('options');
self::$_singleton = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, self::$options);
Wootook::dispatchEvent('database.init', array(
'handler' => self::$_singleton
));
self::$_connections[$connectionName] = self::_initConnection($connectionName);
}
return self::$_singleton;
return self::$_connections[$connectionName];
}
private static function _initConnection($connectionName)
{
$hostname = Wootook::getConfig("global/database/{$connectionName}/params/hostname");
$username = Wootook::getConfig("global/database/{$connectionName}/params/username");
$password = Wootook::getConfig("global/database/{$connectionName}/params/password");
$database = Wootook::getConfig("global/database/{$connectionName}/params/database");
if (empty($hostname) || empty($username) || empty($database)) {
return null;
}
if (!($port = Wootook::getConfig("global/database/{$connectionName}/params/port")) || !is_numeric($port)) {
$port = 3306;
}
$event = Wootook::dispatchEvent('database.prepare-options', array(
'name' => $connectionName,
'options' => array_merge(self::$options, Wootook::getConfig("global/database/{$connectionName}/options"))
));
$options = $event->getData('options');
$connection = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, $options);
if (($prefix = Wootook::getConfig("global/database/{$connectionName}/table_prefix")) !== null) {
$connection->setTablePrefix($prefix);
}
Wootook::dispatchEvent('database.init', array(
'name' => $connectionName,
'handler' => $connection
));
return $connection;
}
public function setTablePrefix($prefix)
{
$this->_tablePrefix = $prefix;
return $this;
}
public function getTablePrefix()
{
return $this->_tablePrefix;
}
public function getTable($name)
{
if (self::$_prefix === null) {
$config = include ROOT_PATH . 'config.php';
self::$_prefix = $config['global']['database']['table_prefix'];
}
return self::$_prefix . $name;
return $this->getTablePrefix() . $name;
}
}

View file

@ -429,7 +429,7 @@ class Wootook_Empire_Model_Planet
;
$options = array(
'galaxy' => $this->getSystem(),
'galaxy' => $this->getGalaxy(),
'system' => $this->getSystem(),
'position' => $this->getPosition(),
'planet_type' => $this->getType()

View file

@ -1,6 +1,6 @@
<?php
class Test_LegaciesTest
class Test_WootookTest
extends PHPUnit_Framework_TestCase
{
protected function tearDown()