/** * This is a hacky way how to populate a forum at lang.moodle.org with commits into the core * * @param mlang_stage $stage * @param string $commitmsg * @param string $committer * @param string $committeremail * @param string $commithash * @param string $fullcommitmsg * @return void */ function amos_core_commit_notify(mlang_stage $stage, $commitmsg, $committer, $committeremail, $commithash, $fullcommitmsg) { global $CFG; $DB; require_once $CFG->dirroot . '/mod/forum/lib.php'; if ($CFG->wwwroot !== 'http://lang.moodle.org') { // this is intended for lang.moodle.org portal only return; } if (!$stage->has_component()) { // nothing to commit return; } // these are hard-coded values of a forum to inject commit messages into $courseid = 2; // course 'Translating Moodle' $cmid = 7; // forum 'Notification of string changes' $userid = 2; // user 'AMOS bot' $cm = get_coursemodule_from_id('forum', $cmid); $discussion = new stdclass(); $discussion->course = $courseid; $discussion->forum = $cm->instance; $discussion->name = substr(s('[AMOS commit] ' . $commitmsg), 0, 255); $discussion->message = 'Author: ' . $committer . "\n"; $discussion->message .= $fullcommitmsg . "\n\n"; $discussion->message .= 'http://git.moodle.org/gw?p=moodle.git;a=commit;h=' . $commithash . "\n"; $discussion->message .= 'http://github.com/moodle/moodle/commit/' . $commithash . "\n\n"; $standardplugins = local_amos_standard_plugins(); foreach ($stage->get_iterator() as $component) { foreach ($component->get_iterator() as $string) { if ($string->deleted) { $sign = '- '; } else { $sign = '+ '; } if (isset($standardplugins[$component->version->dir][$component->name])) { $name = $standardplugins[$component->version->dir][$component->name]; } else { $name = $component->name; } $discussion->message .= $sign . $component->version->dir . ' en [' . $string->id . ',' . $name . "]\n"; } } $discussion->message = s($discussion->message); $discussion->messageformat = FORMAT_MOODLE; $discussion->messagetrust = 0; $discussion->attachments = null; $discussion->mailnow = 1; $message = null; forum_add_discussion($discussion, null, $message, $userid); }
/** * 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; }
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); }
/** * Rebasing should respect commits in whatever order so it is safe to re-run the import scripts */ public function test_non_chronological_commits() { global $DB; // firstly commit the most recent version $today = time(); $stage = new mlang_stage(); $component = new mlang_component('things', 'en', mlang_version::by_branch('MOODLE_20_STABLE')); $component->add_string(new mlang_string('foo', 'Today Foo', $today)); // changed today $component->add_string(new mlang_string('bar', 'New Bar', $today)); // new today $component->add_string(new mlang_string('job', 'Boring', $today)); // not changed $stage->add($component); $stage->commit('Initial commit', array('source' => 'unittest')); $component->clear(); unset($component); unset($stage); // we are re-importing the history - let us commit the version that was actually created yesterday $yesterday = time() - DAYSECS; $stage = new mlang_stage(); $this->assertFalse($stage->has_component()); $component = new mlang_component('things', 'en', mlang_version::by_branch('MOODLE_20_STABLE')); $component->add_string(new mlang_string('foo', 'Foo', $yesterday)); // as it was yesterday $component->add_string(new mlang_string('job', 'Boring', $yesterday)); // still the same $stage->add($component); $stage->rebase($yesterday, true, $yesterday); $rebased = $stage->get_component('things', 'en', mlang_version::by_branch('MOODLE_20_STABLE')); $this->assertIsA($rebased, 'mlang_component'); $component->clear(); unset($component); unset($stage); $this->assertTrue($rebased->has_string('foo')); $this->assertFalse($rebased->has_string('bar')); $this->assertTrue($rebased->has_string('job')); // and the same case using rebase() without deleting $stage = new mlang_stage(); $this->assertFalse($stage->has_component()); $component = new mlang_component('things', 'en', mlang_version::by_branch('MOODLE_20_STABLE')); $component->add_string(new mlang_string('foo', 'Foo', $yesterday)); // as it was yesterday $component->add_string(new mlang_string('job', 'Boring', $yesterday)); // still the same $stage->add($component); $stage->rebase($yesterday); $rebased = $stage->get_component('things', 'en', mlang_version::by_branch('MOODLE_20_STABLE')); $this->assertIsA($rebased, 'mlang_component'); $component->clear(); unset($component); unset($stage); $this->assertTrue($rebased->has_string('foo')); $this->assertFalse($rebased->has_string('bar')); $this->assertTrue($rebased->has_string('job')); }