protected static function reinstall($site_module_file, $restart) { I2CE::raiseError("Beginning re-intiaizliation of site to new file {$site_module_file}"); //we have at one point installed the system, however we changed //the config file that we are using or the name of the module we are using // we need to update the system starting with the site module $config = I2CE::getConfig(); $site_module = ''; $config->setIfIsSet($site_module, '/config/site/module'); $mod_factory = I2CE_ModuleFactory::instance(); $previous_site_file = ''; $config->setIfIsSet($previous_site_file, '/config/data/' . $site_module . '/file'); $installed = ''; I2CE::longExecution(); $mod_factory = I2CE_ModuleFactory::instance(); $tmp_config = I2CE_MagicData::instance("temp_ReInit"); I2CE::getFileSearch()->addPath('MODULES', dirname(dirname(__FILE__)), 'EVEN_HIGHER'); $configurator = new I2CE_Configurator($tmp_config, false); $site_module_config_file_path = '/config/data/' . $site_module . '/file'; unset($config->{$site_module_config_file_path}); $new_site_module = $configurator->processConfigFile($site_module_file, true, false, true); I2CE::raiseError("Reinitializing: " . $new_site_module); if (!(is_string($new_site_module) && strlen($new_site_module) > 0)) { I2CE::raiseError("Installation Failed for site. Invalid configuration file {$site_module_file}. No name given."); return false; } if ($site_module !== $new_site_module) { I2CE::raiseError("You are not permitted to change the site from {$site_module} to {$new_site_module}"); return false; } I2CE::raiseError("Begining re-initializiation of site {$site_module} -- moving config file from {$previous_site_file} to {$site_module_file}"); if ($config->is_parent("/config/data")) { I2CE::raiseError("Erasing all previously found config file locations"); foreach ($config->traverse("/config/data") as $module => $mod_config) { if ($module == $site_module || !$mod_config instanceof I2CE_MagicDataNode) { continue; } $mod_config->__unset("file"); } } $config->{$site_module_config_file_path} = I2CE_FileSearch::relativePath($site_module_file); //make sure we are looking at the correct config file for the site module I2CE::setupFileSearch(array("CLASSES" => "./", 'MODULES' => array(dirname(dirname(__FILE__)), dirname($site_module_file))), true); $mod_factory->resetStoredLoadedPaths(); $configurator->findAvailableConfigs(I2CE::getFileSearch(), true); if (!self::updateOutOfDateConfigFiles()) { //maybe something that wasn't in the site module was changed I2CE::raiseError("Re-installation failed for {$site_module} "); return false; } I2CE::setupFileSearch(); $mod_factory->resetStoredLoadedPaths(); $mod_factory->loadPaths(null, 'CLASSES'); //make sure all of our classes are loaded. $mod_factory->updateHooks(); return true; }
/** * Checks to see if the locales for a given module are up to date * @param string $shortname The module * @param string $file -- defaults to null which means use the currently loaded file location for the config file * @returns booolean. True if all is up to date. */ public function checkLocalesUptoDate($shortname, $file = null) { if ($file == null) { if (!$this->config->setIfIsSet($file, "data/{$shortname}/file")) { return false; // the module has never been loaded } $r_file = I2CE_FileSearch::realPath($file); if (!file_exists($r_file) || !is_readable($r_file)) { return false; // the friggin file does not even exist. why are you asking me? } } else { $r_file = I2CE_FileSearch::realPath($file); if (!$r_file) { return false; //invalid file was set. } if (!$this->config->setIfIsSet($saved_file, "data/{$shortname}/file")) { return false; // the module has never been loaded } if (I2CE_FileSearch::realPath($saved_file) != $r_file) { //the loaded config file is different than the one we are looking at return false; } } $locales = I2CE_Locales::getAvailableLocales(); $dirs = array(); if (!$this->config->setIfIsSet($dirs, "data/{$shortname}/paths/CONFIGS", true)) { return true; } $localized = array(); $this->config->setIfIsSet($localized, "status/localized/{$shortname}", true); $basename = basename($r_file); $dirname = dirname($r_file); //I2CE::raiseError("Checking $shortname in " . implode(',',$dirs) . " for locales " . implode(',',$locales) ); foreach ($dirs as $dir) { foreach ($locales as $locale) { if (I2CE_FileSearch::isAbsolut($dir)) { //the config path in theconfig file is absolut. $t_file = $dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename; $localized_file = I2CE_FileSearch::realPath($t_file); $dir = I2CE_FileSearch::relativePath($dir); } else { //the config path in theconfig file is relative to the module file $t_file = $dirname . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename; $localized_file = I2CE_FileSearch::realPath($t_file); } if (!$localized_file || !is_file($localized_file) || !is_readable($localized_file)) { continue; } if (!array_key_exists($locale, $localized) || !is_array($localized[$locale])) { I2CE::raiseError("Localization data {$locale} for module {$shortname} has never been loaded"); return false; //we have never examined this one before } foreach (array('file', 'mtime', 'hash') as $key) { if (!array_key_exists($key, $localized[$locale])) { return false; } } //we have examined this one before. $l_file = I2CE_FileSearch::realPath($localized[$locale]['file']); if ($localized_file !== $l_file) { return false; } @($mtime = filemtime($localized_file)); if (!$mtime || !$localized[$locale]['mtime']) { return false; } if ($mtime > $localized[$locale]['mtime']) { return false; } $contents = file_get_contents($localized_file); if (!$contents) { return false; } if ($localized[$locale]['hash'] != md5($contents)) { return false; } } } return true; }
public function importLocalizedTemplates($localized = array()) { $imported = array(); $i2ceConfigNodeList = $this->template->query('/I2CEConfiguration'); if ($i2ceConfigNodeList->length != 1) { I2CE::raiseError("No configuration template loaded"); return $imported; } else { $configNode = $i2ceConfigNodeList->item(0); } $shortname = trim($configNode->getAttribute('name')); if (!$shortname) { I2CE::raiseError("Could not find module name"); return $imported; } $config = $this->storage->config->data->{$shortname}; $file = false; $config->setIfIsSet($file, "file"); if (!$file) { I2CE::raiseError("Could not source file"); return $imported; } $dirs = array(); $basedir = dirname($file); $basename = basename($file); $config->setIfIsSet($dirs, "paths/CONFIGS", true); if (!is_array($localized)) { $localized = array(); } foreach ($dirs as $dir) { foreach ($this->locales as $locale) { if (array_key_exists($locale, $imported)) { continue; } if (I2CE_FileSearch::isAbsolut($dir)) { //the config path in theconfig file is absolut. $localized_file = I2CE_FileSearch::realPath($dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename); $dir = I2CE_FileSearch::relativePath($dir); } else { //the config path in theconfig file is relative to the module file $localized_file = I2CE_FileSearch::realPath($basedir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename); } if (!$localized_file || !is_file($localized_file) || !is_readable($localized_file)) { continue; } I2CE::raiseError("Loading {$localized_file}"); $loc_template = new I2CE_MagicDataTemplate(); $loc_template->loadRootFile($localized_file); $loc_node = $loc_template->doc->documentElement; if (!$loc_node instanceof DOMNODE) { continue; } $results = $loc_template->query('./configurationGroup', $loc_node); $localenode = null; if ($results->length == 1) { $localenode = $results->item(0); if ($localenode->getAttribute('locale') !== $locale) { I2CE::raiseError("Locale mismatch on {$localized_file}"); continue; } } $results = $loc_template->query('./metadata/version', $loc_node); if ($results->length != 1) { I2CE::raiseError("No version on {$localized_file}"); continue; } $new_vers = trim($results->item(0)->textContent); if (!array_key_exists($locale, $localized) || !is_array($localized[$locale]) || !array_key_exists('vers', $localized[$locale]) || !is_string($localized[$locale]['vers']) || strlen($localized[$locale]['vers']) == 0) { $old_vers = '0'; } else { $old_vers = $localized[$locale]['vers']; } if ($localenode) { $localenode_imported = $this->template->doc->importNode($localenode, true); I2CE::raiseError("Adding in localizations of {$shortname} in {$locale} to process"); $configNode->appendChild($localenode_imported); } $data = array('file' => I2CE_FileSearch::relativePath($localized_file), 'mtime' => @filemtime($localized_file), 'hash' => md5(file_get_contents($localized_file)), 'old_vers' => $old_vers, 'vers' => $new_vers); $imported[$locale] = $data; } } if (count($imported) > 0) { I2CE::raiseError("Found localized config files for " . $shortname . ": " . implode(',', array_keys($imported))); } return $imported; }