/** * Internal function to parse and handle the configs in the theme.xml file. * This is used for installations and upgrades. * * Returns false if nothing changed, else will return the configuration options changed. * * @param boolean $install Set to false to force uninstall/disable mode. * @param int $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output. * * @return false | array * * @throws \InstallerException */ public function _parseConfigs($install = true, $verbosity = 0) { // Keep track of if this changed anything. $changes = array(); $action = $install ? 'Installing' : 'Uninstalling'; $set = $install ? 'Set' : 'Unset'; \Core\Utilities\Logger\write_debug($action . ' configs for ' . $this->getName()); // I need to get the schema definitions first. $node = $this->_xmlloader->getElement('configs'); //$prefix = $node->getAttribute('prefix'); // Now, get every table under this node. foreach ($node->getElementsByTagName('config') as $confignode) { /** @var \DOMElement $confignode */ $key = $confignode->getAttribute('key'); $options = $confignode->getAttribute('options'); $type = $confignode->getAttribute('type'); $default = $confignode->getAttribute('default'); $title = $confignode->getAttribute('title'); $description = $confignode->getAttribute('description'); $mapto = $confignode->getAttribute('mapto'); $encrypted = $confignode->getAttribute('encrypted'); $formAtts = $confignode->getAttribute('form-attributes'); if ($encrypted === null || $encrypted === '') { $encrypted = '0'; } if ($verbosity == 2) { CLI::PrintActionStart($action . ' config ' . $key); } // Themes only allow for keys starting with "/theme/"! // This is to encourage that all themes share a common subset of configuration options. // EG: if the end user sees: "Site Logo", "Business Address", "Business Phone" on one theme, // they would be expecting to see those same options with the same values if they change the theme, // (and the new theme supports those same options). if (strpos($key, '/theme/') !== 0) { trigger_error('Please ensure that all config options in themes start with "/theme/"! (Mismatched config found in ' . $this->getName() . ':' . $key, E_USER_NOTICE); continue; } // Default if omitted. if (!$type) { $type = 'string'; } $m = \ConfigHandler::GetConfig($key); $m->set('options', $options); $m->set('type', $type); $m->set('default_value', $default); $m->set('title', $title); $m->set('description', $description); $m->set('mapto', $mapto); $m->set('encrypted', $encrypted); $m->set('form_attributes', $formAtts); // Default from the xml, only if it's not already set. if ($m->get('value') === null || !$m->exists()) { $m->set('value', $confignode->getAttribute('default')); } // Allow configurations to overwrite any value. This is useful on the initial installation. if (is_array(\Core\Session::Get('configs')) && isset(\Core\Session::Get('configs')[$key])) { $m->set('value', \Core\Session::Get('configs')[$key]); } if ($m->save()) { $changes[] = $set . ' configuration [' . $m->get('key') . '] to [' . $m->get('value') . ']'; if ($verbosity == 2) { CLI::PrintActionStatus(true); } } else { if ($verbosity == 2) { CLI::PrintActionStatus('skip'); } } // Make it available immediately \ConfigHandler::CacheConfig($m); } return sizeof($changes) ? $changes : false; }
/** * Internal function to parse and handle the configs in the component.xml file. * This is used for installations and upgrades. * * Returns false if nothing changed, else will return an int of the number of configuration options changed. * * @param boolean $install Set to false to force uninstall/disable mode. * @param int $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output. * * @return boolean | int * @throws InstallerException */ public function _parseConfigs($install = true, $verbosity = 0) { // Keep track of if this changed anything. $changes = array(); $action = $install ? 'Installing' : 'Uninstalling'; $set = $install ? 'Set' : 'Removed'; Core\Utilities\Logger\write_debug($action . ' configs for ' . $this->getName()); // I need to get the schema definitions first. $node = $this->_xmlloader->getElement('configs'); //$prefix = $node->getAttribute('prefix'); $componentName = $this->getKeyName(); // Now, get every table under this node. foreach ($node->getElementsByTagName('config') as $confignode) { /** @var DOMElement $confignode */ $key = $confignode->getAttribute('key'); $options = $confignode->getAttribute('options'); $type = $confignode->getAttribute('type'); $default = $confignode->getAttribute('default'); $title = $confignode->getAttribute('title'); $description = $confignode->getAttribute('description'); $mapto = $confignode->getAttribute('mapto'); $encrypted = $confignode->getAttribute('encrypted'); $formAtts = $confignode->getAttribute('form-attributes'); if($encrypted === null || $encrypted === '') $encrypted = '0'; // Default if omitted. if(!$type) $type = 'string'; if($verbosity == 2){ CLI::PrintActionStart($action . ' config ' . $key); } $m = ConfigHandler::GetConfig($key); if($install){ // Installation/Upgrade Logic $m->set('options', $options); $m->set('type', $type); $m->set('default_value', $default); $m->set('title', $title); $m->set('description', $description); $m->set('mapto', $mapto); $m->set('encrypted', $encrypted); $m->set('form_attributes', $formAtts); $m->set('component', $componentName); // Default from the xml, only if it's not already set. if ($m->get('value') === null || !$m->exists()){ $m->set('value', $confignode->getAttribute('default')); } // Allow configurations to overwrite any value. This is useful on the initial installation. if(\Core\Session::Get('configs/' . $key) !== null){ $m->set('value', \Core\Session::Get('configs/' . $key)); } if ($m->save()){ $changes[] = $set . ' configuration [' . $m->get('key') . '] to [' . $m->get('value') . ']'; if($verbosity == 2){ CLI::PrintActionStatus(true); } } else{ if($verbosity == 2){ CLI::PrintActionStatus('skip'); } } // Make it available immediately ConfigHandler::CacheConfig($m); } else{ // Uninstallation Logic $m->delete(); $changes[] = $set . ' configuration [' . $key . ']'; if($verbosity == 2){ CLI::PrintActionStatus(true); } } } return (sizeof($changes)) ? $changes : false; } // private function _parseConfigs