function setUp() { parent::setup(); self::$config = I2CE_MagicData::instance("config"); self::$store_sysv = new I2CE_MagicDataStorageSysV("ManageFlying_config"); self::$config->addStorage(self::$store_sysv); }
/** * Gets the storage options for the given form. * Since this is the cached version for this form then * we don't want to use any options set for that and * use what's needed for the cached tables. * @param string $form * @return I2CE_MagicDataNode */ protected function getStorageOptions($form) { if (!is_scalar($form)) { I2CE::raiseError("Bad call to get storage options for {$form}"); return false; } $config = I2CE_MagicData::instance("temp_Module_CachedForm_storage_options"); $config->table = I2CE_CachedForm::getCachedTableName($form); if ($this->preserve_ids) { $config->id->form_prepended = 0; } else { $config->id->form_prepended = 1; } return $config; }
/** * Public set the more storage options for a given form * @param string $form * @param mixed $storageOptions. Either a I2CE_MagicDataNode or an array. */ public function setStorageOptions($form, $storageOptions) { if (array_key_exists($form, $this->storage_options_cache)) { unset($this->storage_options_cache[$form]); } if (!is_string($form) || strlen($form) == 0) { I2CE::raiseError("Invlaid form"); return false; } if (is_array($storageOptions)) { $tmp_storageOptions = I2CE_MagicData::instance("temp_form_storage_options_" . $form); $tmp_storageOptions->setValue($storageOptions); $this->storage_options_cache[$form] = $tmp_storageOptions; } else { if ($storageOptions instanceof I2CE_MagicDataNode) { $this->storage_options_cache[$form] = $storageOptions; } else { I2CE::raiseError("Invalid storage options"); return false; } } return true; }
$h3_list = $template->query('preceding::h3[1]', $li); if ($h3_list->length == 1) { //check to see if preceeding h2 is same as current category $h2_list = $template->query('preceding::h2[1]', $h3_list->item(0)); if ($h2_list->length == 1 && $h2_list->item(0)->textContent == $qry['category']) { $qry['subcategory'] = $h3_list->item(0)->textContent; } } $mods = $template->query("ancestor-or-self::*[@type='module'][1]", $li); if ($mods->length == 1 && ($mod = $mods->item(0)->getAttribute('name'))) { $qry['mods'] = $mod; } $qry['text'] = $a->textContent; $data[$type] = $qry; } $list_storage = I2CE_MagicData::instance("temp_lists"); $list_storage->modules->Lists->auto_list = $data; foreach ($list_storage->modules->Lists->auto_list as $type => $listConfig) { $listConfig->traverse('text', true, false)->setTranslatable(); } I2CE::setupFileSearch(array('XML' => array(dirname(dirname(__FILE__) . "/../modules/MagicDataExport/xml/export_magicdata.xml")))); echo $list_storage; $export = new I2CE_MagicDataExport_Template(); $export->loadRootFile(dirname(dirname(__FILE__) . "/../modules/MagicDataExport/xml/export_magicdata.xml") . "/export_magicdata.xml"); $configNodes = $export->query('/I2CEConfiguration/configurationGroup'); $configNode = $configNodes->item(0); $configNode->setAttribute('name', 'auto_list'); $configNode->setAttribute('path', '/modules/Lists/auto_list'); $export->createExport($configNode, $list_storage->modules->Lists->auto_list); foreach ($export->query('//displayName', $configNode) as $dp) { $dp->parentNode->removeChild($dp);
} getAvailableModules(); 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;
protected function loadMDTemplate($doc, $transform = false, $erase = false) { //doc is either a file name or a DOMDocument if ($transform) { //transform if (is_string($doc)) { $file = $doc; $doc = new DOMDocument(); if (!($contents = file_get_contents($file))) { $this->userMessage("Could not load source file"); return false; } if (!$doc->loadXML($contents)) { $this->userMessage("Could not load file source contents"); return false; } } if (!$doc instanceof DOMDocument) { $this->userMessage("Could not load xml into document"); return false; } $proc = new XSLTProcessor(); $xslt_doc = new DOMDocument(); if (!$xslt_doc->loadXML($transform)) { $this->userMessage("Could not load transform: " . $_FILES['xsl']['name']); return false; } if (!$proc->importStylesheet($xslt_doc)) { $this->userMessage("Could not import style sheet"); return false; } $trans_doc = new DOMDocument('1.0', 'UTF-8'); $trans_doc->appendChild($trans_doc->importNode($doc->documentElement, true)); if (($trans_out = $proc->transformToXML($trans_doc)) === false) { $this->userMessage("Could not transform accoring to xsl"); return false; } } else { $trans_doc = $doc; } if ($trans_doc instanceof DOMDocument) { $temp_file = tempnam(sys_get_temp_dir(), 'MDN_UPLOAD'); if (!file_put_contents($temp_file, $trans_out)) { $this->userMessage("Could not save transformed files"); return false; } } else { $temp_file = $trans_doc; } $template = new I2CE_MagicDataTemplate(); $template->setVerboseErrors(true); if (!$template->loadRootFile($temp_file)) { I2CE::raiseError("Unable to load transformed file as Magic Data"); $this->userMessage("Unable to load transformed file as Magic Data"); return false; } if (!$template->validate()) { I2CE::raiseError("Unable to validate transformed file as Magic Data"); $this->userMessage("Unable to validate transformed file as Magic Data"); return false; } $store = new I2CE_MagicDataStorageMem(); $mem_config = I2CE_MagicData::instance("mdn_load"); $mem_config->addStorage($store); $nodeList = $template->query("/configurationGroup"); if (!$nodeList instanceof DOMNodeList || $nodeList->length == 0) { $nodeList = $template->query("/I2CEConfiguration/configurationGroup"); //perhaps we really need to do something more if this is a module } foreach ($nodeList as $configNode) { $locale = false; $status = $template->getDefaultStatus(); if ($configNode->hasAttribute('locale')) { $locale = $configNode->getAttribute('locale'); } $vers = '0'; if ($template->setConfigValues($configNode, $mem_config, $status, $vers) === false) { I2CE::raiseError("Could not load configuration values"); $this->userMessage("Could not load configuration values"); return false; } } //I2CE::raiseError(print_r($mem_config->getAsArray(),true)); if ($erase) { $this->config->eraseChildren(); } $merges = $template->getMerges(); foreach ($merges as $path => $merge) { if ($this->config->is_scalar($path)) { I2CE::raiseError("Trying to merge arrays into {$path} where target is scalar valued. Skipping"); continue; } if ($mem_config->is_scalar($path)) { I2CE::raiseError("Trying to merge arrays into {$path} where source is scalar valued. Skipping"); continue; } $old_arr = $this->config->getAsArray($path); $new_arr = $mem_config->getAsArray($path); $mem_config->__unset($path); if (!is_array($old_arr)) { //in case the target did not exist $old_arr = array(); } if (!is_array($new_arr)) { //in case no values were set for the source $new_arr = array(); } switch ($merge) { case 'uniquemerge': $new_arr = I2CE_Util::array_unique(array_merge($old_arr, $new_arr)); break; case 'merge': $new_arr = array_merge($old_arr, $new_arr); break; case 'mergerecursive': I2CE_Util::merge_recursive($old_arr, $new_arr); $new_arr = $old_arr; break; } $this->config->__unset($path); $this->config->{$path} = $new_arr; } //we took care of all array merges. anything that is left is an overwrite. foreach ($mem_config as $k => $v) { if (is_scalar($v) && $mem_config->is_translatable($k) && !$this->config->is_parent($k)) { $this->config->setTranslatable($k); $translations = $mem_config->traverse($k, true, false)->getTranslations(); foreach ($translations as $locale => $trans) { if (strlen($trans) == 0) { continue; } $this->config->setTranslation($locale, $trans, $k); } } else { $this->config->{$k}->setValue($v, null, false); } if ($this->config->{$k} instanceof I2CE_MagicDataNode) { //free up some memory. $this->config->{$k}->unpopulate(true); } } return 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:
function testUpdateClassPath() { $config = I2CE_MagicData::instance("config"); $store = new I2CE_MagicDataStorageMem("_Config"); $config->addStorage($store); $datadir = self::data_dir("UpdateClassPath"); $ret = self::$mdt->updateClassPath(); $this->assertEquals(FALSE, $ret); $this->assertContains("Internal Error", self::$errors[0]); $this->assertEquals(array(), self::$not_errors); self::$errors = array(); $ret = self::$mdt->updateClassPath($config); $this->assertEquals(FALSE, $ret); $this->assertContains("Internal Error", self::$errors[0]); $this->assertEquals(array(), self::$not_errors); self::$errors = array(); $ret = self::$mdt->updateClassPath($config, "test"); $this->assertEquals(TRUE, $ret); $this->assertEquals(array(), self::$errors); $this->assertEquals(array(), self::$not_errors); self::$errors = array(); $config->test->class->file = "super"; $ret = self::$mdt->updateClassPath($config, "test"); $this->assertEquals(TRUE, $ret); $this->assertEquals(array(), self::$errors); $this->assertEquals(array(), self::$not_errors); $this->assertTrue(!isset($config->test->class->file)); self::$errors = array(); $config->test->class->name = "NotFound"; $ret = self::$mdt->updateClassPath($config, "test"); $this->assertEquals(FALSE, $ret); $this->assertRegexp("{Class NotFound cannot be found}", self::$errors[0]); $this->assertEquals(array(), self::$not_errors); $this->assertTrue(!isset($config->test->class->file)); self::$errors = array(); /* Not obvious till you dig into the code but without specifying a path for CLASSES, you get ./ which FileSearch->absolut() resolves to the directory of the calling function (from the backtrace. Which, in this case is the I2CE/lib directory. */ $path = dirname(dirname(__FILE__)) . "/lib/I2CE_MagicDataTemplate.php"; $config->test->class->name = "I2CE_MagicDataTemplate"; $ret = self::$mdt->updateClassPath($config, "test"); $this->assertEquals(TRUE, $ret); $this->assertEquals(array(), self::$errors); $this->assertEquals(array(), self::$not_errors); $this->assertEquals($path, $config->test->class->file); self::$errors = array(); $config->test->paths->CLASSES = array("{$datadir}/NoSuch"); $config->test->class->name = "Blah"; $ret = self::$mdt->updateClassPath($config, "test"); $this->assertEquals(FALSE, $ret); $this->assertRegExp("{NoSuch doesn't exist!}", self::$errors[0]); $this->assertEquals(array(), self::$not_errors); $this->assertTrue(!isset($config->test->class->file)); self::$errors = array(); $config->test->paths->CLASSES = array("{$datadir}"); $config->test->class->name = "NotFound"; $ret = self::$mdt->updateClassPath($config, "test"); $this->assertEquals(FALSE, $ret); $this->assertRegexp("{Class NotFound cannot be found in the given " . "class search path: [^ ]+/tests/UpdateClassPath}", self::$errors[0]); $this->assertEquals(array(), self::$not_errors); $this->assertTrue(!isset($config->test->class->file)); self::$errors = array(); $config->test->paths->CLASSES = array("{$datadir}"); $config->test->class->name = "Found"; $ret = self::$mdt->updateClassPath($config, "test"); $this->assertEquals(TRUE, $ret); $this->assertEquals(array(), self::$errors); $this->assertEquals(array(), self::$not_errors); $this->assertEquals("{$datadir}Found.php", $config->test->class->file); self::$errors = array(); }
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; }
/** * Creates the magic data instance. * Sets the mafic data storage mechanisms to be used. * @param boolean $set_config. Defaults to true meaning we set the magic data storage for I2CE * @param boolean $set_config. Defaults to false meaning we dont replace the magic data instance * @returns I2CE_MagicData on success, null on failure */ public static function setupMagicData($set_config = true, $replace = false) { $config_protocol = self::getRuntimeVariable('I2CE_CONFIG_PROTOCOL', 'config_alt'); switch (strtolower($config_protocol)) { case 'mongodb': require_once 'I2CE_MagicDataStorageMongoDB.php'; $config = I2CE_MagicData::instance("config", $replace); $store_mongo = new I2CE_MagicDataStorageMongoDB("config"); if (!$store_mongo->isAvailable()) { I2CE::raiseError("MongoDB config not available. Trying to use original config_alt table"); //the alternative config table has not been created. the config table may be there, so let's try it require_once 'I2CE_MagicDataStorageDBAlt.php'; $store_db = new I2CE_MagicDataStorageDBAlt("config"); if (!$store_db || !$store_db->isAvailable()) { I2CE::raiseError("No persistent caching storage mechanism (apc or memchached) is available. Adding simple memory storage"); require_once 'I2CE_MagicDataStorageMem.php'; $config->addStorage(new I2CE_MagicDataStorageMem()); } else { I2CE::raiseError("Added persistent caching storage mechanism config_alt"); $config->addStorage($store_db); } } else { require_once 'I2CE_MagicDataStorageAPC.php'; $db = MDB2::singleton(); $store_mem = new I2CE_MagicDataStorageAPC($db->database_name . "_config"); if ($store_mem->isAvailable()) { $config->addStorage($store_mem); } } $config->addStorage($store_mongo); //store_mongo may not be available. that's OK on initialization if ($set_config) { self::setConfig($config); } return $config; default: $db = MDB2::singleton(); require_once 'I2CE_MagicDataStorageAPC.php'; require_once 'I2CE_MagicDataStorageDBAlt.php'; $store_db = new I2CE_MagicDataStorageDBAlt("config"); if (!$store_db->isAvailable()) { I2CE::raiseError("Alt config table not available. Trying to use original config table"); //the alternative config table has not been created. the config table may be there, so let's try it require_once 'I2CE_MagicDataStorageDB.php'; $store_db = new I2CE_MagicDataStorageDB("config"); } $config = I2CE_MagicData::instance("config", $replace); $store_mem = new I2CE_MagicDataStorageAPC($db->database_name . "_config"); if ($store_mem->isAvailable()) { $config->addStorage($store_mem); } require_once 'I2CE_MagicDataStorageMemcached.php'; $store_memcached = new I2CE_MagicDataStorageMemcached($db->database_name . '_config'); if ($store_memcached->isAvailable()) { $config->addStorage($store_memcached); } else { I2CE::raiseError("No memcached"); } if (!$store_mem->isAvailable() && !$store_memcached->isAvailable()) { I2CE::raiseError("No persistent caching storage mechanism (apc or memchached) is available. Adding simple memory storage"); require_once 'I2CE_MagicDataStorageMem.php'; $config->addStorage(new I2CE_MagicDataStorageMem()); } $config->addStorage($store_db); //store_dn may not be available. that's OK on initialization if ($set_config) { self::setConfig($config); } return $config; } }
$search_dirs = array(getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . '*'); } $usage[] = "[--modules=\$module1,\$module2..\$moduleN]: The module(s) for which we wish to operate on\n" . "\tIf not specified, it uses every valid module\n"; $usage[] = "[--search_dirs=\$dir1,\$dir2]: Set the search directories for modules\n" . "\tIf not specified, we search " . implode(',', $search_dirs) . "\n"; $usage[] = "[--limit_search=T/F]: Limit the module search results of found sub-modules of a top-level module to those that are real subdirectories of top-level's given directory\n" . "\tDefaults to T.\n"; if (!isset($booleans) || !is_array($booleans)) { $booleans[] = array(); } $booleans['limit_search'] = true; require_once "CLI.php"; require_once "I2CE_MagicData.php"; require_once "I2CE.php"; require_once "I2CE_ModuleFactory.php"; require_once "I2CE_Configurator.php"; require_once "I2CE_FileSearch.php"; $storage = I2CE_MagicData::instance("CLI_application"); I2CE::setConfig($storage); $mod_factory = I2CE_ModuleFactory::instance(); $configurator = new I2CE_Configurator($storage, false); $found_modules = false; function getAvailableModules() { global $configurator; global $modules; global $search_dirs; global $found_modules; global $booleans; if (is_array($found_modules)) { return $found_modules; } $found_modules = array();
$pot_master_out = implode('', $pot_master_out); } $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;
/** * Constructor * * @param I2CE_MagicData $storage -- if none is passed in, * then a simple MagicData and config storage object using * MagicDataStorageMem will be set up. * * @param boolean $set_last_access */ public function __construct($storage = null, $set_last_access = true) { $this->locales = array(I2CE_Locales::DEFAULT_LOCALE); if (null !== $storage) { $this->storage = $storage; } else { $store = new I2CE_MagicDataStorageMem(); $config = I2CE_MagicData::instance("config"); $config->addStorage($store); $this->storage = $config; I2CE::setConfig($config); } $this->resetMerges(); $this->checked_paths = array(); $this->set_last_access = $set_last_access; $this->setRoot(); }