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");
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(); }