/** * Checks the decsep and thousandssep config strings are set correctly * * @link http://tracker.moodle.org/browse/MDL-31332 * @return bool check success flag */ protected function check_decsep_thousandssep() { $details = array(); $langnames = array(); $tree = mlang_tools::components_tree(array('component' => 'langconfig')); foreach ($tree as $branch => $languages) { $version = mlang_version::by_code($branch); foreach (array_keys($languages) as $language) { $langconfig = mlang_component::from_snapshot('langconfig', $language, $version); if ($langname = $langconfig->get_string('thislanguageint')) { $langnames[$language] = $langname->text; } else { $langnames[$language] = $language; } if ($decsep = $langconfig->get_string('decsep')) { $decsep = $decsep->text; } if ($thousandssep = $langconfig->get_string('thousandssep')) { $thousandssep = $thousandssep->text; } if (empty($decsep) and empty($thousandssep)) { $details[$language][$version->label] = 1; } else { if (empty($decsep) or empty($thousandssep)) { $details[$language][$version->label] = 2; } else { if ($decsep === $thousandssep) { $details[$language][$version->label] = 3; } } } } } ksort($details); foreach ($details as $language => $branches) { $msg = sprintf('Invalid decsep and/or thousandssep in %s {%s} at', $langnames[$language], $language); foreach ($branches as $branch => $severity) { $msg .= ' ' . $branch . str_repeat('!', $severity); } $this->output($msg, true); } if (empty($details)) { return 0; } return 1; }
$gitout = array(); $gitstatus = 0; $gitcmd = AMOS_PATH_GIT . " show {$gitbranch}:install/stringnames.txt"; exec($gitcmd, $gitout, $gitstatus); if ($gitstatus != 0) { fputs(STDERR, "ERROR EXECUTING {$gitcmd}\n"); exit($gitstatus); } $list = array(); // [component][stringid] => true foreach ($gitout as $string) { list($stringid, $component) = array_map('trim', explode(',', $string)); $list[$component][$stringid] = true; } unset($gitout); $tree = mlang_tools::components_tree(array('branch' => $version->code)); $langs = array_keys($tree[$version->code]); unset($tree); $phpdoc = <<<EOF /** * Automatically generated strings for Moodle {$version->label} installer * * Do not edit this file manually! It contains just a subset of strings * needed during the very first steps of installation. This file was * generated automatically by export-installer.php (which is part of AMOS * {@link http://docs.moodle.org/dev/Languages/AMOS}) using the * list of strings defined in /install/stringnames.txt. * * @package installer * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */
require_capability('local/amos:commit', get_system_context()); // for langpack maintainers only $PAGE->set_pagelayout('standard'); $PAGE->set_url('/local/amos/merge.php'); navigation_node::override_active_url(new moodle_url('/local/amos/stage.php')); $PAGE->set_title('AMOS ' . get_string('merge', 'local_amos')); $PAGE->set_heading('AMOS ' . get_string('merge', 'local_amos')); $mergeform = new local_amos_merge_form(null, local_amos_merge_options()); if ($data = $mergeform->get_data()) { $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey()); $sourceversion = mlang_version::by_code($data->sourceversion); $targetversion = mlang_version::by_code($data->targetversion); if (is_null($sourceversion) or is_null($targetversion)) { notice('Invalid version selected', new moodle_url('/local/amos/stage.php')); } $tree = mlang_tools::components_tree(array('branch' => $sourceversion->code, 'lang' => $data->language)); $sourcecomponentnames = array_keys(reset(reset($tree))); unset($tree); foreach ($sourcecomponentnames as $sourcecomponentname) { // get a snapshot of both components and merge source into target $sourcecomponent = mlang_component::from_snapshot($sourcecomponentname, $data->language, $sourceversion); $targetcomponent = mlang_component::from_snapshot($sourcecomponent->name, $sourcecomponent->lang, $targetversion); mlang_tools::merge($sourcecomponent, $targetcomponent); $sourcecomponent->clear(); // keep just strings that are defined in english $englishcomponent = mlang_component::from_snapshot($sourcecomponent->name, 'en', $targetversion); $targetcomponent->intersect($englishcomponent); $englishcomponent->clear(); // stage the target $stage->add($targetcomponent); $targetcomponent->clear();
require_login(SITEID, false); require_capability('local/amos:stage', get_system_context()); $PAGE->set_pagelayout('standard'); $PAGE->set_url('/local/amos/diff.php'); navigation_node::override_active_url(new moodle_url('/local/amos/stage.php')); $PAGE->set_title('AMOS ' . get_string('diff', 'local_amos')); $PAGE->set_heading('AMOS ' . get_string('diff', 'local_amos')); $diffform = new local_amos_diff_form(null, local_amos_diff_options()); if ($data = $diffform->get_data()) { if ($data->versiona == $data->versionb) { notice(get_string('nodiffs', 'local_amos'), new moodle_url('/local/amos/stage.php')); } $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey()); $versiona = mlang_version::by_code($data->versiona); $versionb = mlang_version::by_code($data->versionb); $tree = mlang_tools::components_tree(array('branch' => $versiona->code, 'lang' => 'en')); $componentnames = array_keys($tree[$versiona->code]['en']); $total = count($componentnames); unset($tree); echo $OUTPUT->header(); $progressbar = new progress_bar(); $progressbar->create(); // prints the HTML code of the progress bar // we may need a bit of extra execution time and memory here @set_time_limit(HOURSECS); raise_memory_limit(MEMORY_EXTRA); // number of differences $num = 0; foreach ($componentnames as $i => $componentname) { $progressbar->update($i, $total, get_string('diffprogress', 'local_amos')); // the most recent snapshots
* @package local_amos * @copyright 2010 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('CLI_SCRIPT', true); require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'; require_once $CFG->dirroot . '/local/amos/cli/config.php'; require_once $CFG->dirroot . '/local/amos/mlanglib.php'; require_once $CFG->dirroot . '/local/amos/renderer.php'; require_once $CFG->libdir . '/clilib.php'; list($options, $unrecognized) = cli_get_params(array('full' => false), array('f' => 'full')); fputs(STDOUT, "*****************************************\n"); fputs(STDOUT, date('Y-m-d H:i', time())); fputs(STDOUT, " REVERSE CLEANUP JOB STARTED\n"); $mem = memory_get_usage(); $tree = mlang_tools::components_tree(); foreach ($tree as $vercode => $languages) { $version = mlang_version::by_code($vercode); foreach ($languages['en'] as $componentname => $unused) { if ($componentname == 'langconfig') { continue; } $memprev = $mem; $mem = memory_get_usage(); $memdiff = $memprev < $mem ? '+' : '-'; $memdiff = $memdiff . abs($mem - $memprev); $english = mlang_component::from_snapshot($componentname, 'en', $version, null, true, true); foreach ($english->get_iterator() as $string) { if (empty($options['full']) and $string->timemodified < time() - DAYSECS) { continue; }
public function test_components_tree() { // prepare a tree $stage = new mlang_stage(); $components = array(); foreach (array('MOODLE_19_STABLE', 'MOODLE_20_STABLE', 'MOODLE_21_STABLE') as $branch) { foreach (array('en', 'cs', 'es') as $language) { foreach (array('moodle', 'auth_mnet', 'workshop') as $componentname) { $component = new mlang_component($componentname, $language, mlang_version::by_branch($branch)); $component->add_string(new mlang_string('foo', 'Bar')); $stage->add($component); $component->clear(); } } } $stage->commit('Committing test strings'); // full tree $tree = mlang_tools::components_tree(); $this->assertIsA($tree, 'array'); $this->assertEqual(3, count($tree)); // 3 versions $this->assertEqual(3, count($tree[1900])); // 3 languages $this->assertEqual(3, count($tree[2000])); // 3 languages $this->assertEqual(3, count($tree[2100])); // 3 languages $this->assertEqual(3, count($tree[1900]['cs'])); // 3 components $this->assertEqual(3, count($tree[2000]['en'])); // 3 components $this->assertEqual(3, count($tree[2100]['es'])); // 3 components $this->assertEqual(1, $tree[2100]['es']['moodle']); // 1 string // empty trees $tree = mlang_tools::components_tree(array('branch' => 1800)); $this->assertIsA($tree, 'array'); $this->assertTrue(empty($tree)); $tree = mlang_tools::components_tree(array('component' => 'book')); $this->assertIsA($tree, 'array'); $this->assertTrue(empty($tree)); // single value filter $tree = mlang_tools::components_tree(array('branch' => 2000, 'lang' => 'cs')); $this->assertIsA($tree, 'array'); $this->assertEqual(1, count($tree)); $this->assertEqual(1, count($tree[2000])); $this->assertEqual(3, count($tree[2000]['cs'])); $this->assertEqual(1, $tree[2000]['cs']['workshop']); // yet another single value filter $tree = mlang_tools::components_tree(array('component' => 'auth_mnet')); $this->assertEqual(3, count($tree)); $this->assertEqual(3, count($tree[1900])); $this->assertEqual(3, count($tree[2000])); $this->assertEqual(3, count($tree[2100])); $this->assertEqual(1, count($tree[1900]['cs'])); $this->assertEqual(1, count($tree[2000]['en'])); $this->assertEqual(1, count($tree[2100]['es'])); $this->assertEqual(1, $tree[2100]['en']['auth_mnet']); // multivalues filter $tree = mlang_tools::components_tree(array('branch' => array(2000, 2100), 'lang' => array('en'), 'component' => array('moodle', 'workshop'))); $this->assertEqual(2, count($tree)); $this->assertEqual(1, count($tree[2000])); $this->assertEqual(1, count($tree[2100])); $this->assertEqual(2, count($tree[2000]['en'])); $this->assertEqual(2, count($tree[2100]['en'])); $this->assertEqual(1, $tree[2000]['en']['moodle']); $this->assertEqual(1, $tree[2000]['en']['workshop']); $this->assertEqual(1, $tree[2100]['en']['moodle']); $this->assertEqual(1, $tree[2100]['en']['workshop']); }