From dce83f9a143a864f32a4e8f6e26c40f5ef841925 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Wed, 8 Sep 2010 00:42:46 +0100 Subject: [PATCH] moving the configuration closer to the start fixes #163 --- app_controller.php | 58 +++++++++++++++++++ app_model.php | 2 +- .../libs/controllers/components/infinitas.php | 54 ----------------- 3 files changed, 59 insertions(+), 55 deletions(-) diff --git a/app_controller.php b/app_controller.php index 846e2af27..c264822df 100644 --- a/app_controller.php +++ b/app_controller.php @@ -273,6 +273,7 @@ public function beforeFilter(){ * application. */ public function __construct(){ + $this->__setupConfig(); $event = EventCore::trigger(new StdClass(), 'requireComponentsToLoad'); if(isset($event['requireComponentsToLoad']['libs'])){ @@ -288,10 +289,67 @@ public function __construct(){ $this->components = array_merge($this->components, $components); } } + + unset($event); parent::__construct(); } + /** + * Set up system configuration. + * + * Load the default configuration and check if there are any configs + * to load from the current plugin. configurations can be completely rewriten + * or just added to. + */ + private function __setupConfig(){ + $this->configs = ClassRegistry::init('Management.Config')->getConfig(); + + $eventData = EventCore::trigger(new StdClass(), $this->plugin.'.setupConfigStart', $this->configs); + if (isset($eventData['setupConfigStart'][$this->plugin])){ + $this->configs = (array)$eventData['setupConfigStart'][$this->plugin]; + + if (!array($this->configs)) { + $this->cakeError('eventError', array('message' => 'Your config is wrong.', 'event' => $eventData)); + } + } + + $eventData = EventCore::trigger(new StdClass(), $this->plugin.'.setupConfigEnd'); + if (isset($eventData['setupConfigEnd'][$this->plugin])){ + $this->configs = $this->configs + (array)$eventData['setupConfigEnd'][$this->plugin]; + } + + if (!$this->__writeConfigs()) { + $this->cakeError('configError', array('message' => 'Config was not written')); + } + + unset($this->configs, $eventData); + } + + /** + * Write the configuration. + * + * Write all the config values that have been called found in InfinitasComponent::setupConfig() + */ + private function __writeConfigs(){ + if (empty($this->configs)) { + return false; + } + + foreach($this->configs as $config) { + if (!(isset($config['Config']['key']) || isset($config['Config']['value']))) { + $config['Config']['key'] = isset($config['Config']['key']) ? $config['Config']['key'] : 'NOT SET'; + $config['Config']['value'] = isset($config['Config']['key']) ? $config['Config']['value'] : 'NOT SET'; + $this->log(serialize($config['Config']), 'configuration_error'); + continue; + } + + Configure::write($config['Config']['key'], $config['Config']['value']); + } + + return true; + } + /** * Common methods for the app */ diff --git a/app_model.php b/app_model.php index d3ef23b87..8e878719f 100644 --- a/app_model.php +++ b/app_model.php @@ -53,7 +53,7 @@ class AppModel extends LazyModel { function __construct($id = false, $table = null, $ds = null) { $this->__getPlugin(); - parent::__construct($id, $table, $ds); + parent::__construct($id, $table, $ds); if (isset($this->_schema) && is_array($this->_schema)) { if($this->Behaviors->enabled('Event')) { diff --git a/extensions/libs/controllers/components/infinitas.php b/extensions/libs/controllers/components/infinitas.php index cd6f34f02..991f5b03c 100644 --- a/extensions/libs/controllers/components/infinitas.php +++ b/extensions/libs/controllers/components/infinitas.php @@ -35,7 +35,6 @@ public function initialize(&$controller, $settings = array()) { $this->Controller = &$controller; $settings = array_merge(array(), (array)$settings); - $this->setupConfig(); $this->__registerPlugins(); $this->__checkBadLogins(); @@ -64,59 +63,6 @@ private function __registerPlugins(){ } } - /** - * Set up system configuration. - * - * Load the default configuration and check if there are any configs - * to load from the current plugin. configurations can be completely rewriten - * or just added to. - */ - public function setupConfig(){ - $this->configs = Cache::read('core_configs', 'core'); - - if ($this->configs === false) { - $this->configs = ClassRegistry::init('Management.Config')->getConfig(); - } - - $eventData = $this->Controller->Event->trigger($this->Controller->plugin.'.setupConfigStart', $this->configs); - if (isset($eventData['setupConfigStart'][$this->Controller->plugin])){ - $this->configs = (array)$eventData['setupConfigStart'][$this->Controller->plugin]; - - if (!array($this->configs)) { - $this->cakeError('eventError', array('message' => 'Your config is wrong.', 'event' => $eventData)); - } - } - - $eventData = $this->Controller->Event->trigger($this->Controller->plugin.'.setupConfigEnd'); - if (isset($eventData['setupConfigEnd'][$this->Controller->plugin])){ - $this->configs = $this->configs + (array)$eventData['setupConfigEnd'][$this->Controller->plugin]; - } - - if (!$this->_writeConfigs()) { - $this->cakeError('configError', array('message' => 'Config was not written')); - } - } - - /** - * Write the configuration. - * - * Write all the config values that have been called found in InfinitasComponent::setupConfig() - */ - function _writeConfigs(){ - if (empty($this->configs)) { - return false; - } - - foreach($this->configs as $config) { - if (!(isset($config['Config']['key']) || isset($config['Config']['value']))) { - continue; - } - Configure::write($config['Config']['key'], $config['Config']['value']); - } - - return true; - } - /** * Setup the theme for the site *