/** * Upgrade a single assignment. This is used by both upgrade single and upgrade batch * * @param int $assignmentid - The assignment id to upgrade * @return array(string, boolean, string) - * The array contains * - the assignment summary (returned by tool_assignmentupgrade_get_assignment) * - success * - the upgrade log */ function tool_assignmentupgrade_upgrade_assignment($assignmentid) { global $CFG; require_once $CFG->dirroot . '/mod/assign/upgradelib.php'; $assignment_upgrader = new assign_upgrade_manager(); $info = tool_assignmentupgrade_get_assignment($assignmentid); if ($info) { $log = ''; $success = $assignment_upgrader->upgrade_assignment($assignmentid, $log); } else { $success = false; $log = get_string('assignmentnotfound', 'tool_assignmentupgrade', $assignmentid); $info = new stdClass(); $info->name = get_string('unknown', 'tool_assignmentupgrade'); $info->shortname = get_string('unknown', 'tool_assignmentupgrade'); } return array($info, $success, $log); }
// // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Script to show all the assignments that have not been upgraded after the main upgrade. * * @package tool_assignmentupgrade * @copyright 2012 NetSpot * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(__FILE__) . '/../../../config.php'; require_once dirname(__FILE__) . '/locallib.php'; require_once $CFG->libdir . '/adminlib.php'; require_sesskey(); $assignmentid = required_param('id', PARAM_INT); // admin_externalpage_setup calls require_login and checks moodle/site:config admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('upgradesingle', array('id' => $assignmentid))); $PAGE->navbar->add(get_string('upgradesingle', 'tool_assignmentupgrade')); $renderer = $PAGE->get_renderer('tool_assignmentupgrade'); $assignmentinfo = tool_assignmentupgrade_get_assignment($assignmentid); echo $renderer->convert_assignment_are_you_sure($assignmentinfo);
/** * Convert a list of assignments from the old format to the new one. * @param bool $upgradeall - Upgrade all possible assignments * @param array $assignmentids An array of assignment ids to upgrade * @return array of $entry['assignmentsummary' => (result from tool_assignmentupgrade_get_assignment) * $entry['success'] => boolean * $entry['log'] => string - upgrade log */ function tool_assignmentupgrade_upgrade_multiple_assignments($upgradeall, $assignmentids) { global $CFG; require_once $CFG->dirroot . '/mod/assign/locallib.php'; require_once $CFG->dirroot . '/mod/assign/upgradelib.php'; $upgrades = array(); if ($upgradeall) { $assignmentids = tool_assignmentupgrade_load_all_upgradable_assignmentids(); } $assignment_upgrader = new assign_upgrade_manager(); foreach ($assignmentids as $assignmentid) { $info = tool_assignmentupgrade_get_assignment($assignmentid); if ($info) { $log = ''; $success = $assignment_upgrader->upgrade_assignment($assignmentid, $log); } else { $success = false; $log = get_string('assignmentnotfound', 'tool_assignmentupgrade', $assignmentid); $info = new stdClass(); $info->name = get_string('unknown', 'tool_assignmentupgrade'); $info->shortname = get_string('unknown', 'tool_assignmentupgrade'); } $upgrades[] = array('assignmentsummary' => $info, 'success' => $success, 'log' => $log); } return $upgrades; }