Commit 3412b12c authored by Damyon Wiese's avatar Damyon Wiese
Browse files

MDL-61041 assign: Remove assignment 2.2 upgrader

parent 0180369b
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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
*/
define('NO_OUTPUT_BUFFERING', true);
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentstable.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentsbatchform.php');
require_sesskey();
// This calls require_login and checks moodle/site:config.
admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('batchupgrade'));
$PAGE->set_pagelayout('maintenance');
$PAGE->navbar->add(get_string('batchupgrade', 'tool_assignmentupgrade'));
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
$confirm = required_param('confirm', PARAM_BOOL);
if (!$confirm) {
print_error('invalidrequest');
die();
}
raise_memory_limit(MEMORY_EXTRA);
// Release session.
\core\session\manager::write_close();
echo $renderer->header();
echo $renderer->heading(get_string('batchupgrade', 'tool_assignmentupgrade'));
$current = 0;
if (optional_param('upgradeall', false, PARAM_BOOL)) {
$assignmentids = tool_assignmentupgrade_load_all_upgradable_assignmentids();
} else {
$assignmentids = explode(',', optional_param('selected', '', PARAM_TEXT));
}
$total = count($assignmentids);
foreach ($assignmentids as $assignmentid) {
list($summary, $success, $log) = tool_assignmentupgrade_upgrade_assignment($assignmentid);
$current += 1;
$params = array('current'=>$current, 'total'=>$total);
echo $renderer->heading(get_string('upgradeprogress', 'tool_assignmentupgrade', $params), 3);
echo $renderer->convert_assignment_result($summary, $success, $log);
}
echo $renderer->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
echo $renderer->footer();
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
/**
* Privacy Subsystem implementation for tool_assignmentupgrade.
*
* @package tool_assignmentupgrade
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_assignmentupgrade\privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\writer;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for tool_assignmentupgrade implementing metadata, plugin, and user_preference providers.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\user_preference_provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection) : collection {
$collection->add_user_preference(
'tool_assignmentupgrade_perpage',
'privacy:metadata:preference:perpage'
);
return $collection;
}
/**
* Export all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$perpage = get_user_preferences('tool_assignmentupgrade_perpage', null, $userid);
if ($perpage !== null) {
writer::export_user_preference(
'tool_assignmentupgrade',
'perpage',
$perpage,
get_string('privacy:metadata:preference:perpage', 'tool_assignmentupgrade')
);
}
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
/**
* This tool can upgrade old assignment activities to the new assignment activity type
*
* The upgrade can be done on any old assignment instance providing it is using one of the core
* assignment subtypes (online text, single upload, etc).
* The new assignment module was introduced in Moodle 2.3 and although it completely reproduces
* the features of the existing assignment type it wasn't designed to replace it entirely as there
* are many custom assignment types people use and it wouldn't be practical to try to convert them.
* Instead the existing assignment type will be left in core and people will be encouraged to
* use the new assignment type.
*
* This screen is the main entry-point to the plugin, it gives the admin a list
* of options available to them.
*
* @package tool_assignmentupgrade
* @copyright 2012 NetSpot
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
// This calls require_login and checks moodle/site:config.
admin_externalpage_setup('assignmentupgrade');
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
$actions = array();
$header = get_string('pluginname', 'tool_assignmentupgrade');
$actions[] = tool_assignmentupgrade_action::make('listnotupgraded');
echo $renderer->index_page($header, $actions);
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
/**
* Strings for the assignment upgrade tool
*
* @package tool_assignmentupgrade
* @copyright 2012 NetSpot
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['areyousure'] = 'Are you sure?';
$string['areyousuremessage'] = 'Are you sure you want to upgrade the assignment "{$a->name}"?';
$string['assignmentid'] = 'Assignment ID';
$string['assignmentnotfound'] = 'Assignment could not be found (id={$a})';
$string['assignmentsperpage'] = 'Assignments per page';
$string['assignmenttype'] = 'Assignment type';
$string['backtoindex'] = 'Back to index';
$string['batchoperations'] = 'Batch operations';
$string['batchupgrade'] = 'Upgrade multiple assignments';
$string['confirmbatchupgrade'] = 'Confirm batch upgrade assignments';
$string['conversioncomplete'] = 'Assignment converted';
$string['conversionfailed'] = 'The assignment conversion was not successful. The log from the upgrade was: <br />{$a}';
$string['listnotupgraded'] = 'List assignments that have not been upgraded';
$string['listnotupgraded_desc'] = 'You can upgrade individual assignments from here';
$string['noassignmentsselected'] = 'No assignments selected';
$string['noassignmentstoupgrade'] = 'There are no assignments that require upgrading';
$string['notsupported'] = '';
$string['notupgradedintro'] = 'This page lists the assignments created with an older version of Moodle that have not been upgraded to the new assignment module in Moodle 2.3. Not all assignments can be upgraded - if they were created with a custom assignment subtype, then that subtype will need to be upgraded to the new assignment plugin format in order to complete the upgrade.';
$string['notupgradedtitle'] = 'Assignments not upgraded';
$string['pluginname'] = 'Assignment upgrade helper';
$string['select'] = 'Select';
$string['submissions'] = 'Submissions';
$string['supported'] = 'Upgrade';
$string['updatetable'] = 'Update table';
$string['unknown'] = 'Unknown';
$string['upgradeassignmentsummary'] = 'Upgrade assignment: {$a->name} (Course: {$a->shortname})';
$string['upgradeassignmentsuccess'] = 'Result: Upgrade successful';
$string['upgradeassignmentfailed'] = 'Result: Upgrade failed. The log from the upgrade was: <br/><div class="tool_assignmentupgrade_upgradelog">{$a->log}</div>';
$string['upgradable'] = 'Upgradable';
$string['upgradeselected'] = 'Upgrade selected assignments';
$string['upgradeselectedcount'] = 'Upgrade {$a} selected assignments?';
$string['upgradeall'] = 'Upgrade all assignments';
$string['upgradeallconfirm'] = 'Upgrade all assignments?';
$string['upgradeprogress'] = 'Upgrade assignment {$a->current} of {$a->total}';
$string['upgradesingle'] = 'Upgrade single assignment';
$string['viewcourse'] = 'View the course with the converted assignment';
$string['privacy:metadata:preference:perpage'] = 'The assignment upgrade records per page preference set for the user.';
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentstable.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentsbatchform.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/paginationform.php');
// This calls require_login and checks moodle/site:config.
admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('listnotupgraded'));
$PAGE->navbar->add(get_string('listnotupgraded', 'tool_assignmentupgrade'));
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
$perpage = optional_param('perpage', 0, PARAM_INT);
if (!$perpage) {
$perpage = get_user_preferences('tool_assignmentupgrade_perpage', 100);
} else {
set_user_preference('tool_assignmentupgrade_perpage', $perpage);
}
$assignments = new tool_assignmentupgrade_assignments_table($perpage);
$batchform = new tool_assignmentupgrade_batchoperations_form();
$data = $batchform->get_data();
if ($data && $data->selectedassignments != '' || $data && isset($data->upgradeall)) {
require_sesskey();
echo $renderer->confirm_batch_operation_page($data);
} else {
$paginationform = new tool_assignmentupgrade_pagination_form();
$pagedata = new stdClass();
$pagedata->perpage = $perpage;
$paginationform->set_data($pagedata);
echo $renderer->assignment_list_page($assignments, $batchform, $paginationform);
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
/**
* Assignment upgrade tool library functions
*
* @package tool_assignmentupgrade
* @copyright 2012 NetSpot
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Get the URL of a script within this plugin.
* @param string $script the script name, without .php. E.g. 'index'
* @param array $params URL parameters (optional)
* @return moodle_url
*/
function tool_assignmentupgrade_url($script, $params = array()) {
return new moodle_url('/admin/tool/assignmentupgrade/' . $script . '.php', $params);
}
/**
* Class to encapsulate the continue / cancel for batch operations
*
* @package tool_assignmentupgrade
* @copyright 2012 NetSpot
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_assignmentupgrade_batchoperationconfirm implements renderable {
/** @var string $continuemessage The message to show above the continue cancel buttons */
public $continuemessage = '';
/** @var string $continueurl The url to load if the user clicks continue */
public $continueurl;
/**
* Constructor for this class
* @param stdClass $data - The data from the previous batch form
*/
public function __construct($data) {
if (isset($data->upgradeselected)) {
$this->continuemessage = get_string('upgradeselectedcount',
'tool_assignmentupgrade',
count(explode(',', $data->selectedassignments)));
$urlparams = array('upgradeselected'=>'1',
'confirm'=>'1',
'sesskey'=>sesskey(),
'selected'=>$data->selectedassignments);
$this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', $urlparams);
} else if (isset($data->upgradeall)) {
if (!tool_assignmentupgrade_any_upgradable_assignments()) {
$this->continuemessage = get_string('noassignmentstoupgrade', 'tool_assignmentupgrade');
$this->continueurl = '';
} else {
$this->continuemessage = get_string('upgradeallconfirm', 'tool_assignmentupgrade');
$urlparams = array('upgradeall'=>'1', 'confirm'=>'1', 'sesskey'=>sesskey());
$this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', $urlparams);
}
}
}
}
/**
* Class to encapsulate one of the functionalities that this plugin offers.
*
* @package tool_assignmentupgrade
* @copyright 2012 NetSpot
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_assignmentupgrade_action {
/** @var string the name of this action. */
public $name;
/** @var moodle_url the URL to launch this action. */
public $url;
/** @var string a description of this aciton. */
public $description;
/**
* Constructor to set the fields.
*
* In order to create a new tool_assignmentupgrade_action instance you must use
* the tool_assignmentupgrade_action::make
* method.
*
* @param string $name the name of this action.
* @param moodle_url $url the URL to launch this action.
* @param string $description a description of this aciton.
*/
protected function __construct($name, moodle_url $url, $description) {
$this->name = $name;
$this->url = $url;
$this->description = $description;
}
/**
* Make an action with standard values.
* @param string $shortname internal name of the action. Used to get strings and build a URL.
* @param array $params any URL params required.
* @return tool_assignmentupgrade_action
*/
public static function make($shortname, $params = array()) {
return new self(
get_string($shortname, 'tool_assignmentupgrade'),
tool_assignmentupgrade_url($shortname, $params),
get_string($shortname . '_desc', 'tool_assignmentupgrade'));
}
}
/**
* Determine if there are any assignments that can be upgraded
* @return boolean - Are there any assignments that can be upgraded
*/
function tool_assignmentupgrade_any_upgradable_assignments() {
global $DB, $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
// First find all the unique assignment types.
$types = $DB->get_records_sql('SELECT plugin AS assignmenttype,
value AS version
FROM {config_plugins}
WHERE
name = ? AND
plugin LIKE ?', array('version', 'assignment_%'));
$upgradabletypes = array();
foreach ($types as $assignment) {
$shorttype = substr($assignment->assignmenttype, strlen('assignment_'));
if (assign::can_upgrade_assignment($shorttype, $assignment->version)) {
$upgradabletypes[] = $shorttype;
}
}
list($sql, $params) = $DB->get_in_or_equal($upgradabletypes);
$count = $DB->count_records_sql('SELECT COUNT(id) FROM {assignment} WHERE assignmenttype ' . $sql, $params);
return $count > 0;
}
/**
* Load a list of all the assignmentids that can be upgraded
* @return array of assignment ids
*/
function tool_assignmentupgrade_load_all_upgradable_assignmentids() {
global $DB, $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
// First find all the unique assignment types.
$types = $DB->get_records_sql('SELECT
plugin AS assignmenttype,
value AS version
FROM {config_plugins}
WHERE
name = ? AND
plugin LIKE ?', array('version', 'assignment_%'));
$upgradabletypes = array();
foreach ($types as $assignment) {
$shorttype = substr($assignment->assignmenttype, strlen('assignment_'));
if (assign::can_upgrade_assignment($shorttype, $assignment->version)) {
$upgradabletypes[] = $shorttype;
}
}
list($sql, $params) = $DB->get_in_or_equal($upgradabletypes);
$records = $DB->get_records_sql('SELECT id from {assignment} where assignmenttype ' . $sql, $params);
$ids = array();
foreach ($records as $record) {
$ids[] = $record->id;
}
return $ids;
}
/**
* 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);
}
/**
* Get the information about a assignment to be upgraded.
* @param int $assignmentid the assignment id.
* @return stdClass the information about that assignment.
*/
function tool_assignmentupgrade_get_assignment($assignmentid) {
global $DB;
return $DB->get_record_sql("
SELECT a.id, a.name, c.shortname, c.id AS courseid
FROM {assignment} a
JOIN {course} c ON c.id = a.course
WHERE a.id = ?", array($assignmentid));
}
M.tool_assignmentupgrade = {
init_upgrade_table: function(Y) {
Y.use('node', function(Y) {
checkboxes = Y.all('td.c0 input');
checkboxes.each(function(node) {
node.on('change', function(e) {
rowelement = e.currentTarget.get('parentNode').get('parentNode');
if (e.currentTarget.get('checked')) {
rowelement.setAttribute('class', 'selectedrow');
} else {
rowelement.setAttribute('class', 'unselectedrow');
}
});
rowelement = node.get('parentNode').get('parentNode');
if (node.get('checked')) {
rowelement.setAttribute('class', 'selectedrow');
} else {
rowelement.setAttribute('class', 'unselectedrow');
}
});
});
var selectall = Y.one('th.c0 input');
selectall.on('change', function(e) {
if (e.currentTarget.get('checked')) {
checkboxes = Y.all('td.c0 input');
checkboxes.each(function(node) {
rowelement = node.get('parentNode').get('parentNode');
node.set('checked', true);
rowelement.setAttribute('class', 'selectedrow');
});
} else {
checkboxes = Y.all('td.c0 input');
checkboxes.each(function(node) {
rowelement = node.get('parentNode').get('parentNode');
node.set('checked', false);
rowelement.setAttribute('class', 'unselectedrow');
});
}
});
var upgradeselectedbutton = Y.one('#id_upgradeselected');
upgradeselectedbutton.on('click', function(e) {