/** * 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; }
$emailsubject = get_string('emailcontributionsubject', 'local_amos'); $emailbody = get_string('emailcontributionbody', 'local_amos', $a); foreach ($maintainers as $maintainer) { email_to_user($maintainer, $amosbot, $emailsubject, $emailbody); } } // stash has been submited so it is dropped $stash->drop(); redirect(new moodle_url('/local/amos/contrib.php')); } $output = $PAGE->get_renderer('local_amos'); /// Output starts here echo $output->header(); if ($submit) { require_sesskey(); $stash = mlang_stash::instance_from_id($submit); if ($stash->ownerid != $USER->id) { print_error('stashaccessdenied', 'local_amos'); die; } echo $output->heading_with_help(get_string('submitting', 'local_amos'), 'submitting', 'local_amos'); $stashinfo = local_amos_stash::instance_from_mlang_stash($stash, $USER); if (empty($stashinfo->strings)) { echo $output->heading(get_string('stagestringsnone', 'local_amos')); echo $output->footer(); die; } echo $output->render($stashinfo); $submitform->set_data(array('name' => s($stash->name), 'stashid' => $stash->id)); $submitform->display(); echo $output->footer();
$maintainerof = false; } $contribution = $DB->get_record('amos_contributions', array('id' => $id), '*', MUST_EXIST); if ($contribution->authorid !== $USER->id) { require_capability('local/amos:commit', get_system_context()); if ($maintainerof !== 'all') { if (!in_array($contribution->lang, $maintainerof)) { print_error('contributionaccessdenied', 'local_amos'); } } $author = $DB->get_record('user', array('id' => $contribution->authorid)); } else { $author = $USER; } // get the contributed components and rebase them to see what would happen $stash = mlang_stash::instance_from_id($contribution->stashid); $stage = new mlang_stage(); $stash->apply($stage); list($origstrings, $origlanguages, $origcomponents) = mlang_stage::analyze($stage); $stage->rebase(); list($rebasedstrings, $rebasedlanguages, $rebasedcomponents) = mlang_stage::analyze($stage); if ($stage->has_component()) { } else { // nothing left after rebase } $contribinfo = new local_amos_contribution($contribution, $author); $contribinfo->language = implode(', ', array_filter(array_map('trim', explode('/', $origlanguages)))); $contribinfo->components = implode(', ', array_filter(array_map('trim', explode('/', $origcomponents)))); $contribinfo->strings = $origstrings; $contribinfo->stringsreb = $rebasedstrings; echo $output->render($contribinfo);