public function beforeSaveConfig(Am_Config $before, Am_Config $after) { // Do the same for plugins; foreach (Am_Di::getInstance()->plugins as $type => $pm) { /* @var $pm Am_Plugins */ $configKey = $type == 'modules' ? 'modules' : 'plugins.' . $type; $b = (array) $before->get($configKey); $a = (array) $after->get($configKey); $enabled = array_filter(array_diff($a, $b), 'strlen'); $disabled = array_filter(array_diff($b, $a), 'strlen'); foreach ($disabled as $plugin) { if ($pm->load($plugin)) { try { $pm->get($plugin)->deactivate(); } catch (Exception $e) { Am_Di::getInstance()->errorLogTable->logException($e); trigger_error("Error during plugin [{$plugin}] deactivation: " . get_class($e) . ": " . $e->getMessage(), E_USER_WARNING); } } // Now clean config for plugin; $after->set($pm->getConfigKey($plugin), array()); } foreach ($enabled as $plugin) { if ($type == 'payment' && !empty($this->plugins_cc[$plugin]) && !Am_Di::getInstance()->modules->isEnabled('cc')) { // we got a cc plugin enabled but cc module is not yet enabled! $modules_cc = $after->get('modules', array()); $modules_cc[] = 'cc'; $modules_cc = array_unique($modules_cc); $after->set('modules', $modules_cc); continue; } if ($pm->load($plugin)) { $class = $pm->getPluginClassName($plugin); try { call_user_func(array($class, 'activate'), $plugin, $type); } catch (Exception $e) { Am_Di::getInstance()->errorLogTable->logException($e); trigger_error("Error during plugin [{$plugin}] activattion: " . get_class($e) . ": " . $e->getMessage(), E_USER_WARNING); } } } } Am_Di::getInstance()->config->set('modules', $modules = $after->get('modules', array())); Am_Di::getInstance()->app->dbSync(true, $modules); $after->save(); }
public function beforeSaveConfig(Am_Config $before, Am_Config $after) { // Do the same for plugins; foreach (array('modules', 'payment', 'misc', 'protect') as $type) { $configKey = $type == 'modules' ? 'modules' : 'plugins.' . $type; $b = (array) $before->get($configKey); $a = (array) $after->get($configKey); $enabled = array_filter(array_diff($a, $b), 'strlen'); $disabled = array_filter(array_diff($b, $a), 'strlen'); $pm = Am_Di::getInstance()->plugins[$type]; foreach ($disabled as $plugin) { if ($pm->load($plugin)) { try { $pm->get($plugin)->deactivate(); } catch (Exception $e) { Am_Di::getInstance()->errorLogTable->logException($e); trigger_error("Error during plugin [{$plugin}] deactivation: " . get_class($e) . ": " . $e->getMessage(), E_USER_WARNING); } } // Now clean config for plugin; $after->set($pm->getConfigKey($plugin), array()); } foreach ($enabled as $plugin) { if ($pm->load($plugin)) { $class = $pm->getPluginClassName($plugin); try { call_user_func(array($class, 'activate'), $plugin, $type); } catch (Exception $e) { Am_Di::getInstance()->errorLogTable->logException($e); trigger_error("Error during plugin [{$plugin}] activattion: " . get_class($e) . ": " . $e->getMessage(), E_USER_WARNING); } } } } Am_Di::getInstance()->config->set('modules', $modules = $after->get('modules', array())); Am_Di::getInstance()->app->dbSync(true, $modules); $after->save(); }