if (count($found_modules) == 0) { usage("No modules found"); } $forms = array(); $formClasses = array(); $classMap = array(); foreach ($found_modules as $module => $top) { $file = null; $storage->setIfIsSet($file, "/config/data/{$module}/file"); if (!$file) { echo "No config file for {$module} -- Skipping\n"; continue; } $mod_storage = I2CE_MagicData::instance("tmp_{$module}"); I2CE::setConfig($mod_storage); $mod_configurator = new I2CE_Configurator($mod_storage, false); ob_start(); $s = $mod_configurator->processConfigFile($file, '0', false, false); //process the configGroups but not the meta data. dont show verbose errors. if ($s != $module) { echo "Module mismatch on {$s}!={$module} in {$file}-- Skipping\n"; continue; } if (!$mod_storage->pathExists("/modules/forms/forms") && !$mod_storage->pathExists("/modules/forms/formClasses")) { $mod_configurator->__destruct(); $mod_configurator = null; $mod_storage->erase(); $mod_storage = null; continue; } foreach ($mod_storage->modules->forms->forms as $form => $formData) {
/** * Finds newly available configuration files and stores them in the magic data. * @param mixed $modules a string or array of strings: * the shortnames of modules we wish to look for sub-modules. If null (default), we check all enabled modules. * @return array of string the shortname of any modules we found (old and new) */ public function checkForNewModules($modules = null) { if ($modules !== null) { if (!is_array($modules)) { $modules = array($modules); } $fileSearch = new I2CE_FileSearch(); $this->loadPaths($modules, array('CLASSES', 'MODULES'), true, $fileSearch); //add in the class path and module paths for the new modules } else { $fileSearch = I2CE::getFileSearch(); } require_once 'I2CE_Configurator.php'; //need to explicitly put this in here b/c the system may not be enabled $configurator = new I2CE_Configurator(I2CE::getConfig()); return $configurator->findAvailableConfigs($fileSearch, false, '', true); }
<?php $path_to_i2ce_root = '..'; $path_to_i2ce_root = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . $path_to_i2ce_root) . DIRECTORY_SEPARATOR; require_once $path_to_i2ce_root . 'lib' . DIRECTORY_SEPARATOR . 'I2CE.php'; require_once $path_to_i2ce_root . 'lib' . DIRECTORY_SEPARATOR . 'I2CE_Configurator.php'; require_once $path_to_i2ce_root . 'lib' . DIRECTORY_SEPARATOR . 'I2CE_MagicData.php'; require_once $path_to_i2ce_root . 'lib' . DIRECTORY_SEPARATOR . 'I2CE_FileSearch.php'; require_once "Console/Getopt.php"; $cg = new Console_Getopt(); $args = $cg->readPHPArgv(); $dir = getcwd(); array_shift($args); $config = I2CE_MagicData::instance("check_validity"); I2CE::setConfig($config); foreach ($args as $file) { $file = realpath($file); echo "Checking the validity of {$file}\n"; chdir($path_to_i2ce_root . 'lib'); $config = I2CE_MagicData::instance("config"); $configurator = new I2CE_Configurator($config); if ($configurator->processConfigFile(I2CE_FileSearch::absolut($file), true, true)) { echo "\tThe file {$file} is valid\n"; } chdir($dir); } # Local Variables: # mode: php # c-default-style: "bsd" # indent-tabs-mode: nil # c-basic-offset: 4 # End:
protected static function _updateModules($updates, $removals = array(), $optional_excludes = array(), $disables = array()) { I2CE::raiseError("Updating Modules"); //make sure everything is nice and fresh clearstatcache(); $mod_factory = I2CE_ModuleFactory::instance(); $exec = array('max_execution_time' => 20 * 60, 'memory_limit' => 256 * 1048576); I2CE::longExecution($exec); if (!is_array($updates)) { $updates = array($updates); } if (!is_array($removals)) { $removals = array($removals); } $msg = "Will attempt to update:\n"; foreach (array('Updates' => $updates, 'Removals' => $removals, 'Disables' => $disables) as $k => $v) { if (count($v) > 0) { $msg .= "\t{$k}:\n\t\t" . implode(',', $v) . "\n"; } } I2CE::raiseError($msg); $storage = I2CE::getConfig(); $tmp_storage = I2CE_MagicData::instance("temp_ModuleFactory"); $configurator = new I2CE_Configurator($tmp_storage); if ($storage->setIfIsSet($sitemodule, "config/site/module")) { I2CE::raiseError("Site is set at " . $storage->getPath() . ' to be ' . $sitemodule); //make sure the site direcotry is added in to the config path. $data = $configurator->checkRequirements($updates, $disables, $removals, $mod_factory->getEnabled(), $sitemodule); } else { I2CE::raiseError("Site is not set at " . $storage->getPath()); $data = $configurator->checkRequirements($updates, $disables, $removals, $mod_factory->getEnabled()); } //note that checkRequirements has the result of putting _all_ valid config module metadata under /config/data of $tmp_storage if (isset($data['failure'])) { $storage->clearCache(); I2CE::raiseError("Installation failed: " . $data['failure']); return false; } foreach (array_keys($data['removals']) as $shortname) { if (!$mod_factory->disable($shortname)) { $storage->clearCache(); I2CE::raiseError("Unable to disable {$shortname}", E_USER_NOTICE); return false; } } //now we remove from the requirements list anything that is already enabled and up-to-date if (count($data['moved']) > 0) { I2CE::raiseError("Found the following in another location. Attempting to move:" . implode(',', array_keys($data['moved']))); I2CE::setupFileSearch(array(), true); //reset the file search and clear its cache I2CE::getFileSearch()->addPath('MODULES', dirname(dirname(__FILE__)), 'EVEN_HIGHER'); } $skipped = array(); $moved = array(); foreach ($data['requirements'] as $shortname => $file) { if (!$mod_factory->isEnabled($shortname)) { continue; } if ($mod_factory->isUpToDate($shortname, $file) && $mod_factory->isUpToDateModule($shortname)) { //everything is in the correct place and up to date. $skipped[] = $shortname; $mod_factory->loadPaths($shortname, null, true); //for the loading of all categories for this module $storage->config->data->{$shortname}->file = $data['requirements'][$shortname]; I2CE::raiseError("Updated {$shortname} config file to be " . $data['requirements'][$shortname]); unset($data['requirements'][$shortname]); //this module is enabled and the config is up-to-date so we dont need to do anything continue; } //let us see if this module has been moved if (!$storage->__isset("config/data/{$shortname}")) { continue; } if (!$tmp_storage->__isset("config/data/{$shortname}")) { continue; } $meta = $storage->config->data->{$shortname}; $tmp_meta = $tmp_storage->config->data->{$shortname}; foreach (array("hash", "last_access") as $key) { if (!isset($meta->{$key}) || !isset($tmp_meta->{$key}) || $tmp_meta->{$key} !== $meta->{$key}) { continue 2; } } $class_file = null; $tmp_meta->setIfIsSet($class_file, "class/file"); if ($class_file && ($class_file = I2CE_FileSearch::realPath($class_file))) { if (!$meta->__isset("class/hash")) { continue; } if (!is_readable($class_file)) { continue; } $contents = file_get_contents($class_file); if (!$contents) { continue; } if ($meta->class->hash !== md5($contents)) { continue; } } $mtimes = array(); foreach (array("class/file", "file") as $f) { if (!isset($tmp_meta->{$f})) { continue; } @($mtimes[$f] = filemtime(I2CE_FileSearch::realPath($tmp_meta->{$f}))); if (!$mtimes[$f]) { continue 2; } } if (false == $mod_factory->checkLocalesUpToDate($shortname, $class_file)) { //the locales for this module are not up to date continue; } //we made it here. we can skip the update. I2CE::raiseError("Able to move config file for {$shortname} from:\n " . $meta->file . "\nto:\n " . $tmp_meta->file); foreach (array("class/file" => "class/last_access", "file" => "last_access") as $f => $a) { $val = null; $tmp_meta->setIfIsSet($val, $f); if ($val === null) { continue; } $meta->{$f} = $val; $meta->{$a} = $mtimes[$f]; $tmp_meta->{$a} = $mtimes[$f]; } unset($data['requirements'][$shortname]); //this module is enabled and the config is up-to-date so we dont need to do anything $mod_factory->loadPaths($shortname, null, true); //for the loading of all categories for this module $moved[] = $shortname; } if (count($skipped) > 0) { I2CE::raiseError("Skipping update on the following up-to-date modules:" . implode(',', $skipped)); } if (count($moved) > 0) { I2CE::raiseError("Moved the following modules:" . implode(',', $moved)); } I2CE::raiseError("Attempting to update/enable the following out of date modules: " . implode(',', array_keys($data['requirements']))); //make sure all of our class paths for existing moduels are loaded. $good_modules = array_diff($mod_factory->getEnabled(), $data['removals'], array_keys($data['requirements'])); I2CE::raiseError("The following modules class paths are being added:\n\t" . implode(',', $good_modules)); $mod_factory->loadPaths($good_modules, 'CLASSES', true); if (!array_key_exists('optional', $data) || !is_array($data['optional'])) { $data['optional'] = array(); } if (is_string($optional_excludes)) { $optional_excludes = array($optional_excludes); } if (!is_array($optional_excludes)) { $optional_excludes = array(); } $to_enable = array_merge($data['requirements'], $data['optional']); //while (count ($data['requirements']) > 0) { I2CE::raiseError("Trying to enable the following required:\n" . implode(" ", array_keys($data['requirements']))); I2CE::raiseError("Trying to enable the following optional:\n" . implode(" ", array_keys($data['optional']))); I2CE::raiseError("Trying to enable the following:\n" . implode(" ", array_keys($to_enable))); while (count($to_enable) > 0) { $shortname = key($to_enable); // reset ($data['requirements']); // $shortname = key($data['requirements']); if (!is_string($shortname) || strlen($shortname) == 0) { I2CE::raiseError("Invalid Shortname"); continue; } $file = array_shift($to_enable); if (array_key_exists($shortname, $data['optional']) && in_array($shortname, $optional_excludes)) { continue; } $old_vers = '0'; $storage->setIfIsSet($old_vers, "/config/data/{$shortname}/version"); $new_vers = null; $tmp_storage->setIfIsSet($new_vers, "/config/data/{$shortname}/version"); $mod_config = $tmp_storage->config->data->{$shortname}; $storage->__unset("/config/data/{$shortname}"); //set the module's metadata to the new stuff. $storage->config->data->{$shortname} = $mod_config; //keep the old version set around until we know that the module was upgraded $storage->config->data->{$shortname}->version = $old_vers; if (!$tmp_storage->__isset("/config/data/{$shortname}/class/name")) { //there is no class associated in the new version of this module. if ($storage->__isset("/config/data/{$shortname}/class/name")) { //there was a class previously assoicated to this module -- remove its hooks/fuzzy methods, $mod_factory->removeHooks($shortname); unset($storage->config->data->{$shortname}->class); } } foreach (array('conflict' => 'conflict_external', 'requirement' => 'requirement_external') as $type => $key) { if ($mod_config->is_parent($key)) { foreach ($mod_config->{$key} as $ext => $req_data) { if ($req_data instanceof I2CE_MagicDataNode) { $req_data = $req_data->getAsArray(); } else { $req_data = array(); } foreach ($req_data as $req_d) { if (!is_array($req_d) || !array_key_exists('eval', $req_d) || !$req_d['eval']) { continue; } $eval = null; @eval('$eval = ' . $req_d['eval'] . ';'); if (is_bool($eval) && !$eval) { if (self::failedRequiredUpdate($shortname, $data, "Could not verify external {$type} {$ext} for {$shortname}", $configurator)) { return false; } else { continue 4; } } } } } } $mod_storage = I2CE_MagicData::instance("temp_ModuleFactory_" . $shortname); I2CE::getFileSearch()->addPath('MODULES', dirname(dirname(__FILE__)), 'EVEN_HIGHER'); $r_file = I2CE_FileSearch::realPath($file); $mod_configurator = new I2CE_Configurator($mod_storage); $s = $mod_configurator->processConfigFile($r_file, false, true, true, false); if (!is_string($s)) { if (self::failedRequiredUpdate($shortname, $data, "Could load configuration file", $configurator)) { return false; } else { continue; } } if ($s != $shortname) { //be super safe if (self::failedRequiredUpdate($shortname, $data, "Configuration shortname mismatch ({$s}/{$shortname})", $configurator)) { return false; } else { continue; } } self::processErasers($mod_config, $old_vers); $loaded = self::loadModuleMagicData($shortname, $r_file, $old_vers, $new_vers, $mod_configurator); if ($loaded === false) { if (self::failedRequiredUpdate($shortname, $data, "Could not load magic data", $configurator)) { return false; } else { continue; } } $loaded_mod_config = $mod_storage->config->data->{$shortname}; self::processErasers($loaded_mod_config, $old_vers); if (!self::preUpgradeModule($shortname, $old_vers, $new_vers, $mod_storage)) { if (self::failedRequiredUpdate($shortname, $data, "Could not pre-update module", $configurator)) { return false; } else { continue; } } //if $loaded === true, then there was no magic data to update, so we can skip the store. if (is_array($loaded) && !self::storeModuleMagicData($shortname, $old_vers, $new_vers, $mod_configurator, $loaded)) { if (self::failedRequiredUpdate($shortname, $data, "Could not store magic data", $configurator)) { return false; } else { continue; } } if (!self::upgradeModule($shortname, $old_vers, $new_vers)) { if (self::failedRequiredUpdate($shortname, $data, "Could not upgrade module", $configurator)) { return false; } else { continue; } } if (!self::postUpdateModule($shortname, $old_vers, $new_vers)) { if (self::failedRequiredUpdate($shortname, $data, "Could not post update module", $configurator)) { return false; } else { continue; } } $mod_factory->setModuleHash($shortname); $mod_factory->setModuleClassHash($shortname, false); $mod_configurator->__destruct(); $mod_configurator = null; $mod_storage->erase(); $mod_storage = null; $storage = I2CE::getConfig(); //just to make sure that any upgrades did not change the storage. this happens with i2ce install for example $storage->config->data->{$shortname}->version = $new_vers; //we updated this module. update the permanent modules config data with the temporary $mod_factory->loadPaths($shortname, null, true); //for the loading of all categories for this module } I2CE::raiseError("Enabled Modules: " . implode(',', $mod_factory->getEnabled())); return true; }
} $roles = array(); $tasks = array(); $role_tasks = array(); $task_tasks = array(); if ($do_wiki_task = simple_prompt("Make task and role wiki pages")) { foreach ($found_modules as $module => $top_module) { $current_pkg = false; $current_pkg = $module_packages[$module]; if (!array_key_exists($module, $module_packages)) { I2CE::raiseError("Could not deterine which package {$module} resides in"); //should not happen continue; } $mod_storage = I2CE_MagicData::instance("CLI_application_mod_task_role:{$module}"); $mod_configurator = new I2CE_Configurator($mod_storage, false); if ($module != $mod_configurator->processConfigFile($storage->config->data->{$module}->file, true, false, false)) { I2CE::raiseError("Unable to process config data for {$module}"); return false; } if ($mod_storage->is_parent("/I2CE/formsData/forms/role")) { foreach ($mod_storage->I2CE->formsData->forms->role as $role => $data) { if (!$data->is_parent('fields')) { continue; } if ($data->is_scalar('fields/assignable') && !$data->fields->assignable) { continue; } if (!$data->is_scalar('fields/name')) { continue; }
protected function actionMenu() { I2CE_ModuleFactory::callHooks('pre_admin_menu_modules', array('page' => $this)); $this->template->setBodyId("adminPage"); $config = I2CE::getConfig()->config; $this->template->setAttribute("class", "active", "menuConfigure", "a[@href='configure']"); $this->template->appendFileById("menu_configure.html", "ul", "menuConfigure"); $this->template->setAttribute("class", "active", "menuConfigureModules", "a[@href='admin/modules']"); if ($this->isGet() && $this->get_exists('redirect') && $this->get('redirect')) { $this->template->setDisplayData("redirect", $this->get('redirect')); } $siteModule = ''; $this->mod_factory->checkForNewModules(); //re-read all the module information available to the system $config->setIfIsSet($siteModule, 'site/module'); //now we get the sub-modules of the current module if ($this->isGet() && $this->get_exists('possibles')) { $modules = explode(':', $this->get('possibles')); } else { if ($this->shortname == 'I2CE') { $modules = array(); if ($siteModule) { $modules = $this->mod_factory->checkForNewModules($siteModule); } $t_modules = $this->mod_factory->checkForNewModules('I2CE'); foreach ($t_modules as $module) { if (!in_array($module, $modules)) { $modules[] = $module; } } } else { $modules = $this->mod_factory->checkForNewModules($this->shortname); } } $this->template->addHeaderLink("admin.css"); $this->template->addHeaderLink("mootools-core.js"); $this->template->addHeaderLink("admin.js"); $cats = array(); foreach ($modules as $module) { $dispName = $config->data->{$module}->displayName; if ($dispName != 'I2CE') { $dispName = preg_replace('/^I2CE\\s+/', '', $dispName); } if (isset($config->data->{$module}->category)) { $cats[$config->data->{$module}->category][$module] = $dispName; } else { $cats['UNCATEGORIZED'][$module] = $dispName; } } ksort($cats); $compare = create_function('$m,$n', 'return strcasecmp($m,$n);'); foreach ($cats as $cat => $modules) { uasort($modules, $compare); $cats[$cat] = $modules; } $menuNode = $this->template->addFile("module_menu.html", "div"); $displayData = array('module_link' => 'link', 'module_description' => 'description', 'module_email' => 'email', 'module_email_2' => 'email', 'module_version' => 'version', 'module_creator' => 'creator', 'module_name' => 'displayName'); $possibles = array(); $configurator = new I2CE_Configurator(I2CE::getConfig()); foreach ($cats as $cat => $modList) { $catNode = $this->template->appendFileById("module_category.html", "div", "modules"); if (!$catNode instanceof DOMNode) { continue; } if ($cat != 'UNCATEGORIZED') { $this->template->setDisplayData("module_category", $cat, $catNode); } else { $this->template->setDisplayData("module_category", 'Uncategorized', $catNode); } foreach ($modList as $module => $displayName) { $conflicting = false; $modNode = $this->template->appendFileByName("module_module.html", "li", "module_list", 0, $catNode); if (!$modNode instanceof DOMNode) { continue; } $modNode->setAttribute('id', 'tr_' . $module); $modNode->setAttribute('name', $module); $data = $config->data->{$module}; $origEnableNode = $this->template->getElementByName('module_enable', 0); if ($module == 'I2CE') { $origEnableNode->parentNode->removeChild($origEnableNode); } else { if ($module == $config->site->module) { $origEnableNode->parentNode->removeChild($origEnableNode); } else { $reqs = $configurator->getDependencyList($module); $badness = ''; $origEnableNode->setAttribute('id', $module); if (array_key_exists('badness', $reqs) && !empty($reqs['badness'])) { $badness = $reqs['badness']; if ($this->mod_factory->isEnabled($module)) { $checked = "checked='checked' disabled='disabled'"; //shouldn't be } else { $checked = ' disabled="disabled"'; } $conflicting = true; $modNode->setAttribute('class', 'conflict'); $deps = implode(',', $reqs['requirements']); $optional = implode(',', $reqs['enable']); $conflicts = implode(',', $reqs['conflicts']); $html = " <div class='check' deps='{$deps}' cons='{$conflicts}' opt='{$optional}'>\n <input type='checkbox' name='modules[]' value='{$module}' {$checked} id='input_enable_{$module}' />\n </div>\n"; $origEnableNode->parentNode->replaceChild($this->template->importText($html), $origEnableNode); } else { if ($configurator->moduleRequires($module, $data->version, $config->site->module)) { if ($this->mod_factory->isEnabled($module)) { $checked = "checked='checked'"; } else { $checked = ''; } $deps = implode(',', $reqs['requirements']); $optional = implode(',', $reqs['enable']); $conflicts = implode(',', $reqs['conflicts']); $html = "<div class='check' deps='{$deps}' cons='{$conflicts}' opt='{$optional}'>\n <input type='hidden' name='modules[]' value='{$module}' id='input_enable_{$module}' />\n <input type='checkbox' {$checked} disabled='disabled' value='{$module}' {$checked} ' />\n </div>\n"; $origEnableNode->parentNode->replaceChild($this->template->importText($html), $origEnableNode); } else { if ($configurator->moduleConflicts($module, $data->version, $config->site->module)) { if ($this->mod_factory->isEnabled($module)) { $checked = "checked='checked' disabled='disabled'"; } else { $checked = ' disabled="disabled"'; } $conflicting = true; $modNode->setAttribute('class', 'conflict'); $deps = implode(',', $reqs['requirements']); $optional = implode(',', $reqs['enable']); $conflicts = implode(',', $reqs['conflicts']); $html = " <div class='check' id='{$module}' deps='{$deps}' cons='{$conflicts}' opt='{$optional}'>\n <input type='checkbox' name='modules[]' value='{$module}' {$checked} id='input_enable_{$module}' />\n </div>\n"; $origEnableNode->parentNode->replaceChild($this->template->importText($html), $origEnableNode); } else { if ($this->mod_factory->isEnabled($module)) { $checked = "checked='checked'"; } else { $checked = ''; } $deps = implode(',', $reqs['requirements']); $optional = implode(',', $reqs['enable']); $conflicts = implode(',', $reqs['conflicts']); $html = " <div class='check' id='{$module}' deps='{$deps}' cons='{$conflicts}' opt='{$optional}'>\n <input type='checkbox' name='modules[]' value='{$module}' {$checked} id='input_enable_{$module}' />\n </div>\n"; $origEnableNode->parentNode->replaceChild($this->template->importText($html), $origEnableNode); $possibles[] = $module; } } } } } $display = array(); foreach ($displayData as $name => $dd) { if (isset($data->{$dd})) { $display[$name] = $data->{$dd}; } else { $display[$name] = ''; } } if (!empty($display['module_email'])) { if (!(substr($display['module_email'], 0, 6) == 'mailto')) { $display['module_email'] = 'mailto://' . $display['module_email']; } } $display['module_message'] = ''; foreach ($display as $name => $val) { $this->template->setDisplayData($name, $val, $modNode); } $module_menu = 'admin/modules'; if ($module != 'I2CE') { $module_menu .= '/' . $module; } $module_configure = ''; if (!$conflicting && (!isset($data->noConfigData) || $data->noConfigData != 1) && $this->mod_factory->isInitialized($module) && $this->mod_factory->isEnabled('swissConfig')) { $module_configure = 'swissConfig/edit/' . $module; } $menuLinkNodeList = $this->template->query(".//a[@name='module_menu']", $modNode); if ($menuLinkNodeList->length > 0) { $menuLinkNode = $menuLinkNodeList->item(0); } if ($menuLinkNode instanceof DOMElement) { $menuLinkNode->setAttribute('id', 'menu_link_' . $module); } if (!isset($data->paths->MODULES) || $this->shortname == $module || $conflicting) { $module_menu = ''; } else { if ($this->hasAjax() === true) { $subModNode = $this->template->appendFileByName("module_sub_module.html", "li", "module_list", -1); if ($subModNode instanceof DOMElement) { $subModNode->setAttribute('id', "sub_module_li_{$module}"); } $subModDiv = $this->template->query("./descendant-or-self::node()[@id='sub_module']", $subModNode); if ($subModDiv->length > 0) { $subModDiv = $subModDiv->item(0); } if ($subModDiv instanceof DOMElement) { $subModDiv->setAttribute('id', "sub_module_{$module}"); } $arrowNode = $this->template->createElement('img', array('src' => 'file/admin-arrow-down.gif', 'id' => "menu_link_arrow_{$module}")); $menuLinkNode->parentNode->appendChild($arrowNode); $this->addAjaxUpdate("sub_module_{$module}", "menu_link_arrow_{$module}", 'click', $module_menu, "modules", true); //fuzzy method from stub module $this->addAjaxCompleteFunction("menu_link_arrow_{$module}", "Modules.update(\"{$module}\");"); //fuzzy method from stub module } } $this->template->setDisplayDataImmediate("module_configure", $module_configure, $modNode); $this->template->setDisplayDataImmediate("module_menu", $module_menu, $modNode); } } $possibleNode = $this->template->getElementById('module_possibles', $menuNode); if ($possibleNode instanceof DOMElement) { $possibleNode->setAttribute('value', implode(':', $possibles)); } $formNode = $this->template->getElementByName('admin_enable_form', 0); if ($formNode instanceof DOMElement) { $action = 'admin/enable'; if ($this->shortname != 'I2CE') { $action .= '/' . $this->shortname; } $formNode->setAttribute('action', $action); } I2CE_ModuleFactory::callHooks('post_admin_menu_modules', array('page' => $this, 'possibles' => $possibles)); }