예제 #1
0
 function setUp()
 {
     parent::setUp();
     I2CE::setupFileSearch();
     self::$c = new I2CE_Configurator();
     self::$c->resetCheckedPaths();
 }
예제 #2
0
 function setUp()
 {
     parent::setup();
     I2CE::setupFileSearch();
     $store = new I2CE_MagicDataStorageMem();
     self::$md = TestMagicDataTearDown::instance("config");
     self::$md->addStorage($store);
     I2CE::setConfig(self::$md);
     self::$c = new I2CE_Configurator(self::$md);
     self::$c->resetCheckedPaths();
 }
예제 #3
0
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();
    $bad_modules = array();
    foreach ($search_dirs as $dir) {
        foreach (glob($dir) as $d) {
            $d = realpath($d);
            I2CE::raiseError("Searching {$d}");
            I2CE::setupFileSearch(array('MODULES' => $d));
            $fileSearch = I2CE::getFileSearch();
            $top_module = $configurator->findAvailableConfigs($fileSearch, false);
            if (!is_array($top_module) || count($top_module) != 1) {
                I2CE::raiseError("WARNING:  no top-level module found for {$dir} -- Skipping.");
                continue;
            }
            $top_module = $top_module[0];
            I2CE::raiseError("Found {$top_module} as top-level module for {$d}");
            $searchPath = $fileSearch->getSearchPath('MODULES', true);
            if ($booleans['limit_search']) {
                I2CE::raiseError("Limiting search to {$d}");
                $avail_modules = $configurator->findAvailableConfigs($fileSearch, true, $d);
            } else {
                $avail_modules = $configurator->findAvailableConfigs($fileSearch, true);
            }
            if (is_array($modules)) {
                $avail_modules = array_intersect($modules, $avail_modules);
            }
            foreach ($avail_modules as $m) {
                if (array_key_exists($m, $found_modules)) {
                    I2CE::raiseError("WARNING: conflict with module {$m}.  Found more than once -- Skipping");
                    $found_modules[$m] = false;
                    $bad_modules[] = $m;
                } else {
                    $found_modules[$m] = $top_module;
                }
            }
        }
    }
    foreach ($bad_modules as $m) {
        unset($found_modules[$m]);
    }
    if (count($found_modules) == 0) {
        usage("No modules files found in this directory:\n\t" . implode("\n\t", $search_dirs) . "\n");
    }
    return $found_modules;
}
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 
* received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
* @version 2.1
* @access public
*/
$translations_dir = "translations" . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
$usage[] = "Looks for .pot files in {$translations_dir}\n";
$set_categories = false;
$set_configs = false;
require_once "translate_base.php";
@(require_once "Archive/Tar.php");
if (!class_exists('Archive_Tar')) {
    usage('Please install the PEAR Archive_Tar package');
}
I2CE::setupFileSearch(array('MODULES' => getcwd()));
$fileSearch = I2CE::getFileSearch();
$module = $configurator->findAvailableConfigs($fileSearch, false);
if (count($module) != 1) {
    usage("No Modules Specified");
}
$module = $module[0];
$out_dir = 'translations' . DIRECTORY_SEPARATOR . 'launchpad';
$archive_file = $out_dir . DIRECTORY_SEPARATOR . 'templates-' . $module . '.tgz';
if ($translations_dir[strlen($translations_dir) - 1] == DIRECTORY_SEPARATOR) {
    $translations_dir = substr($translations_dir, 0, -1);
}
if (!is_dir($translations_dir) || !is_readable($translations_dir)) {
    usage("Could not find/read {$translations_dir} directory");
}
if (!is_dir($out_dir)) {
            $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);
    //condense the .xml export
}
foreach ($export->query('//*[@name="category"] | //*[@name="subcategory"] | //*[@name="text"]') as $t) {
    $t->setAttribute('locale', 'en_US');
    //shouldn't have to do this because we set the nodes as translatbale above.  there is a bug in magic data export
예제 #6
0
 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;
 }
예제 #7
0
function getTranslatableDocuments($show_bad = true)
{
    global $categories;
    global $found_modules;
    I2CE::raiseError("Getting Translate-able Documents");
    getAvailableModules();
    I2CE::raiseError("Will attempt to  template files for the following modules:\n\t" . implode(",", array_keys($found_modules)));
    $factory = I2CE_ModuleFactory::instance();
    $templates = array();
    foreach ($found_modules as $module => $top_module) {
        I2CE::setupFileSearch();
        //reset the file search.
        $fileSearch = I2CE::getFileSearch();
        $good_paths = array();
        $bad_paths = array();
        foreach ($categories as $cat) {
            $fileSearch->setPreferredLocales($cat, I2CE_Locales::DEFAULT_LOCALE);
            //only search the en_US locale
            $factory->loadPaths($module, $cat, true, $fileSearch);
            //load all template paths
            $ordered_paths = $fileSearch->getSearchPath($cat, true);
            //get the paths found with their localization;
            if (count($ordered_paths) == 0) {
                //echo "\tNo $cat directories for $module. -- Skipping\n";
                continue;
            }
            foreach ($ordered_paths as $paths) {
                foreach ($paths as $path => $locale) {
                    if ($locale !== I2CE_Locales::DEFAULT_LOCALE) {
                        //should not happen.
                        var_dump($locale);
                        die("Yell at Carl -- you have locale {$locale} instead of " . I2CE_Locales::DEFAULT_LOCALE . "\n");
                    }
                    $dir = basename($path);
                    if ($dir != I2CE_Locales::DEFAULT_LOCALE) {
                        $bad_paths[] = $path;
                    } else {
                        $good_paths[$path] = I2CE_Locales::DEFAULT_LOCALE;
                    }
                }
            }
        }
        if ($show_bad && count($bad_paths) > 0) {
            I2CE::raiseError("The following template paths for {$module} were not localized:\n\t" . implode("\n\t", $bad_paths));
        }
        if (count($good_paths) == 0) {
            //echo "\tNo localized template files for $module -- Skipping\n";
            continue;
        }
        foreach ($good_paths as $path => $locale) {
            $rec_path = $path . DIRECTORY_SEPARATOR . '**';
            //do a recursive search
            $files = $fileSearch->resolve(array('/^.*\\.html?$/'), array($rec_path => I2CE_Locales::DEFAULT_LOCALE), true);
            if (is_array($files) && count($files) > 0) {
                $templates[$module][$path] = $files;
            }
        }
    }
    if (count($templates) == 0) {
        I2CE::raiseError("None of the modules available are setup with localized tempaltes.  Nothing to do.");
    } else {
        I2CE::raiseError("The following modules has translatable templates:\n\t" . implode(",", array_keys($templates)));
    }
    return $templates;
}
예제 #8
0
 ************************/
$template_list = array();
$template_by_mod_list = array();
if ($do_wiki_template = simple_prompt("Make wiki pages related to templates?")) {
    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;
        }
        $len = strlen($packages[$current_pkg]['dir']);
        $priority = 50;
        $storage->setIfIsSet($priority, "/config/data/{$module}/priority");
        I2CE::setupFileSearch();
        //reset the file search.
        $fileSearch = I2CE::getFileSearch();
        $mod_factory->loadPaths($module, 'TEMPLATES', true, $fileSearch);
        //load all template paths
        $results = $fileSearch->findByRegularExpression('TEMPLATES', '/^.*html$/', true);
        //get the paths found with their **=recusrive search
        $files = array();
        $template_by_mod_list[$module] = array();
        foreach ($results as $file) {
            $file = realpath($file);
            $template = basename($file);
            $file_base = ltrim(substr($file, $len), '/');
            $template_by_mod_list[$module][] = "[[iHRIS Template List{$title_append}#{$template} | {$template}]]";
            if (!array_key_exists($template, $template_list)) {
                $template_list[$template] = array();
예제 #9
0
 /**
  * Find the top-level module in a directory.  (e.g. I2CE,
  * ihris-common, ihris-manage)
  *
  * @param string $d Directory to check
  *
  * @param boolean $verbose
  * @return
  */
 public function getTopModule($d, $verbose = false)
 {
     $d = realpath($d);
     if (!array_key_exists($d, $this->top_module)) {
         I2CE::setupFileSearch(array('MODULES' => $d));
         $top_module = $this->findAvailableConfigs(I2CE::getFileSearch(), false, "", $verbose);
         I2CE::getFileSearch()->removePath('MODULES', $d);
         if (!is_array($top_module) || count($top_module) != 1) {
             return false;
         }
         $this->setTopModule($d, $top_module[0]);
     }
     return $this->top_module[$d];
 }
 public function testGetModuleFileMap()
 {
     $dir = self::data_dir(__CLASS__) . "testI2CE/";
     I2CE::setupFileSearch(array('MODULES' => $dir));
     self::$c->setRoot($dir);
     self::$c->findAvailableConfigs(NULL, TRUE, array("xml"), '', TRUE);
     $b = array("BIN" => array("bin/found.php"), 'MODULES' => array("modules/not-found.php"), '' => array("one.xml"));
     $a = self::$c->getModuleFileMap("testI2CE");
     $c = array_merge((array) array_diff($a, $b), (array) array_diff($b, $a));
     $this->assertEquals(array(), $c);
     $this->assertEquals(array(), self::$errors);
     $this->assertEquals(array(), self::$not_errors);
     $this->assertEquals(array(), I2CE::getFileSearch()->getSearchPath('MODULES'));
     $this->assertEquals(array(), self::$errors);
 }