示例#1
0
    $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);
        $component->clear();
        unset($component);
    }
    unlink($checkout);
}
// we just parsed the last git commit - let us commit what we have
amos_parse_lang_commit();
fputs(STDOUT, date('Y-m-d H:i', time()));
fputs(STDOUT, " PARSE LANG JOB DONE\n");
示例#2
0
/**
 * 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;
}
示例#3
0
                continue;
            }
            if ($string->deleted) {
                // propagate removal of this string to all other languages where it is present
                $stage = new mlang_stage();
                foreach (array_keys($tree[$vercode]) as $otherlang) {
                    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}
示例#4
0
 }
 // get the most recent snapshot from the git repository
 chdir(AMOS_REPO_MOODLE);
 $gitout = array();
 $gitstatus = 0;
 $gitcmd = AMOS_PATH_GIT . " show {$gitbranch}:{$filepath} 2> /dev/null";
 exec($gitcmd, $gitout, $gitstatus);
 if ($gitstatus == 128) {
     // the $filepath does not exist in the $gitbranch
     if ($amoscomponent->has_string()) {
         fputs(STDERR, "-- '{$filepath}' does not exist in {$gitbranch}\n");
         foreach ($amoscomponent->get_iterator() as $string) {
             $string->deleted = true;
             $string->timemodified = time();
         }
         $stage->add($amoscomponent);
         continue;
     }
     // no string file and nothing in AMOS - that is correct
     continue;
 }
 if ($gitstatus != 0) {
     fputs(STDERR, "FATAL ERROR {$gitstatus} EXECUTING {$gitcmd}\n");
     exit($gitstatus);
 }
 $tmp = make_upload_directory('amos/temp/fix-drift/' . $version->dir);
 $dumpfile = $tmp . '/' . $legacyname . '.php';
 file_put_contents($dumpfile, implode("\n", $gitout));
 $gitcomponent = mlang_component::from_phpfile($dumpfile, 'en', $version, time());
 foreach ($amoscomponent->get_iterator() as $amosstring) {
     $gitstring = $gitcomponent->get_string($amosstring->id);
示例#5
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();
 }
示例#6
0
 /**
  * Migrate help file into a help string if such one does not exist yet
  *
  * This is a temporary method and will be dropped once we have all English helps migrated. It does not do anything
  * yet. It is intended to be run once upon a checkout of 1.9 language files prepared just for this purpose.
  *
  * @param mixed         $helpfile
  * @param mixed         $tostring
  * @param mixed         $tocomponent
  * @param mixed         $timestamp
  * @return mlang_stage
  */
 protected static function migrate_helpfile($version, $helpfile, $tostring, $tocomponent, $timestamp = null)
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/amos/cli/config.php';
     $stage = new mlang_stage();
     foreach (array_keys(self::list_languages(false)) as $lang) {
         $fullpath = AMOS_REPO_LANGS . '/' . $lang . '_utf8/help/' . $helpfile;
         if (!is_readable($fullpath)) {
             continue;
         }
         $helpstring = file_get_contents($fullpath);
         $helpstring = preg_replace('|<h1>.*</h1>|i', '', $helpstring);
         $helpstring = iconv('UTF-8', 'UTF-8//IGNORE', $helpstring);
         $helpstring = trim($helpstring);
         if (empty($helpstring)) {
             continue;
         }
         $to = mlang_component::from_snapshot($tocomponent, $lang, $version, $timestamp, false, false, array($tostring));
         if (!$to->has_string($tostring)) {
             $to->add_string(new mlang_string($tostring, $helpstring, $timestamp));
             $stage->add($to);
         }
         $to->clear();
     }
     return $stage;
 }