if (!$current->deleted) { $current->deleted = true; $current->timemodified = time(); $stage->add($other); } } $other->clear(); unset($other); } $stage->rebase(); if ($stage->has_component()) { $string->timemodified = local_amos_renderer::commit_datetime($string->timemodified); $msg = <<<EOF Propagating removal of the string The string '{$string->id}' was removed from the English language pack by {$string->extra->userinfo} at {$string->timemodified}. Their commit message was: {$string->extra->commitmsg} {$string->extra->commithash} EOF; fputs(STDOUT, "COMMIT removal of '{$string->id}' from '{$english->name}'\n"); $stage->commit($msg, array('source' => 'revclean', 'userinfo' => 'AMOS-bot <*****@*****.**>'), true); } $stage->clear(); unset($stage); } } } } fputs(STDOUT, date('Y-m-d H:i', time())); fputs(STDOUT, " REVERSE CLEANUP JOB DONE\n");
$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) { if ($string->deleted) { $sign = '-'; } else { $sign = '+'; } echo $sign . ' ' . $string->id . PHP_EOL; } } echo PHP_EOL; $continue = cli_input('Continue? [y/n]', 'n', array('y', 'n')); if ($continue !== 'y') { echo 'Import aborted' . PHP_EOL; exit(5); } $meta = array('source' => 'import', 'userinfo' => $options['userinfo']); if ($options['commithash']) { $meta['commithash'] = $commithash; } $stage->commit($options['message'], $meta, true);
fputs(STDOUT, "!= AMOS GIT DIFF: {$version->dir} [{$amosstring->id},{$frankenstylename}]\n"); $gitstring->clean_text(); $fixcomponent->add_string($gitstring); continue; } } foreach ($gitcomponent->get_iterator() as $gitstring) { $amosstring = $amoscomponent->get_string($gitstring->id); if (is_null($amosstring)) { fputs(STDOUT, ">> GIT ONLY: {$version->dir} [{$gitstring->id},{$frankenstylename}]\n"); $gitstring->clean_text(); $fixcomponent->add_string($gitstring); continue; } } if ($fixcomponent->has_string()) { $stage->add($fixcomponent); } $fixcomponent->clear(); $amoscomponent->clear(); $gitcomponent->clear(); } } if ($options['execute']) { $stage->commit('Fixing the drift between Git and AMOS repository', array('source' => 'fixdrift', 'userinfo' => 'AMOS-bot <*****@*****.**>')); } else { list($x, $y, $z) = mlang_stage::analyze($stage); if ($x > 0) { fputs(STDOUT, "There are {$x} string changes prepared for sync execution\n"); } }
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(); }