Esempio n. 1
0
     // whole file removal - xxx what can be done? :-/
     continue;
 }
 // dump the given revision of the file to a temporary area
 $checkout = $commithash . '_' . str_replace('/', '_', $file);
 if (in_array($checkout, $MLANG_BROKEN_CHECKOUTS)) {
     fputs(STDERR, "BROKEN {$checkout}\n");
     continue;
 }
 $checkout = $tmp . '/' . $checkout;
 exec(AMOS_PATH_GIT . " show {$commithash}:{$file} > {$checkout}");
 // push the string on all branches where the English original is currently (or has ever been) defined
 // note that all English strings history must already be registered in AMOS repository
 // pushing into Moodle 1.x branches only to prevent conflicts with translations done via web
 foreach (array('MOODLE_19_STABLE') as $branch) {
     $version = mlang_version::by_branch($branch);
     // get the translated strings from PHP file - the lang repository in in 1.x format
     $component = mlang_component::from_phpfile($checkout, $langcode, $version, $timemodified, mlang_component::name_from_filename($file), 1);
     $encomponent = mlang_component::from_snapshot($component->name, 'en', $version, $timemodified);
     // keep just those defined in English on that branch - this is where we are reconstruct branching of lang packs.
     // langconfig.php is not compared with English because it may contain extra string like parentlanguage.
     if ($component->name !== 'langconfig') {
         $component->intersect($encomponent);
     } elseif ($version->code >= mlang_version::MOODLE_20) {
         if ($parentlanguage = $component->get_string('parentlanguage')) {
             if (substr($parentlanguage->text, -5) == '_utf8') {
                 $parentlanguage->text = substr($parentlanguage->text, 0, -5);
             }
         }
     }
     $stage->add($component);
 public function test_php_parser_security_variable_expansion()
 {
     // security issues
     $parser = mlang_parser_factory::get_parser('php');
     $data = '<?php $string[\'dbpass\'] = $CFG->dbpass;';
     // this would give the user sensitive data about AMOS portal
     $component = new mlang_component('test', 'xx', mlang_version::by_branch('MOODLE_20_STABLE'));
     $this->expectException('mlang_parser_exception');
     $parser->parse($data, $component);
 }
Esempio n. 3
0
 public function test_stage_propagate()
 {
     $version20 = mlang_version::by_branch('MOODLE_20_STABLE');
     $version21 = mlang_version::by_branch('MOODLE_21_STABLE');
     $version22 = mlang_version::by_branch('MOODLE_22_STABLE');
     $component20en = new mlang_component('admin', 'en', $version20);
     $component20en->add_string(new mlang_string('foo1', 'Bar1'));
     $component20en->add_string(new mlang_string('foo2', 'Bar2'));
     $component20cs = new mlang_component('admin', 'cs', $version20);
     $component20cs->add_string(new mlang_string('foo1', 'TranslatedOldBar1'));
     $component21en = new mlang_component('admin', 'en', $version21);
     $component21en->add_string(new mlang_string('foo1', 'Bar1'));
     $component21en->add_string(new mlang_string('foo2', 'Bar2'));
     $component21en->add_string(new mlang_string('foo3', 'Bar3'));
     $component22en = new mlang_component('admin', 'en', $version22);
     $component22en->add_string(new mlang_string('foo1', 'Bar1'));
     $component22en->add_string(new mlang_string('foo2', 'Bar2'));
     $component22en->add_string(new mlang_string('foo3', 'NewBar3'));
     $stage = new mlang_stage();
     $stage->add($component20en);
     $stage->add($component20cs);
     $stage->add($component21en);
     $stage->add($component22en);
     $stage->commit('Initial strings', array('source' => 'unittest'), true);
     $component20en->clear();
     $component21en->clear();
     $component22en->clear();
     unset($stage);
     // simple usage - the user translated a string on 2.1 and want it being applied to 2.2, too
     $stage = new mlang_stage();
     $component21cs = new mlang_component('admin', 'cs', $version21);
     $component21cs->add_string(new mlang_string('foo1', 'TranslatedBar1'));
     $stage->add($component21cs);
     $component21cs->clear();
     $this->assertEqual($stage->propagate(array($version22)), 1);
     $propagatedcomponent = $stage->get_component('admin', 'cs', $version22);
     $this->assertNotNull($propagatedcomponent, 'The component "admin" must exist on ' . $version22->label);
     $this->assertTrue($propagatedcomponent->has_string('foo1'));
     $propagatedstring = $propagatedcomponent->get_string('foo1');
     $this->assertTrue($propagatedstring->text, 'TranslatedBar1');
     $stage->clear();
     // the change is not propagated if the changed string is staged several times and the values
     // are different
     $stage = new mlang_stage();
     $component20cs = new mlang_component('admin', 'cs', $version20);
     $component20cs->add_string(new mlang_string('foo2', 'TranslatedOldBar2'));
     $component21cs = new mlang_component('admin', 'cs', $version21);
     $component21cs->add_string(new mlang_string('foo2', 'TranslatedBar2'));
     $stage->add($component20cs);
     $stage->add($component21cs);
     $component20cs->clear();
     $component21cs->clear();
     $this->assertEqual($stage->propagate(array($version20, $version21, $version22)), 0);
     $this->assertEqual($stage->get_component('admin', 'cs', $version20)->get_string('foo2')->text, 'TranslatedOldBar2');
     $this->assertEqual($stage->get_component('admin', 'cs', $version21)->get_string('foo2')->text, 'TranslatedBar2');
     $this->assertNull($stage->get_component('admin', 'cs', $version22));
     $stage->clear();
     // but the change is propagated if the changed string is staged several times and the values
     // are the same
     $stage = new mlang_stage();
     $component20cs = new mlang_component('admin', 'cs', $version20);
     $component20cs->add_string(new mlang_string('foo2', 'TranslatedBar2'));
     $component21cs = new mlang_component('admin', 'cs', $version21);
     $component21cs->add_string(new mlang_string('foo2', 'TranslatedBar2'));
     $stage->add($component20cs);
     $stage->add($component21cs);
     $component20cs->clear();
     $component21cs->clear();
     $this->assertEqual($stage->propagate(array($version20, $version21, $version22)), 1);
     $this->assertEqual($stage->get_component('admin', 'cs', $version22)->get_string('foo2')->text, 'TranslatedBar2');
     $this->assertEqual($stage->get_component('admin', 'cs', $version21)->get_string('foo2')->text, 'TranslatedBar2');
     $this->assertEqual($stage->get_component('admin', 'cs', $version20)->get_string('foo2')->text, 'TranslatedBar2');
     $stage->clear();
     // the staged string is propagated to another branch only if the English originals match
     // in the following test, the 2.1 translation of foo3 should not propagate to neither 2.0
     // (because the string does not exist there) not 2.2 (because the English originals differ)
     $stage = new mlang_stage();
     $component21cs = new mlang_component('admin', 'cs', $version21);
     $component21cs->add_string(new mlang_string('foo3', 'TranslatedBar3'));
     $stage->add($component21cs);
     $component21cs->clear();
     $this->assertEqual($stage->propagate(array($version20, $version21, $version22)), 0);
     $this->assertNull($stage->get_component('admin', 'cs', $version20));
     $this->assertNull($stage->get_component('admin', 'cs', $version22));
     $stage->clear();
 }
Esempio n. 4
0
The file is directly included into the PHP processor. Make sure to review the file
for a malicious contents before you import it via this script.

EOF;
if ($options['help'] or empty($options['message']) or empty($unrecognized)) {
    echo $usage . PHP_EOL;
    exit(1);
}
$filepath = $unrecognized[0];
if (!is_readable($filepath)) {
    echo 'File not readable' . PHP_EOL;
    echo $usage . PHP_EOL;
    exit(2);
}
$version = mlang_version::by_branch($options['version']);
if (is_null($version)) {
    echo 'Invalid version' . PHP_EOL;
    exit(3);
}
$component = mlang_component::from_phpfile($filepath, $options['lang'], $version, $options['timemodified'], $options['name'], (int) $options['format']);
fputs(STDOUT, "{$component->name} {$component->version->label} {$component->lang}" . PHP_EOL);
$stage = new mlang_stage();
$stage->add($component);
$stage->rebase(null, true, $options['timemodified']);
if (!$stage->has_component()) {
    echo 'No strings found (after rebase)' . PHP_EOL;
    exit(4);
}
foreach ($stage->get_iterator() as $component) {
    foreach ($component->get_iterator() as $string) {
Esempio n. 5
0
 * @subpackage amos
 * @copyright  2011 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->libdir . '/clilib.php';
list($options, $unrecognized) = cli_get_params(array('from' => false, 'to' => false, 'help' => false), array('h' => 'help'));
if ($options['help'] or !$options['from'] or !$options['to']) {
    echo 'Usage: ' . basename(__FILE__) . ' --from=MOODLE_XX_STABLE --to=MOODLE_YY_STABLE' . PHP_EOL;
    exit(1);
}
$fromversion = mlang_version::by_branch($options['from']);
$toversion = mlang_version::by_branch($options['to']);
if (is_null($fromversion) or is_null($toversion)) {
    echo 'Unknown branch' . PHP_EOL;
    exit(2);
}
// Make sure that this is not executed by mistake
if ($DB->record_exists('amos_repository', array('branch' => $toversion->code))) {
    echo 'The target branch already exists' . PHP_EOL;
    exit(3);
}
// Let us get the list of commits that change strings on the given branch
$sql = "SELECT DISTINCT commitid\n          FROM {amos_repository}\n         WHERE branch = ?\n      ORDER BY commitid";
$rs = $DB->get_recordset_sql($sql, array($fromversion->code));
foreach ($rs as $record) {
    $commitid = $record->commitid;
    echo 'cloning changes introduced by commit ' . $commitid . ' ... ';