/** * AMOS upgrade scripts * * @package local_amos * @copyright 2010 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_local_amos_upgrade($oldversion) { global $CFG, $DB, $OUTPUT; $dbman = $DB->get_manager(); $result = true; if ($oldversion < 2010090103) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/local/amos/db/install.xml', 'amos_stashes'); upgrade_plugin_savepoint(true, 2010090103, 'local', 'amos'); } if ($oldversion < 2010090107) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/local/amos/db/install.xml', 'amos_hidden_requests'); upgrade_plugin_savepoint(true, 2010090107, 'local', 'amos'); } if ($oldversion < 2010110400) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/local/amos/db/install.xml', 'amos_greylist'); upgrade_plugin_savepoint(true, 2010110400, 'local', 'amos'); } if ($oldversion < 2011010600) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/local/amos/db/install.xml', 'amos_contributions'); upgrade_plugin_savepoint(true, 2011010600, 'local', 'amos'); } if ($oldversion < 2011011000) { require_once dirname(dirname(__FILE__)) . '/mlanglib.php'; // convert legacy stashes that were pull-requested $stashids = $DB->get_records('amos_stashes', array('pullrequest' => 1), 'timemodified ASC', 'id'); foreach ($stashids as $stashrecord) { $stash = mlang_stash::instance_from_id($stashrecord->id); // split the stashed components into separate packages by their language $stage = new mlang_stage(); $langstages = array(); // (string)langcode => (mlang_stage) $stash->apply($stage); foreach ($stage->get_iterator() as $component) { $lang = $component->lang; if (!isset($langstages[$lang])) { $langstages[$lang] = new mlang_stage(); } $langstages[$lang]->add($component); } $stage->clear(); unset($stage); // create new contribution record for every language and attach a new stash to it foreach ($langstages as $lang => $stage) { if (!$stage->has_component()) { // this should not happen, but... continue; } $copy = new mlang_stage(); foreach ($stage->get_iterator() as $component) { $copy->add($component); } $copy->rebase(); if ($copy->has_component()) { $tostatus = 0; // new } else { $tostatus = 30; // nothing left after rebase - consider it accepted } $langstash = mlang_stash::instance_from_stage($stage, 0, $stash->name); $langstash->message = $stash->message; $langstash->push(); $contribution = new stdClass(); $contribution->authorid = $stash->ownerid; $contribution->lang = $lang; $contribution->assignee = null; $contribution->subject = $stash->name; $contribution->message = $stash->message; $contribution->stashid = $langstash->id; $contribution->status = $tostatus; $contribution->timecreated = $stash->timemodified; $contribution->timemodified = null; $contribution->id = $DB->insert_record('amos_contributions', $contribution); // add a comment there $comment = new stdClass(); $comment->contextid = SITEID; $comment->commentarea = 'amos_contribution'; $comment->itemid = $contribution->id; $comment->content = 'This contribution was automatically created during the conversion of legacy pull-requested stashes.'; $comment->format = 0; $comment->userid = 2; $comment->timecreated = time(); $DB->insert_record('comments', $comment); } $stash->drop(); } upgrade_plugin_savepoint(true, 2011011000, 'local', 'amos'); } if ($oldversion < 2011011001) { $table = new xmldb_table('amos_stashes'); $field = new xmldb_field('shared'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } $field = new xmldb_field('pullrequest'); if ($dbman->field_exists($table, $field)) { $dbman->drop_field($table, $field); } $table = new xmldb_table('amos_hidden_requests'); if ($dbman->table_exists($table)) { $dbman->drop_table($table); } upgrade_plugin_savepoint(true, 2011011001, 'local', 'amos'); } return $result; }
$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) { if ($string->deleted) { $sign = '-'; } else { $sign = '+'; } echo $sign . ' ' . $string->id . PHP_EOL; } } echo PHP_EOL;
if ($otherlang == 'en') { continue; } $other = mlang_component::from_snapshot($componentname, $otherlang, $version, null, true, false, array($string->id)); if ($other->has_string($string->id)) { $current = $other->get_string($string->id); 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);
public function test_execution_strings_move() { $stage = new mlang_stage(); $version = mlang_version::by_branch('MOODLE_20_STABLE'); $now = time(); // this block emulates parse-core.php $component = new mlang_component('admin', 'en', $version); $component->add_string(new mlang_string('configsitepolicy', 'OLD', $now - 2)); $stage->add($component); $stage->rebase($now - 2, true, $now - 2); $stage->commit('Committed initial English string', array('source' => 'unittest'), true, $now - 2); $component->clear(); unset($component); // this block emulates parse-lang.php $component = new mlang_component('admin', 'cs', $version); $component->add_string(new mlang_string('configsitepolicy', 'OLD in cs', $now - 1)); $stage->add($component); $stage->rebase(); $stage->commit('Committed initial Czech translation', array('source' => 'unittest'), true, $now - 1); $component->clear(); unset($component); // this block emulates parse-core.php again later // now the string is moved in the English pack by the developer who provides AMOS script in commit message // this happened in b593d49d593ee778f525b4074f5ee7978c5e2960 $component = new mlang_component('admin', 'en', $version); $component->add_string(new mlang_string('sitepolicy_help', 'NEW', $now)); $component->add_string(new mlang_string('configsitepolicy', 'OLD', $now, true)); $commitmsg = 'MDL-24570 multiple sitepolicy fixes + adding new separate guest user policy AMOS BEGIN MOV [configsitepolicy,core_admin],[sitepolicy_help,core_admin] AMOS END'; $stage->add($component); $stage->rebase($now, true, $now); $stage->commit($commitmsg, array('source' => 'unittest'), true, $now); $component->clear(); unset($component); // execute AMOS script if the commit message contains some if ($version->code >= mlang_version::MOODLE_20) { $instructions = mlang_tools::extract_script_from_text($commitmsg); if (!empty($instructions)) { foreach ($instructions as $instruction) { $changes = mlang_tools::execute($instruction, $version, $now); $changes->rebase($now); $changes->commit($commitmsg, array('source' => 'commitscript'), true, $now); unset($changes); } } } // check the results $component = mlang_component::from_snapshot('admin', 'cs', $version, $now); $this->assertTrue($component->has_string('sitepolicy_help')); $this->assertEqual('OLD in cs', $component->get_string('sitepolicy_help')->text); $this->assertEqual(1, $component->get_number_of_strings()); }