diff --git a/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php b/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php index cdcba95..b350548 100644 --- a/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php +++ b/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php @@ -129,211 +129,6 @@ SQL_EOF; $this->query($sql); -$sql = <<getTableName('core_website')} ( - `website_id` TINYINT UNSIGNED NOT NULL, - `code` VARCHAR(64) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `sort_order` TINYINT UNSIGNED NOT NULL, - `default_group_id` TINYINT UNSIGNED NOT NULL, - `is_default` BOOL NOT NULL, - `is_staging` BOOL NOT NULL, - `is_active` BOOL NOT NULL, - PRIMARY KEY (`webste_id`), - UNIQUE (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('core_game_group')} ( - `group_id` TINYINT UNSIGNED NOT NULL, - `website_id` TINYINT UNSIGNED NOT NULL, - `code` VARCHAR(64) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `sort_order` TINYINT UNSIGNED NOT NULL, - `is_default` BOOL NOT NULL, - PRIMARY KEY (`group_id`), - INDEX (`webste_id`), - UNIQUE (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('core_game')} ( - `game_id` SMALLINT UNSIGNED NOT NULL, - `group_id` TINYINT UNSIGNED NOT NULL, - `website_id` TINYINT UNSIGNED NOT NULL, - `code` VARCHAR(64) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `sort_order` TINYINT UNSIGNED NOT NULL, - `is_default` BOOL NOT NULL, - `is_staging` BOOL NOT NULL, - `is_active` BOOL NOT NULL, - PRIMARY KEY (`group_id`), - INDEX (`webste_id`), - UNIQUE (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('core_website')} (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`, `is_staging`, `is_active`) -VALUES -(0, "admin", "Administration", 0, 0, 0, 0, 1), -(1, "default", "Default Website", 1, 1, 1, 0, 1); -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('core_game_group')} (`group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`) -VALUES -(0, 0, "admin", "Administration", 0, 0), -(1, 1, "default", "Default Group", 1, 1); -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('core_game')} (`game_id`, `group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`, `is_staging`, `is_active`) -VALUES -(0, 0, 0, "admin", "Administration", 0, 0, 0, 1), -(1, 1, 1, "default", "Default Game", 1, 1, 0, 1); -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('core_config')} ( - `website_id` TINYINT UNSIGNED NOT NULL, - `game_id` TINYINT UNSIGNED NOT NULL, - `config_path` VARCHAR(64) NOT NULL, - `config_value` VARCHAR(255) NOT NULL, - PRIMARY KEY (`website_id`, `game_id`, `config_path`), - INDEX (`website_id`), - INDEX (`game_id`), - INDEX (`config_path`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('core_config')} (`webste_id`, `game_id`, `config_path`, `config_value`) VALUES - (1, 1, 'resource/base-income/metal', '20'), - (1, 1, 'resource/base-income/cristal', '10'), - (1, 1, 'resource/base-income/deuterium', '0'), - (1, 1, 'resource/base-income/energy', '0'), - - (1, 1, 'resource/initial/fields', '163'), - (1, 1, 'resource/initial/metal', '500'), - (1, 1, 'resource/initial/cristal', '500'), - (1, 1, 'resource/initial/deuterium', '0'), - (1, 1, 'resource/initial/energy', '0'), - - (1, 1, 'game/general/name', 'Wootook'), - (1, 1, 'game/general/boards-url', 'http://wootook.org/board/'), - (1, 1, 'game/general/extra-url-title', 'Wootook!'), - (1, 1, 'game/general/extra-url', 'http://wootook.org/'), - (1, 1, 'game/general/active', '1'), - (1, 1, 'game/general/closing-message', 'Le jeu est clos pour le moment.'), - (1, 1, 'game/general/locale', 'fr_FR'), - - (1, 1, 'game/resource/multiplier', '1000'), - (1, 1, 'game/speed/general', '2500'), - (1, 1, 'game/speed/fleet', '2500'), - - (1, 1, 'game/debris/metal-percent', '30'), - (1, 1, 'game/debris/cristal-percent', '30'), - (1, 1, 'game/debris/deuterium-percent', '0'), - (1, 1, 'game/debris/energy-percent', '0'), - - (1, 1, 'game/debris/fleet', '1'), - (1, 1, 'game/debris/defense', '0'), - - (1, 1, 'game/noob-protection/active', '0'), - (1, 1, 'game/noob-protection/points-cap', '5000'), - (1, 1, 'game/noob-protection/multiplier', '5'), - - (0, 0, 'web/cookie/name', '__wtk'), - (0, 0, 'web/cookie/time', '2592000'), - (0, 0, 'web/cookie/domain', ''), - (0, 0, 'web/cookie/path', ''), - - (0, 0, 'engine/options/bbcode', '1'), - (0, 0, 'engine/options/ga', '1'), - (0, 0, 'engine/options/announces', '0'), - (0, 0, 'engine/options/retailer', '0'), - (0, 0, 'engine/options/notes', '0'), - (0, 0, 'engine/options/chat', '0'), - (0, 0, 'engine/options/banner', '0'), - (0, 0, 'engine/options/vacation-min-time', '172800'), - - (0, 0, 'game/news/active', '0'), - (0, 0, 'game/news/content', 'Bienvenue sur le nouveau serveur de jeu Wootook!'), - - (0, 0, 'engine/ban/duration', '86400'), - - (0, 0, 'engine/bot/active', '0'), - (0, 0, 'engine/bot/name', 'Woot'), - (0, 0, 'engine/bot/email', 'contact@wootook.org'), - --------------------------------------------------------------------------------- - --- (0, 0, 'game_speed', '2500'), --- (0, 0, 'fleet_speed', '2500'), --- (0, 0, 'resource_multiplier', '1000'), - --- (0, 0, 'metal_basic_income', '20'), --- (0, 0, 'cristal_basic_income', '10'), --- (0, 0, 'deuterium_basic_income', '0'), --- (0, 0, 'energy_basic_income', '0'), - --- (0, 0, 'Fleet_Cdr', '30'), --- (0, 0, 'Defs_Cdr', '30'), --- (0, 0, 'initial_fields', '5000'), --- (0, 0, 'COOKIE_NAME', 'wootook'), --- (0, 0, 'game_name', 'Wootook'), --- (0, 0, 'game_disable', '1'), --- (0, 0, 'close_reason', 'Le jeu est clos pour le moment.'), - (0, 0, 'BuildLabWhileRun', '0'), --- (0, 0, 'urlaubs_modus_erz', '1'), --- (0, 0, 'noobprotection', '1'), --- (0, 0, 'noobprotectiontime', '5000'), --- (0, 0, 'noobprotectionmulti', '5'), --- (0, 0, 'forum_url', 'http://wootook.org/board/'), --- (0, 0, 'OverviewNewsFrame', '1'), --- (0, 0, 'OverviewNewsTEXT', 'Bienvenue sur le nouveau serveur Wootook'), --- (0, 0, 'OverviewExternChat', '0'), --- (0, 0, 'OverviewExternChatCmd', ''), --- (0, 0, 'OverviewBanner', '0'), --- (0, 0, 'OverviewClickBanner', ''), - (0, 0, 'ExtCopyFrame', '0'), - (0, 0, 'ExtCopyOwner', ''), - (0, 0, 'ExtCopyFunct', ''), --- (0, 0, 'ForumBannerFrame', '0'), --- (0, 0, 'stat_settings', '1000'), --- (0, 0, 'link_enable', '0'), --- (0, 0, 'link_name', ''), --- (0, 0, 'link_url', ''), --- (0, 0, 'enable_announces', '1'), --- (0, 0, 'enable_marchand', '1'), --- (0, 0, 'enable_notes', '1'), --- (0, 0, 'bot_name', 'Isaac'), --- (0, 0, 'bot_adress', 'contact@wootook.org'), --- (0, 0, 'banner_source_post', '../images/bann.png'), --- (0, 0, 'ban_duration', '30'), --- (0, 0, 'enable_bot', '0'), --- (0, 0, 'enable_bbcode', '1'); -SQL_EOF; - -$this->query($sql); - $sql = <<getTableName('declared')} ( `declarator` TEXT NOT NULL, @@ -755,8 +550,8 @@ $this->query($sql); /* * Galaxy positions generation */ -$galaxyCount = Wootook::getConfig('default/engine/universe/galaxies'); -$systemCount = Wootook::getConfig('default/engine/universe/systems'); +$galaxyCount = Wootook::getConfig('engine/universe/galaxies'); +$systemCount = Wootook::getConfig('engine/universe/systems'); $sql = <<getTableName('galaxy')} diff --git a/application/code/core/Legacies/Empire/install/mysql5/uninstall-1.5.0.php b/application/code/core/Legacies/Empire/install/mysql5/uninstall-1.5.0.php index 74ec834..a4010e5 100644 --- a/application/code/core/Legacies/Empire/install/mysql5/uninstall-1.5.0.php +++ b/application/code/core/Legacies/Empire/install/mysql5/uninstall-1.5.0.php @@ -40,124 +40,118 @@ * */ -$this->setSetupConnection('legacies_setup'); +$this->setSetupConnection('core_setup'); $sql = <<getTableName('legacies/aks')}; +DROP TABLE {$this->getTableName('aks')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/alliance')}; +DROP TABLE {$this->getTableName('alliance')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/annonce')}; +DROP TABLE {$this->getTableName('annonce')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/banned')}; +DROP TABLE {$this->getTableName('banned')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/buddy')}; +DROP TABLE {$this->getTableName('buddy')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/chat')}; +DROP TABLE {$this->getTableName('chat')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/config')}; +DROP TABLE {$this->getTableName('declared')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/declared')}; +DROP TABLE {$this->getTableName('errors')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/errors')}; +DROP TABLE {$this->getTableName('fleets')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/fleets')}; +DROP TABLE {$this->getTableName('galaxy')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/galaxy')}; +DROP TABLE {$this->getTableName('iraks')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/iraks')}; +DROP TABLE {$this->getTableName('lunas')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/lunas')}; +DROP TABLE {$this->getTableName('messages')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/messages')}; +DROP TABLE {$this->getTableName('multi')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/multi')}; +DROP TABLE {$this->getTableName('notes')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/notes')}; +DROP TABLE {$this->getTableName('planets')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/planets')}; +DROP TABLE {$this->getTableName('rw')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/rw')}; +DROP TABLE {$this->getTableName('statpoints')}; SQL_EOF; $this->query($sql); $sql = <<getTableName('legacies/statpoints')}; -SQL_EOF; - -$this->query($sql); - -$sql = <<getTableName('legacies/users')}; +DROP TABLE {$this->getTableName('users')}; SQL_EOF; $this->query($sql); diff --git a/application/code/core/Wootook.php b/application/code/core/Wootook.php index 9c8059e..c0cb5c2 100644 --- a/application/code/core/Wootook.php +++ b/application/code/core/Wootook.php @@ -106,6 +106,18 @@ class Wootook */ protected static $_gameConfigs = array(); + /** + * + * Enter description here ... + * @var array + */ + protected static $_ignoreDatabaseConfig = false; + + protected static $_websitesById = array(); + protected static $_websitesByCode = array(); + protected static $_gamesById = array(); + protected static $_gamesByCode = array(); + /** * Registers an event listener to be called later in the application. * @@ -200,9 +212,11 @@ class Wootook public static function getLocale() { - $availableLocales = self::$_config->getConfig('global/locales'); - - return self::getPreferredLocale($availableLocales); + $availableLocales = self::getWebsiteConfig('locales'); + if ($availableLocales !== null) { + return self::getPreferredLocale($availableLocales->toArray()); + } + return self::getPreferredLocale(); } public static function setDefaultLocale($locale) @@ -310,36 +324,52 @@ class Wootook public static function loadConfig($filename = null) { - if ($filename === null) { - $filename = ROOT_PATH . DIRECTORY_SEPARATOR . 'config.php'; - } - - self::$_config = new Wootook_Core_Config_Adapter_Array($filename); - - self::$_globalConfig = clone self::$_config['default']; - self::$_globalConfig->merge(self::$_config['global']); - - self::_appendDatabaseConfig(self::$_globalConfig); - self::$_websiteConfigs = array(); self::$_gameConfigs = array(); + self::$_config = new Wootook_Core_Config_Adapter_Array(); + try { + if (!is_array($filename)) { + if ($filename === null) { + $filename = ROOT_PATH . 'config.php'; + } + self::$_config->load($filename); + } else { + self::$_config->setData($filename); + } + } catch (Wootook_Core_Exception_DataAccessException $e) { + self::$_globalConfig = new Wootook_Core_Config_Node(array(), self::$_config); + self::$_ignoreDatabaseConfig = true; + return self::$_config; + } + + self::$_globalConfig = clone self::$_config['default']; + if (isset(self::$_config['global'])) { + self::$_globalConfig->merge(self::$_config['global']); + } + + self::_appendDatabaseConfig(self::$_globalConfig); + return self::$_config; } - protected static function _appendDatabaseConfig(Wootook_Core_Config_Node $config, $type = 'global', $id = 0) + protected static function _appendDatabaseConfig(Wootook_Core_Config_Node $config, $type = 'global', $model = null) { + if (self::$_ignoreDatabaseConfig) { + return $config; + } + $collection = new Wootook_Core_Collection('core_config', 'Wootook_Core_Model_Config'); switch ($type) { case 'website': $collection->where('website_id = :website_id'); - $collection->load(array('website_id' => $id)); + $collection->load(array('website_id' => $model->getId())); break; case 'game': $collection->where('game_id = :game_id'); - $collection->load(array('game_id' => $id)); + $collection->load(array('game_id' => $model->getId())); break; default: @@ -356,26 +386,126 @@ class Wootook return $config; } + public static function getWebsite($websiteId) + { + if (is_numeric($websiteId)) { + if (isset(self::$_websitesById[$websiteId])) { + return self::$_websitesById[$websiteId]; + } + $website = new Wootook_Core_Model_Website(); + try { + $website->load($websiteId); + $websiteCode = $website->getData('code'); + + self::$_websitesById[$websiteId] = $website; + self::$_websitesByCode[$websiteCode] = $website; + } catch (Wootook_Core_Exception_DataAccessException $e) { + throw new Wootook_Core_Exception_RuntimeException('Could not load website entity.', null, $e); + } + + return $website; + } else { + if (isset(self::$_websitesByCode[$websiteId])) { + return self::$_websitesByCode[$websiteId]; + } + $website = new Wootook_Core_Model_Website(); + try { + $website->load($websiteId, 'code'); + $websiteId = $website->getId(); + $websiteCode = $website->getData('code'); + + self::$_websitesById[$websiteId] = $website; + self::$_websitesByCode[$websiteCode] = $website; + } catch (Wootook_Core_Exception_DataAccessException $e) { + throw new Wootook_Core_Exception_RuntimeException('Could not load website entity.', null, $e); + } + + return $website; + } + } + + public static function getGame($gameId) + { + if (is_numeric($gameId)) { + if (isset(self::$_gamesById[$gameId])) { + return self::$_gamesById[$gameId]; + } + $game = new Wootook_Core_Model_Game(); + try { + $game->load($gameId); + $gameCode = $game->getData('code'); + + self::$_gamesById[$gameId] = $game; + self::$_gamesByCode[$gameCode] = $game; + } catch (Wootook_Core_Exception_DataAccessException $e) { + throw new Wootook_Core_Exception_RuntimeException('Could not load game entity.', null, $e); + } + + return $game; + } else { + if (isset(self::$_gamesByCode[$gameId])) { + return self::$_gamesByCode[$gameId]; + } + $game = new Wootook_Core_Model_Game(); + try { + $game->load($gameId, 'code'); + $gameId = $game->getId(); + $gameCode = $game->getData('code'); + + self::$_gamesById[$gameId] = $game; + self::$_gamesByCode[$gameCode] = $game; + } catch (Wootook_Core_Exception_DataAccessException $e) { + throw new Wootook_Core_Exception_RuntimeException('Could not load game entity.', null, $e); + } + + return $game; + } + } + + public static function setWebsite($websiteId, $website) + { + $websiteKey = $website->getData('code'); + self::$_websitesById[$websiteId] = $website; + self::$_websitesByCode[$websiteKey] = $website; + } + + public static function setGame($gameId, $game) + { + $gameKey = $game->getData('code'); + self::$_gameById[$gameId] = $game; + self::$_gameByCode[$gameKey] = $game; + } + protected static function _initWebsiteConfig($websiteId) { if (self::$_config === null) { self::loadConfig(); } - $websiteId = 1; + try { + $website = self::getWebsite($websiteId); + } catch (Wootook_Core_Exception_RuntimeException $e) { + Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); + return null; + } + $websiteKey = $website->getData('code'); + $websiteId = $website->getId(); - if (!isset(self::$_websiteConfigs[$websiteId])) { - self::$_websiteConfigs[$websiteId] = clone self::$_globalConfig; - - $websiteConfig = self::$_config->getConfig("website/{$websiteId}"); - if ($websiteConfig !== null) { - self::$_websiteConfigs[$websiteId]->merge($websiteConfig); + if (!isset(self::$_websiteConfigs[$websiteKey])) { + self::$_websiteConfigs[$websiteKey] = clone self::$_config['default']; + if (isset(self::$_config['frontend'])) { + self::$_websiteConfigs[$websiteKey]->merge(self::$_config['frontend']); } - self::_appendDatabaseConfig(self::$_websiteConfigs[$websiteId], 'website', $websiteId); + $websiteConfig = self::$_config->getConfig("website/{$websiteKey}"); + if ($websiteConfig !== null) { + self::$_websiteConfigs[$websiteKey]->merge($websiteConfig); + } + + self::_appendDatabaseConfig(self::$_websiteConfigs[$websiteKey], 'website', $website); } - return self::$_websiteConfigs[$websiteId]; + return self::$_websiteConfigs[$websiteKey]; } protected static function _initGameConfig($gameId) @@ -384,23 +514,33 @@ class Wootook self::loadConfig(); } - $websiteId = 1; - $gameId = 1; - - if (!isset(self::$_gameConfigs[$gameId])) { - self::_initWebsiteConfig($websiteId); - - self::$_gameConfigs[$gameId] = clone self::$_websiteConfigs[$websiteId]; - - $gameConfig = self::$_config->getConfig("game/{$gameId}"); - if ($gameConfig !== null) { - self::$_gameConfigs[$gameId]->merge($gameConfig); - } - - self::_appendDatabaseConfig(self::$_gameConfigs[$gameId], 'game', $gameId); + try { + $game = self::getGame($gameId); + } catch (Wootook_Core_Exception_RuntimeException $e) { + Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); + return null; } - return self::$_gameConfigs[$gameId]; + $gameKey = $game->getData('code'); + $gameId = $game->getId(); + $websiteId = $game->getData('website_id'); + + if (!isset(self::$_gameConfigs[$gameKey])) { + $websiteConfig = self::_initWebsiteConfig($websiteId); + if ($websiteConfig === null) { + return null; + } + self::$_gameConfigs[$gameKey] = clone $websiteConfig; + + $gameConfig = self::$_config->getConfig("game/{$gameKey}"); + if ($gameConfig !== null) { + self::$_gameConfigs[$gameKey]->merge($gameConfig); + } + + self::_appendDatabaseConfig(self::$_gameConfigs[$gameKey], 'game', $game); + } + + return self::$_gameConfigs[$gameKey]; } public static function getConfig($path = null) @@ -415,36 +555,46 @@ class Wootook return self::$_globalConfig; } - public static function getWebsiteConfig($path = null, $websiteId = null) + public static function getWebsiteConfig($path = null, $websiteKey = null) { if (self::$_config === null) { self::loadConfig(); } - $websiteId = 1; + if ($websiteKey === null) { + $websiteKey = Wootook_Core_Model_Website::DEFAULT_CODE; + } - self::_initWebsiteConfig($websiteId); + $config = self::_initWebsiteConfig($websiteKey); + if ($config === null) { + return null; + } if ($path !== null) { - return self::$_websiteConfigs[$websiteId]->getConfig($path); + return $config->getConfig($path); } - return self::$_websiteConfigs[$websiteId]; + return $config; } - public static function getGameConfig($path = null, $gameId = null) + public static function getGameConfig($path = null, $gameKey = null) { if (self::$_config === null) { self::loadConfig(); } - $gameId = 1; + if ($gameKey === null) { + $gameKey = Wootook_Core_Model_Game::DEFAULT_CODE; + } - self::_initGameConfig($gameId); + $config = self::_initGameConfig($gameKey); + if ($config === null) { + return null; + } if ($path !== null) { - return self::$_gameConfigs[$gameId]->getConfig($path); + return $config->getConfig($path); } - return self::$_gameConfigs[$gameId]; + return $config; } public static function setConfig($path, $value, $websiteId = null, $gameId = null) @@ -453,12 +603,23 @@ class Wootook self::loadConfig(); } - $updater = new Wootook_Core_Model_Config(); - $updater->setPath($path)->setValue($value); - if ($websiteId !== null) { - $updater->setWebsiteId($websiteId); + if (!self::$_ignoreDatabaseConfig) { + $updater = new Wootook_Core_Model_Config(); + $updater->setPath($path)->setValue($value); + if ($websiteId !== null) { + $updater->setWebsiteId($websiteId); + if ($gameId !== null) { + $updater->setGameId($gameId); + self::$_gameConfigs[$gameId]->setConfig($path, $value); + } else { + self::$_websiteConfigs[$websiteId]->setConfig($path, $value); + } + } else { + self::$_globalConfig->setConfig($path, $value); + } + $updater->save(); + } else if ($websiteId !== null) { if ($gameId !== null) { - $updater->setGameId($gameId); self::$_gameConfigs[$gameId]->setConfig($path, $value); } else { self::$_websiteConfigs[$websiteId]->setConfig($path, $value); @@ -466,14 +627,13 @@ class Wootook } else { self::$_globalConfig->setConfig($path, $value); } - $updater->save(); return true; } public static function getBaseUrl() { - return self::$_config->getConfig('global/web/base_url'); + return self::getConfig('web/base_url'); } public static function getSkinUrl($package, $theme, $uri, Array $params = array()) @@ -504,13 +664,13 @@ class Wootook return false; } - Wootook_Core_ErrorProfiler::sleep(); + Wootook_Core_ErrorProfiler::getSingleton()->sleep(); if (($fp = @fopen($path, 'r', true)) === false) { - Wootook_Core_ErrorProfiler::wakeup(); + Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); return false; } fclose($fp); - Wootook_Core_ErrorProfiler::wakeup(); + Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); return true; } } \ No newline at end of file diff --git a/application/code/core/Wootook/Core/Block/Messages.php b/application/code/core/Wootook/Core/Block/Messages.php index f7c704a..103202a 100644 --- a/application/code/core/Wootook/Core/Block/Messages.php +++ b/application/code/core/Wootook/Core/Block/Messages.php @@ -14,14 +14,10 @@ class Wootook_Core_Block_Messages { $messages = array(); - var_dump($this->_storages); foreach ($this->_storages as $namespace) { $session = Wootook::getSession($namespace); - var_dump($session); foreach ($session->getMessages() as $messageLevel => $messageList) { - var_dump(array($messageLevel => $messageList)); - if (!isset($messages[$messageLevel])) { $messages[$messageLevel] = $messageList; } else { diff --git a/application/code/core/Wootook/Core/Config/Adapter/Array.php b/application/code/core/Wootook/Core/Config/Adapter/Array.php index f24c33a..20ae2cb 100644 --- a/application/code/core/Wootook/Core/Config/Adapter/Array.php +++ b/application/code/core/Wootook/Core/Config/Adapter/Array.php @@ -15,8 +15,7 @@ class Wootook_Core_Config_Adapter_Array $data = include $filename; if (!is_array($data)) { - throw new Wootook_Core_Exception_DataAccessException( - Wootook::__('Configuration file could not be loaded.')); + throw new Wootook_Core_Exception_DataAccessException('Configuration file could not be loaded.'); } $this->_init($data); diff --git a/application/code/core/Wootook/Core/Config/Node.php b/application/code/core/Wootook/Core/Config/Node.php index 4ef0bbd..0b25dbd 100644 --- a/application/code/core/Wootook/Core/Config/Node.php +++ b/application/code/core/Wootook/Core/Config/Node.php @@ -47,21 +47,22 @@ class Wootook_Core_Config_Node $length = count($explodedPath); $currentNode = $this; for ($i = 0; $i < $length; $i++) { - if (!$currentNode->offsetExists($explodedPath[$i])) { - $newNode = new Wootook_Core_Config_Node(array(), $currentNode); - $currentNode->offsetSet($explodedPath[$i], $newNode); + if ($i < ($length - 1)) { + if (!$currentNode->offsetExists($explodedPath[$i])) { + $newNode = new Wootook_Core_Config_Node(array(), $currentNode); + $currentNode->offsetSet($explodedPath[$i], $newNode); + } + } else if (is_array($value)) { + $currentNode->offsetSet($explodedPath[$i], new self($value, $this)); + break; + } else { + $currentNode->offsetSet($explodedPath[$i], $value); + break; } $currentNode = $currentNode->offsetGet($explodedPath[$i]); - if ($i >= ($length - 1)) { - if (is_array($value)) { - $currentNode->offsetSet($explodedPath[$i], new self($value, $this)); - } else { - $currentNode->offsetSet($explodedPath[$i], $value); - } - break; - } else if (!$currentNode instanceof Wootook_Core_Config_Node) { + if (!$currentNode instanceof Wootook_Core_Config_Node) { throw new Wootook_Core_Exception_RuntimeException(); } } diff --git a/application/code/core/Wootook/Core/Entity.php b/application/code/core/Wootook/Core/Entity.php index 5f58cba..0f2e90b 100644 --- a/application/code/core/Wootook/Core/Entity.php +++ b/application/code/core/Wootook/Core/Entity.php @@ -34,8 +34,16 @@ abstract class Wootook_Core_Entity { $id = func_get_arg(0); - $idFieldName = self::getIdFieldName(); + if (func_num_args() >= 2) { + $idFieldName = func_get_arg(1); + } else { + $idFieldName = $this->getIdFieldName(); + } + $database = $this->getReadConnection(); + if ($database === null) { + throw new Wootook_Core_Exception_DataAccessException('Could not load data: no read connection configured.'); + } $sql =<<getTable($this->getTableName())} @@ -77,6 +85,10 @@ SQL_EOF; $values[$idFieldName] = $this->getId(); $database = $this->getWriteConnection(); + if ($database === null) { + throw new Wootook_Core_Exception_DataAccessException('Could not load data: no write connection configured.'); + } + $sql =<<getTable($this->getTableName())} SET {$fieldsImploded} @@ -101,6 +113,10 @@ SQL_EOF; $tokensImploded = implode(', ', $tokens); $database = $this->getWriteConnection(); + if ($database === null) { + throw new Wootook_Core_Exception_DataAccessException('Could not load data: no write connection configured.'); + } + $sql =<<getTable($this->getTableName())} ($fieldsImploded) VALUES ({$tokensImploded}) @@ -128,6 +144,10 @@ SQL_EOF; $fieldsImploded = implod(', ', $fields); $idFieldName = self::getIdFieldName(); $database = $this->getWriteConnection(); + if ($database === null) { + throw new Wootook_Core_Exception_DataAccessException('Could not load data: no write connection configured.'); + } + $sql =<<getTable($this->getTableName())} WHERE {$idFieldName}=:{$idFieldName} diff --git a/application/code/core/Wootook/Core/ErrorProfiler.php b/application/code/core/Wootook/Core/ErrorProfiler.php index a00e3b7..ba64222 100644 --- a/application/code/core/Wootook/Core/ErrorProfiler.php +++ b/application/code/core/Wootook/Core/ErrorProfiler.php @@ -12,7 +12,7 @@ class Wootook_Core_ErrorProfiler private static $_isTraceRegistered = false; - private static $_listen = true; + private $_listen = true; private $_mute = false; @@ -30,7 +30,7 @@ class Wootook_Core_ErrorProfiler public function errorManager($errno, $errstr, $errfile = null, $errline = null, Array $errcontext = array()) { - if (!self::$_listen) { + if (!$this->_listen) { return; } @@ -92,10 +92,10 @@ class Wootook_Core_ErrorProfiler public function exceptionManager($exception) { - if (!self::$_listen) { + if (!$this->_listen) { return; } - $this->_exceptions[] = $exception; + $this->_exceptions[] = new Wootook_Core_Exception_Exception('Uncaught Exception: ' . $exception->getMessage(), null, $exception); } protected function _renderError($id, $error) @@ -171,7 +171,19 @@ ERROR_EOF; $index++; echo "Message #{$index}". PHP_EOL; echo $exception->getMessage() . PHP_EOL; - echo $exception->getTraceAsString(); + echo $exception->getTraceAsString() . PHP_EOL; + echo PHP_EOL; + + $child = 0; + $current = $exception; + while (($current = $current->getPrevious()) !== null) { + $child++; + echo " Child level #{$child}". PHP_EOL; + echo " " . $current->getMessage() . PHP_EOL; + echo $current->getTraceAsString() . PHP_EOL; + echo PHP_EOL; + } + echo PHP_EOL; } echo ''; } @@ -204,13 +216,13 @@ ERROR_EOF; } } - public static function sleep() + public function sleep() { - self::$_listen = false; + $this->_listen = false; } - public static function wakeup() + public function wakeup() { - self::$_listen = true; + $this->_listen = true; } } diff --git a/application/code/core/Wootook/Core/Exception/Exception.php b/application/code/core/Wootook/Core/Exception/Exception.php index c19c4b3..4751ddb 100644 --- a/application/code/core/Wootook/Core/Exception/Exception.php +++ b/application/code/core/Wootook/Core/Exception/Exception.php @@ -4,4 +4,22 @@ class Wootook_Core_Exception_Exception extends Exception implements Wootook_Core_Exception { + protected $_previous = null; + + public function __construct($message = null, $code = null, $previous = null) + { + if (PHP_VERSION_ID >= 50300) { + parent::__construct($message, $code, $previous); + } else { + parent::__construct($message, $code); + $this->_previous = $previous; + } + } + + public function __call($method, $params) + { + if (strtolower($method) == 'getprevious') { + return $this->_previous; + } + } } \ No newline at end of file diff --git a/application/code/core/Wootook/Core/Exception/RuntimeException.php b/application/code/core/Wootook/Core/Exception/RuntimeException.php index 9ddb316..bec4c92 100644 --- a/application/code/core/Wootook/Core/Exception/RuntimeException.php +++ b/application/code/core/Wootook/Core/Exception/RuntimeException.php @@ -4,4 +4,29 @@ class Wootook_Core_Exception_RuntimeException extends RuntimeException implements Wootook_Core_Exception { + protected $_previous = null; + + public function __construct($message = null, $code = null, $previous = null) + { + if (PHP_VERSION_ID >= 50300) { + parent::__construct($message, $code, $previous); + } else { + parent::__construct($message, $code); + $this->_previous = $previous; + } + } + + public function __call($method, $params) + { + if (strtolower($method) == 'getprevious') { + return $this->_previous; + } + } + + public function __toString() + { + return <<toArray(); + } if (!is_array($fileList) || empty($fileList)) { $fileList = $this->getAllDatas(); } else { @@ -41,8 +44,8 @@ class Wootook_Core_Layout } $this->_data = array(); - $this->setPackage(Wootook::getConfig('global/package')); - $this->setTheme(Wootook::getConfig('global/theme')); + $this->setPackage(Wootook::getConfig('package')); + $this->setTheme(Wootook::getConfig('theme')); foreach ($fileList as $layoutFile) { foreach (include $this->_getLayoutPath($layoutFile) as $layoutId => $layoutConfig) { @@ -186,12 +189,12 @@ class Wootook_Core_Layout $className = $namespace . $block; $fileName = $path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $block) . '.php'; - Wootook_Core_ErrorProfiler::sleep(); + Wootook_Core_ErrorProfiler::getSingleton()->sleep(); if (!($fp = @fopen($fileName, 'r', true))) { - Wootook_Core_ErrorProfiler::wakeup(); + Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); continue; } - Wootook_Core_ErrorProfiler::wakeup(); + Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); fclose($fp); if (!class_exists($className, true)) { diff --git a/application/code/core/Wootook/Core/Model/Config.php b/application/code/core/Wootook/Core/Model/Config.php index 792b6fe..e5b0170 100644 --- a/application/code/core/Wootook/Core/Model/Config.php +++ b/application/code/core/Wootook/Core/Model/Config.php @@ -10,8 +10,6 @@ class Wootook_Core_Model_Config extends Wootook_Core_Entity_SubTable { - private static $_singleton = null; - protected $_eventPrefix = 'core.config'; protected $_eventObject = 'config'; diff --git a/application/code/core/Wootook/Core/Model/Config/Abstract.php b/application/code/core/Wootook/Core/Model/Config/Abstract.php index ef946a8..14ba56c 100644 --- a/application/code/core/Wootook/Core/Model/Config/Abstract.php +++ b/application/code/core/Wootook/Core/Model/Config/Abstract.php @@ -6,13 +6,15 @@ abstract class Wootook_Core_Model_Config_Abstract { protected function _initData($filename) { - $config = Wootook::getConfig('global/storyline'); + $config = Wootook::getConfig('storyline'); - if ($config === null || empty($config)) { + if ($config === null) { $config = array( 'universe' => 'default', 'episode' => 'default' ); + } else { + $config = $config->toArray(); } $path = 'gamedata' . DIRECTORY_SEPARATOR . $config['universe'] . DIRECTORY_SEPARATOR diff --git a/application/code/core/Wootook/Core/Model/Game.php b/application/code/core/Wootook/Core/Model/Game.php new file mode 100644 index 0000000..1053df6 --- /dev/null +++ b/application/code/core/Wootook/Core/Model/Game.php @@ -0,0 +1,23 @@ +_tableName = 'core_game'; + $this->_idFieldName = 'game_id'; + } +} \ No newline at end of file diff --git a/application/code/core/Wootook/Core/Model/Session.php b/application/code/core/Wootook/Core/Model/Session.php index f30cd73..edc7f92 100644 --- a/application/code/core/Wootook/Core/Model/Session.php +++ b/application/code/core/Wootook/Core/Model/Session.php @@ -51,15 +51,16 @@ class Wootook_Core_Model_Session } $this->_data = &$_SESSION[$namespace]; - $this->_data['messages'] = array(); + if (!isset($this->_data['messages'])) { + $this->_data['messages'] = array(); + } } public function getMessages($clear = true) { $messages = $this->_data['messages']; if ($clear == true) { - var_dump($this->_data['messages']); - //$this->_data['messages'] = array(); + $this->_data['messages'] = array(); } return $messages; } diff --git a/application/code/core/Wootook/Core/Model/Website.php b/application/code/core/Wootook/Core/Model/Website.php new file mode 100644 index 0000000..4284aaa --- /dev/null +++ b/application/code/core/Wootook/Core/Model/Website.php @@ -0,0 +1,23 @@ +_tableName = 'core_website'; + $this->_idFieldName = 'website_id'; + } +} \ No newline at end of file diff --git a/application/code/core/Wootook/Core/Setup/Updater.php b/application/code/core/Wootook/Core/Setup/Updater.php index eea283e..5479fc2 100644 --- a/application/code/core/Wootook/Core/Setup/Updater.php +++ b/application/code/core/Wootook/Core/Setup/Updater.php @@ -55,10 +55,10 @@ class Wootook_Core_Setup_Updater 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"); + $hostname = Wootook::getConfig("database/{$connectionName}/params/hostname"); + $username = Wootook::getConfig("database/{$connectionName}/params/username"); + $database = Wootook::getConfig("database/{$connectionName}/params/database"); + $password = Wootook::getConfig("database/{$connectionName}/params/password"); if ($perms === null) { $perms = 'ALL PRIVILEGES'; @@ -79,10 +79,10 @@ SQL_EOF; 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"); + $hostname = Wootook::getConfig("database/{$connectionName}/params/hostname"); + $username = Wootook::getConfig("database/{$connectionName}/params/username"); + $database = Wootook::getConfig("database/{$connectionName}/params/database"); + $password = Wootook::getConfig("database/{$connectionName}/params/password"); if ($perms === null) { $perms = 'ALL PRIVILEGES'; @@ -111,10 +111,13 @@ SQL_EOF; return Wootook::getConfig($path); } - public function getGameConfig($path) + public function getWebsiteConfig($path = null, $websiteId = null) { - $config = Wootook_Core_Model_Config::getSingleton(); + return Wootook::getWebsiteConfig($path, $websiteId); + } - return $config->getData($path); + public function getGameConfig($path = null, $gameId = null) + { + return Wootook::getGameConfig($path, $gameId); } } diff --git a/application/code/core/Wootook/Core/Time.php b/application/code/core/Wootook/Core/Time.php index 62b9952..d8d0037 100644 --- a/application/code/core/Wootook/Core/Time.php +++ b/application/code/core/Wootook/Core/Time.php @@ -6,7 +6,7 @@ class Wootook_Core_Time public static function init($timezone = null) { if ($timezone === null) { - $timezone = Wootook::getConfig('global/date/timezone'); + $timezone = Wootook::getConfig('date/timezone'); } if ($timezone === null) { $timezone = 'GMT'; diff --git a/application/code/core/Wootook/Core/install/mysql5/.placeholder b/application/code/core/Wootook/Core/install/mysql5/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/application/code/core/Wootook/Core/install/mysql5/install-1.5.0.php b/application/code/core/Wootook/Core/install/mysql5/install-1.5.0.php new file mode 100644 index 0000000..19ff1ce --- /dev/null +++ b/application/code/core/Wootook/Core/install/mysql5/install-1.5.0.php @@ -0,0 +1,195 @@ + + * 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 . + * + * --> 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. + * + */ + +$this->setSetupConnection('core_setup'); + +$sql = <<getTableName('core_website')} ( + `website_id` TINYINT UNSIGNED NOT NULL, + `code` VARCHAR(64) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `sort_order` TINYINT UNSIGNED NOT NULL, + `default_group_id` TINYINT UNSIGNED NOT NULL, + `is_default` BOOL NOT NULL, + `is_staging` BOOL NOT NULL, + `is_active` BOOL NOT NULL, + PRIMARY KEY (`website_id`), + UNIQUE (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_game_group')} ( + `group_id` TINYINT UNSIGNED NOT NULL, + `website_id` TINYINT UNSIGNED NOT NULL, + `code` VARCHAR(64) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `sort_order` TINYINT UNSIGNED NOT NULL, + `is_default` BOOL NOT NULL, + PRIMARY KEY (`group_id`), + INDEX (`website_id`), + UNIQUE (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_game')} ( + `game_id` SMALLINT UNSIGNED NOT NULL, + `group_id` TINYINT UNSIGNED NOT NULL, + `website_id` TINYINT UNSIGNED NOT NULL, + `code` VARCHAR(64) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `sort_order` TINYINT UNSIGNED NOT NULL, + `is_default` BOOL NOT NULL, + `is_staging` BOOL NOT NULL, + `is_active` BOOL NOT NULL, + PRIMARY KEY (`group_id`), + INDEX (`website_id`), + UNIQUE (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_website')} (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`, `is_staging`, `is_active`) +VALUES +(0, "admin", "Administration", 0, 0, 0, 0, 1), +(1, "default", "Default Website", 1, 1, 1, 0, 1); +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_game_group')} (`group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`) +VALUES +(0, 0, "admin", "Administration", 0, 0), +(1, 1, "default", "Default Group", 1, 1); +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_game')} (`game_id`, `group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`, `is_staging`, `is_active`) +VALUES +(0, 0, 0, "admin", "Administration", 0, 0, 0, 1), +(1, 1, 1, "default", "Default Game", 1, 1, 0, 1); +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_config')} ( + `website_id` TINYINT UNSIGNED NOT NULL, + `game_id` TINYINT UNSIGNED NOT NULL, + `config_path` VARCHAR(64) NOT NULL, + `config_value` VARCHAR(255) NOT NULL, + PRIMARY KEY (`website_id`, `game_id`, `config_path`), + INDEX (`website_id`), + INDEX (`game_id`), + INDEX (`config_path`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_config')} (`website_id`, `game_id`, `config_path`, `config_value`) VALUES + (1, 1, 'resource/base-income/metal', '20'), + (1, 1, 'resource/base-income/cristal', '10'), + (1, 1, 'resource/base-income/deuterium', '0'), + (1, 1, 'resource/base-income/energy', '0'), + + (1, 1, 'resource/initial/fields', '163'), + (1, 1, 'resource/initial/metal', '500'), + (1, 1, 'resource/initial/cristal', '500'), + (1, 1, 'resource/initial/deuterium', '0'), + (1, 1, 'resource/initial/energy', '0'), + + (1, 1, 'game/general/name', 'Wootook'), + (1, 1, 'game/general/boards-url', 'http://wootook.org/board/'), + (1, 1, 'game/general/extra-url-title', 'Wootook!'), + (1, 1, 'game/general/extra-url', 'http://wootook.org/'), + (1, 1, 'game/general/active', '1'), + (1, 1, 'game/general/closing-message', 'Le jeu est clos pour le moment.'), + (1, 1, 'game/general/locale', 'fr_FR'), + + (1, 1, 'game/resource/multiplier', '1000'), + (1, 1, 'game/speed/general', '2500'), + (1, 1, 'game/speed/fleet', '2500'), + + (1, 1, 'game/debris/metal-percent', '30'), + (1, 1, 'game/debris/cristal-percent', '30'), + (1, 1, 'game/debris/deuterium-percent', '0'), + (1, 1, 'game/debris/energy-percent', '0'), + + (1, 1, 'game/debris/fleet', '1'), + (1, 1, 'game/debris/defense', '0'), + + (1, 1, 'game/noob-protection/active', '0'), + (1, 1, 'game/noob-protection/points-cap', '5000'), + (1, 1, 'game/noob-protection/multiplier', '5'), + + (0, 0, 'web/cookie/name', '__wtk'), + (0, 0, 'web/cookie/time', '2592000'), + (0, 0, 'web/cookie/domain', ''), + (0, 0, 'web/cookie/path', ''), + + (0, 0, 'engine/options/bbcode', '1'), + (0, 0, 'engine/options/ga', '1'), + (0, 0, 'engine/options/announces', '0'), + (0, 0, 'engine/options/retailer', '0'), + (0, 0, 'engine/options/notes', '0'), + (0, 0, 'engine/options/chat', '0'), + (0, 0, 'engine/options/banner', '0'), + (0, 0, 'engine/options/vacation-min-time', '172800'), + + (0, 0, 'game/news/active', '0'), + (0, 0, 'game/news/content', 'Bienvenue sur le nouveau serveur de jeu Wootook!'), + + (0, 0, 'engine/ban/duration', '86400'), + + (0, 0, 'engine/bot/active', '0'), + (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); diff --git a/application/code/core/Wootook/Core/install/mysql5/uninstall-1.5.0.php b/application/code/core/Wootook/Core/install/mysql5/uninstall-1.5.0.php new file mode 100644 index 0000000..571d2fb --- /dev/null +++ b/application/code/core/Wootook/Core/install/mysql5/uninstall-1.5.0.php @@ -0,0 +1,67 @@ + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * --> 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. + * + */ + +$this->setSetupConnection('legacies_setup'); + +$sql = <<getTableName('core_website')}; +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_game_group')}; +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_game')}; +SQL_EOF; + +$this->query($sql); + +$sql = <<getTableName('core_config')}; +SQL_EOF; + +$this->query($sql); diff --git a/application/code/core/Wootook/Empire/Exception/Exception.php b/application/code/core/Wootook/Empire/Exception/Exception.php index 6fd4d15..b3154b8 100644 --- a/application/code/core/Wootook/Empire/Exception/Exception.php +++ b/application/code/core/Wootook/Empire/Exception/Exception.php @@ -4,4 +4,22 @@ class Wootook_Empire_Exception_Exception extends Exception implements Wootook_Empire_Exception { + protected $_previous = null; + + public function __construct($message = null, $code = null, $previous = null) + { + if (PHP_VERSION_ID >= 50300) { + parent::__construct($message, $code, $previous); + } else { + parent::__construct($message, $code); + $this->_previous = $previous; + } + } + + public function __call($method, $params) + { + if (strtolower($method) == 'getprevious') { + return $this->_previous; + } + } } \ No newline at end of file diff --git a/application/code/core/Wootook/Empire/Exception/RuntimeException.php b/application/code/core/Wootook/Empire/Exception/RuntimeException.php index cef5ece..c4dcb32 100644 --- a/application/code/core/Wootook/Empire/Exception/RuntimeException.php +++ b/application/code/core/Wootook/Empire/Exception/RuntimeException.php @@ -4,4 +4,22 @@ class Wootook_Empire_Exception_RuntimeException extends RuntimeException implements Wootook_Empire_Exception { + protected $_previous = null; + + public function __construct($message = null, $code = null, $previous = null) + { + if (PHP_VERSION_ID >= 50300) { + parent::__construct($message, $code, $previous); + } else { + parent::__construct($message, $code); + $this->_previous = $previous; + } + } + + public function __call($method, $params) + { + if (strtolower($method) == 'getprevious') { + return $this->_previous; + } + } } \ No newline at end of file diff --git a/application/code/core/Wootook/Empire/Model/Planet.php b/application/code/core/Wootook/Empire/Model/Planet.php index cc1b0c0..494b714 100644 --- a/application/code/core/Wootook/Empire/Model/Planet.php +++ b/application/code/core/Wootook/Empire/Model/Planet.php @@ -960,7 +960,7 @@ class Wootook_Empire_Model_Planet $key = array_rand($positions, 1); $finalPosition = $positions[$key]; - $user->createNewPlanet( + $planet = $user->createNewPlanet( $systemInfo->getData('galaxy'), $systemInfo->getData('system'), $finalPosition, @@ -992,10 +992,8 @@ class Wootook_Empire_Model_Planet ->group('galaxy.system') ; - $config = Wootook_Core_Model_Config::getSingleton(); - - if ($galaxyList === null && $config->hasData('user/registration/galaxy_list')) { - $galaxyList = explode(',', $config->getData('user/registration/galaxy_list')); + if ($galaxyList === null && Wootook::getGameConfig('user/registration/galaxy_list')) { + $galaxyList = explode(',', Wootook::getGameConfig('user/registration/galaxy_list')); } if ($galaxyList !== null) { @@ -1003,8 +1001,8 @@ class Wootook_Empire_Model_Planet $collection->where('galaxy.galaxy IN(' . implode(', ', $galaxyList) . ')'); } - if ($systemList === null && $config->hasData('user/registration/system_list')) { - $systemList = explode(',', $config->getData('user/registration/system_list')); + if ($systemList === null && Wootook::getGameConfig('user/registration/system_list')) { + $systemList = explode(',', Wootook::getGameConfig('user/registration/system_list')); } if ($systemList !== null) { diff --git a/application/code/core/Wootook/Empire/Model/User.php b/application/code/core/Wootook/Empire/Model/User.php index 148796d..91ea368 100644 --- a/application/code/core/Wootook/Empire/Model/User.php +++ b/application/code/core/Wootook/Empire/Model/User.php @@ -252,9 +252,9 @@ class Wootook_Empire_Model_User $size = mt_rand(floor($factor / 10), ceil($factor * 5 / 4)) + mt_rand(0, $fuzz); } - $planet = new self(); + $planet = new Wootook_Empire_Model_Planet(); $planet - ->setData('id_owner', $user->getId()) + ->setData('id_owner', $this->getId()) ->setData('name', $name) ->setData('galaxy', $galaxy) ->setData('system', $system) @@ -271,12 +271,19 @@ class Wootook_Empire_Model_User $planet->setData($resourceData['production_field'], $resourceConfig[$resource]); } + $planet->save(); + + var_dump($planet->getId()); + die(); + Wootook::dispatchEvent('planet.init', array( 'planet' => $planet, - 'user' => $user + 'user' => $this )); $planet->save(); + + return $planet; } /** diff --git a/application/design/install/default/layouts/install.php b/application/design/install/default/layouts/install.php index 430f677..6053560 100644 --- a/application/design/install/default/layouts/install.php +++ b/application/design/install/default/layouts/install.php @@ -3,15 +3,6 @@ 'update' => '2columns-left', 'reference' => array( 'content' => array( - 'children' => array( - 'navigation' => array( - 'type' => 'core/html.navigation', - 'template' => 'page/html/navigation.phtml', - 'actions' => array() - ) - ) - ), - 'left' => array( 'children' => array( 'status' => array( 'type' => 'core/template', @@ -39,7 +30,7 @@ 'method' => 'setData', 'params' => array( 'key' => 'step', - 'value' => 'intro' + 'value' => 0 ) ) ) @@ -64,7 +55,7 @@ 'method' => 'setData', 'params' => array( 'key' => 'step', - 'value' => 'system' + 'value' => 1 ) ) ) @@ -89,7 +80,7 @@ 'method' => 'setData', 'params' => array( 'key' => 'step', - 'value' => 'database' + 'value' => 2 ) ) ) @@ -114,7 +105,7 @@ 'method' => 'setData', 'params' => array( 'key' => 'step', - 'value' => 'universe' + 'value' => 3 ) ) ) @@ -139,7 +130,7 @@ 'method' => 'setData', 'params' => array( 'key' => 'step', - 'value' => 'profile' + 'value' => 4 ) ) ) diff --git a/application/design/install/default/scripts/deprecated/install/ins_acc.tpl b/application/design/install/default/scripts/deprecated/install/ins_acc.tpl deleted file mode 100644 index 990f8db..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_acc.tpl +++ /dev/null @@ -1,44 +0,0 @@ - - -
getData('ins_tx_acc1')?>
-getData('ins_tx_acc2')?>

- - - - - - - - - - - - - - - - - - - - - -
getData('ins_acc_user')?>:
getData('ins_acc_pass')?>:
getData('ins_acc_email')?>:
getData('ins_acc_planet')?>:
getData('ins_acc_sex')?>:
-
- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_acc_done.tpl b/application/design/install/default/scripts/deprecated/install/ins_acc_done.tpl deleted file mode 100644 index 2e14361..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_acc_done.tpl +++ /dev/null @@ -1,9 +0,0 @@ - - -
getData('ins_tx_done2')?>
-getData('ins_tx_done3')?>

- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_body.tpl b/application/design/install/default/scripts/deprecated/install/ins_body.tpl deleted file mode 100644 index 295e294..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_body.tpl +++ /dev/null @@ -1,28 +0,0 @@ -

- - - - - - - - -getData('ins_page')?> - -
getData('ins_appname')?>getData('ins_tx_sys')?>
getData('ins_tx_state')?> getData('ins_state')?>
- - - - - - - - - - - - - - - -
getData('ins_mnu_intro')?>
getData('ins_mnu_inst')?>
getData('ins_mnu_goto')?>
getData('ins_mnu_upgr')?>
getData('ins_mnu_quit')?>
\ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_form.tpl b/application/design/install/default/scripts/deprecated/install/ins_form.tpl deleted file mode 100644 index 9b3b364..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_form.tpl +++ /dev/null @@ -1,33 +0,0 @@ - - -
getData('ins_tx_inst1')?>
-getData('ins_tx_inst2')?>
-getData('ins_tx_inst3')?>

- - - - - - - - - - - - - - - - - - - - - -
getData('ins_form_server')?>:
getData('ins_form_db')?>:
getData('ins_form_prefix')?>:
getData('ins_form_login')?>:
getData('ins_form_pass')?>:
-
- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_form_done.tpl b/application/design/install/default/scripts/deprecated/install/ins_form_done.tpl deleted file mode 100644 index 3d9426d..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_form_done.tpl +++ /dev/null @@ -1,8 +0,0 @@ - - -

getData('ins_tx_done1')?>

- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_goto_done.tpl b/application/design/install/default/scripts/deprecated/install/ins_goto_done.tpl deleted file mode 100644 index 55d1b13..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_goto_done.tpl +++ /dev/null @@ -1,9 +0,0 @@ - - -
getData('ins_tx_done4')?>
-getData('ins_tx_done3')?>

- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_goto_form.tpl b/application/design/install/default/scripts/deprecated/install/ins_goto_form.tpl deleted file mode 100644 index 0539d11..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_goto_form.tpl +++ /dev/null @@ -1,33 +0,0 @@ - - -
getData('ins_tx_inst1')?>
-getData('ins_tx_goto4')?>
-getData('ins_tx_goto5')?>

- - - - - - - - - - - - - - - - - - - - - -
getData('ins_form_server')?>:
getData('ins_form_db')?>:
getData('ins_form_prefix')?>:
getData('ins_form_login')?>:
getData('ins_form_pass')?>:
-
- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_goto_intro.tpl b/application/design/install/default/scripts/deprecated/install/ins_goto_intro.tpl deleted file mode 100644 index 16c01e9..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_goto_intro.tpl +++ /dev/null @@ -1,10 +0,0 @@ - - -
getData('ins_tx_goto1')?>
-getData('ins_tx_goto2')?>
-getData('ins_tx_goto3')?>

- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/deprecated/install/ins_intro.tpl b/application/design/install/default/scripts/deprecated/install/ins_intro.tpl deleted file mode 100644 index fe25771..0000000 --- a/application/design/install/default/scripts/deprecated/install/ins_intro.tpl +++ /dev/null @@ -1,11 +0,0 @@ - - -
getData('ins_tx_welco')?>
-getData('ins_tx_intr1')?>
-getData('ins_tx_intr2')?>
-getData('ins_tx_intr3')?>

- - - - - \ No newline at end of file diff --git a/application/design/install/default/scripts/status.phtml b/application/design/install/default/scripts/status.phtml new file mode 100644 index 0000000..6deda53 --- /dev/null +++ b/application/design/install/default/scripts/status.phtml @@ -0,0 +1,8 @@ +
+ getData('step')?> +

__('Welcome')?>

+

__('System')?>

+

__('Database')?>

+

__('Admin profile')?>

+

__('Summary')?>

+
\ No newline at end of file diff --git a/config.php b/config.php index 05cf3cd..e69de29 100644 --- a/config.php +++ b/config.php @@ -1,82 +0,0 @@ - - array ( - 'storyline' => - array ( - 'universe' => 'legacies', - 'episode' => 'default', - ), - 'web' => - array ( - 'base_url' => 'http://localhost/projects/wootook-1.5/', - ), - 'date' => - array ( - 'timezone' => 'Europe/Paris', - ), - 'layout' => - array ( - 'page' => 'page.php', - 'admin' => 'admin.php', - 'empire' => 'empire.php', - ), - 'locales' => - array ( - 'fr' => 'fr_FR', - 'fr_FR' => 'fr_FR', - 'en' => 'en_US', - 'en_US' => 'en_US', - ), - 'database' => - array ( - 'default' => - array ( - 'engine' => 'mysql', - 'options' => - array ( - ), - 'params' => - array ( - 'hostname' => 'localhost', - 'username' => 'root', - 'password' => '%J4mzdo69$', - 'database' => 'db_xnova', - 'port' => '3306', - ), - 'table_prefix' => 'wtk_', - ), - 'core_setup' => - array ( - 'use' => 'default', - ), - 'core_read' => - array ( - 'use' => 'default', - ), - 'core_write' => - array ( - 'use' => 'default', - ), - ), - ), - 'default' => - array ( - 'engine' => - array ( - 'core' => - array ( - 'use_large_numbers' => false, - ), - 'universe' => - array ( - 'galaxies' => NULL, - 'systems' => NULL, - 'positions' => NULL, - ), - 'combat' => - array ( - 'allow_spy_drone_attacks' => false, - ), - ), - ), -); \ No newline at end of file diff --git a/install/index.php b/install/index.php index cd71a60..23a77a4 100644 --- a/install/index.php +++ b/install/index.php @@ -45,15 +45,6 @@ $step = isset($_GET['step']) ? intval($_GET['step']) : 1; $prevStep = $step - 1; $nextStep = $step + 1; -$modules = array( - 'Wootook_Core', - 'Wootook_Empire', - 'Legacies_Empire', - 'Legacies_Officers' - ); - -includeLang('install/install'); - $baseUrl = (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on" ? 'https://' : 'http://') . $_SERVER["SERVER_NAME"] . ($_SERVER["SERVER_PORT"] != "80" ? ":{$_SERVER["SERVER_PORT"]}" : ''); if (isset($_SERVER['REQUEST_URI'])) { @@ -63,17 +54,40 @@ if (isset($_SERVER['REQUEST_URI'])) { $baseUrl .= dirname(dirname($_SERVER['REQUEST_URI'])) . '/'; } } - -Wootook::setConfig('global/web/base_url', $baseUrl); - -Wootook::setConfig('global/package', 'install'); -Wootook::setConfig('global/theme', 'default'); -Wootook::setconfig('global/layout', array( - 'page' => 'page.php', - 'install' => 'install.php' - )); - $session = Wootook::getSession('install'); + +$website = new Wootook_Core_Model_Website(); +$website->setId(0)->setData('code', Wootook_Core_Model_Website::DEFAULT_CODE); +Wootook::setWebsite(0, $website); + +$game = new Wootook_Core_Model_Game(); +$game->setId(0)->setData('code', Wootook_Core_Model_Game::DEFAULT_CODE); +Wootook::setWebsite(0, $game); + +$configRewrites = array( + 'default' => array( + 'web' => array( + 'base_url' => $baseUrl + ), + 'package' => 'install', + 'theme' => 'default', + 'layout' => array( + 'page' => 'page.php', + 'install' => 'install.php' + ), + 'storyline' => array( + 'universe' => 'legacies', + 'episode' => 'default', + ) + ) + ); + +$config = unserialize($session->getData('config')); +if (!is_array($config)) { + $config = array(); +} +Wootook::loadConfig(array_merge_recursive($config, $configRewrites)); + $layout = new Wootook_Core_Layout(); $request = new Wootook_Core_Controller_Request_Http(); $response = new Wootook_Core_Controller_Response_Http(); @@ -284,10 +298,18 @@ case 'install': ) ), ); - Wootook::writeConfig($config); + $session->setData('config', serialize($config)); + $writer = new Wootook_Core_Config_Adapter_Array(); + $writer->setData($config); + $writer->save(ROOT_PATH . 'config.php'); + + Wootook::loadConfig(array_merge_recursive($writer->toArray(), $configRewrites)); + + $galaxyCount = Wootook::getConfig('engine/universe/galaxies'); + $systemCount = Wootook::getConfig('engine/universe/systems'); $gameplays = include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'gameplays.php'; - $gameplayKey = $config['global']['storyline']['universe']; + $gameplayKey = Wootook::getConfig('storyline/universe'); if (!isset($gameplays[$gameplayKey])) { $gameplayKey = key($gameplays); } @@ -313,28 +335,18 @@ case 'install': } } catch (Wootook_Core_Setup_Exception_VersionStageError $e) { Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); - - $session->addError($e->getMessage()); - $session->setData('step', STEP_UNIVERSE); - $response->setRedirect(Wootook::getUrl('install/index.php', array('mode' => 'install', 'step' => STEP_UNIVERSE))); - $response->sendHeaders(); continue; } catch (Wootook_Core_Setup_Exception_VersionValueError $e) { Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); - - $session->addError($e->getMessage()); - $session->setData('step', STEP_UNIVERSE); - $response->setRedirect(Wootook::getUrl('install/index.php', array('mode' => 'install', 'step' => STEP_UNIVERSE))); - $response->sendHeaders(); continue; } catch (Wootook_Core_Setup_Exception_RuntimeException $e) { + $session->addError($e->getMessage()); Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); - $session->addError($e->getMessage()); - $session->setData('step', STEP_UNIVERSE); $response->setRedirect(Wootook::getUrl('install/index.php', array('mode' => 'install', 'step' => STEP_UNIVERSE))); $response->sendHeaders(); - continue; + exit(0); + break; } } $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'gamedata' . DIRECTORY_SEPARATOR diff --git a/scripts/createbanner.php b/scripts/createbanner.php index b09097a..207435e 100644 --- a/scripts/createbanner.php +++ b/scripts/createbanner.php @@ -76,11 +76,9 @@ LEFT JOIN {{table}}planets AS planets ON planets.id_owner=users.id WHERE users.id={$id} EOF; -$config = Wootook_Core_Model_Config::getSingleton(); - $data = array_merge( array( - 'game_name' => $config['game_name'], + 'game_name' => Wootook::getGameConfig('game/general/name'), 'date' => date('d M Y') ), doquery($sql, '', true)