mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-20636 Implement lots of the post-upgrade functionality for the upgrade helper plugin.
This commit is contained in:
parent
d98389ffed
commit
92dcdc88df
@ -620,50 +620,6 @@ function xmldb_local_qedatabase_install() {
|
||||
upgrade_plugin_savepoint(true, 2008000522, 'local', 'qedatabase');
|
||||
}
|
||||
|
||||
// if ($oldversion < 2008000550) {
|
||||
// // Define field needsupgradetonewqe to be added to quiz_attempts
|
||||
// $table = new xmldb_table('quiz_attempts');
|
||||
// $field = new xmldb_field('needsupgradetonewqe');
|
||||
// $field->set_attributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'preview');
|
||||
//
|
||||
// // Launch add field needsupgradetonewqe
|
||||
// if (!field_exists($table, $field)) {
|
||||
// $dbman->add_field($table, $field);
|
||||
// }
|
||||
//
|
||||
// set_field_select('quiz_attempts', 'needsupgradetonewqe', 1, '', '');
|
||||
//
|
||||
// // quiz savepoint reached
|
||||
// upgrade_plugin_savepoint(true, 2008000550, 'local', 'qedatabase');
|
||||
// }
|
||||
|
||||
// if ($oldversion < 2008000551) {
|
||||
// $table = new xmldb_table('question_states');
|
||||
// if ($dbman->table_exists($table)) {
|
||||
// // First delete all data from preview attempts.
|
||||
// delete_records_select('question_states',
|
||||
// "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
|
||||
// delete_records_select('question_sessions',
|
||||
// "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
|
||||
// delete_records('quiz_attempts', 'preview', 1);
|
||||
//
|
||||
// // Now update all the old attempt data.
|
||||
// $db->debug = false;
|
||||
// $oldrcachesetting = $CFG->rcache;
|
||||
// $CFG->rcache = false;
|
||||
//
|
||||
// require_once($CFG->dirroot . '/question/engine/upgradefromoldqe/upgrade.php');
|
||||
// $upgrader = new question_engine_attempt_upgrader();
|
||||
// $upgrader->convert_all_quiz_attempts();
|
||||
//
|
||||
// $CFG->rcache = $oldrcachesetting;
|
||||
// $db->debug = true;
|
||||
// }
|
||||
//
|
||||
// // quiz savepoint reached
|
||||
// upgrade_plugin_savepoint(true, 2008000551, 'local', 'qedatabase');
|
||||
// }
|
||||
|
||||
if ($oldversion < 2008000600) {
|
||||
|
||||
// Define table question_hints to be created
|
||||
|
@ -66,4 +66,47 @@ function xmldb_local_qedatabase_upgrade($oldversion) {
|
||||
// quiz savepoint reached
|
||||
upgrade_plugin_savepoint(true, 2008000704, 'local', 'qedatabase');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008000800) {
|
||||
// Define field needsupgradetonewqe to be added to quiz_attempts
|
||||
$table = new xmldb_table('quiz_attempts');
|
||||
$field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'preview');
|
||||
|
||||
// Launch add field needsupgradetonewqe
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$DB->set_field('quiz_attempts', 'needsupgradetonewqe', 1);
|
||||
|
||||
// quiz savepoint reached
|
||||
upgrade_plugin_savepoint(true, 2008000800, 'local', 'qedatabase');
|
||||
}
|
||||
|
||||
// if ($oldversion < 2008000551) {
|
||||
// $table = new xmldb_table('question_states');
|
||||
// if ($dbman->table_exists($table)) {
|
||||
// // First delete all data from preview attempts.
|
||||
// delete_records_select('question_states',
|
||||
// "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
|
||||
// delete_records_select('question_sessions',
|
||||
// "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
|
||||
// delete_records('quiz_attempts', 'preview', 1);
|
||||
//
|
||||
// // Now update all the old attempt data.
|
||||
// $db->debug = false;
|
||||
// $oldrcachesetting = $CFG->rcache;
|
||||
// $CFG->rcache = false;
|
||||
//
|
||||
// require_once($CFG->dirroot . '/question/engine/upgradefromoldqe/upgrade.php');
|
||||
// $upgrader = new question_engine_attempt_upgrader();
|
||||
// $upgrader->convert_all_quiz_attempts();
|
||||
//
|
||||
// $CFG->rcache = $oldrcachesetting;
|
||||
// $db->debug = true;
|
||||
// }
|
||||
//
|
||||
// // quiz savepoint reached
|
||||
// upgrade_plugin_savepoint(true, 2008000551, 'local', 'qedatabase');
|
||||
// }
|
||||
}
|
||||
|
@ -26,5 +26,5 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2008000704;
|
||||
$plugin->version = 2008000800;
|
||||
$plugin->requires = 2010080300;
|
||||
|
174
local/qeupgradehelper/afterupgradelib.php
Executable file
174
local/qeupgradehelper/afterupgradelib.php
Executable file
@ -0,0 +1,174 @@
|
||||
<?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/>.
|
||||
|
||||
|
||||
/**
|
||||
* Question engine upgrade helper library code that relies on other parts of the
|
||||
* new question engine code.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/upgrade/upgradelib.php');
|
||||
|
||||
|
||||
class local_qeupgradehelper_attempt_upgrader extends question_engine_attempt_upgrader {
|
||||
public $quizid;
|
||||
public $attemptsdone = 0;
|
||||
public $attemptstodo;
|
||||
|
||||
public function __construct($quizid, $attemptstodo) {
|
||||
$this->quizid = $quizid;
|
||||
$this->attemptstodo = $attemptstodo;
|
||||
}
|
||||
|
||||
protected function get_quiz_ids() {
|
||||
return array($this->quizid => 1);
|
||||
}
|
||||
|
||||
protected function print_progress($done, $outof, $quizid) {
|
||||
}
|
||||
|
||||
protected function convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs) {
|
||||
$this->attemptsdone += 1;
|
||||
print_progress($this->attemptsdone, $this->attemptstodo);
|
||||
return parent::convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs);
|
||||
}
|
||||
|
||||
protected function get_resettable_attempts($quiz) {
|
||||
global $CFG;
|
||||
return get_records_sql("
|
||||
SELECT
|
||||
quiza.*
|
||||
|
||||
FROM {$CFG->prefix}quiz_attempts quiza
|
||||
LEFT JOIN (
|
||||
SELECT attempt, MAX(timestamp) AS time
|
||||
FROM {$CFG->prefix}question_states
|
||||
GROUP BY attempt
|
||||
) AS oldtimemodified ON oldtimemodified.attempt = quiza.uniqueid
|
||||
LEFT JOIN (
|
||||
SELECT qa.questionusageid, MAX(qas.timecreated) AS time
|
||||
FROM {$CFG->prefix}question_attempts qa
|
||||
JOIN {$CFG->prefix}question_attempt_steps qas ON qas.questionattemptid = qa.id
|
||||
GROUP BY qa.questionusageid
|
||||
) AS newtimemodified ON newtimemodified.questionusageid = quiza.uniqueid
|
||||
|
||||
WHERE quiza.preview = 0
|
||||
AND quiza.needsupgradetonewqe = 0
|
||||
AND oldtimemodified.time >= newtimemodified.time
|
||||
AND quiza.quiz = {$quiz->id}");
|
||||
}
|
||||
|
||||
public function reset_all_resettable_attempts() {
|
||||
begin_sql();
|
||||
$quiz = get_record('quiz', 'id', $this->quizid);
|
||||
$attempts = $this->get_resettable_attempts($quiz);
|
||||
foreach ($attempts as $attempt) {
|
||||
$this->reset_attempt($quiz, $attempt);
|
||||
}
|
||||
commit_sql();
|
||||
}
|
||||
|
||||
protected function reset_attempt($quiz, $attempt) {
|
||||
global $CFG;
|
||||
|
||||
$this->attemptsdone += 1;
|
||||
print_progress($this->attemptsdone, $this->attemptstodo);
|
||||
|
||||
$questionids = explode(',', $quiz->questions);
|
||||
$slottoquestionid = array(0 => 0);
|
||||
foreach ($questionids as $questionid) {
|
||||
if ($questionid) {
|
||||
$slottoquestionid[] = $questionid;
|
||||
}
|
||||
}
|
||||
|
||||
$slotlayout = explode(',', $attempt->layout);
|
||||
$oldlayout = array();
|
||||
$ok = true;
|
||||
foreach ($slotlayout as $slot) {
|
||||
if (array_key_exists($slot, $slottoquestionid)) {
|
||||
$oldlayout[] = $slottoquestionid[$slot];
|
||||
} else {
|
||||
$ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
$layout = implode(',', $oldlayout);
|
||||
} else {
|
||||
$layout = $attempt->layout;
|
||||
}
|
||||
|
||||
delete_records_select('question_attempt_step_data', "attemptstepid IN (
|
||||
SELECT qas.id
|
||||
FROM {$CFG->prefix}question_attempts qa
|
||||
JOIN {$CFG->prefix}question_attempt_steps qas ON qas.questionattemptid = qa.id
|
||||
WHERE questionusageid = {$attempt->uniqueid})");
|
||||
delete_records_select('question_attempt_steps', "questionattemptid IN (
|
||||
SELECT qa.id
|
||||
FROM {$CFG->prefix}question_attempts qa
|
||||
WHERE questionusageid = {$attempt->uniqueid})");
|
||||
delete_records('question_attempts', 'questionusageid', $attempt->uniqueid);
|
||||
|
||||
set_field('question_usages', 'preferredbehaviour', 'to_be_set_later',
|
||||
'id', $attempt->uniqueid);
|
||||
set_field('quiz_attempts', 'layout', $layout,
|
||||
'uniqueid', $attempt->uniqueid);
|
||||
set_field('quiz_attempts', 'needsupgradetonewqe', 1,
|
||||
'uniqueid', $attempt->uniqueid);
|
||||
}
|
||||
}
|
||||
|
||||
class grabber_question_engine_attempt_upgrader extends question_engine_attempt_upgrader {
|
||||
public function __construct() {
|
||||
$this->questionloader = new question_engine_upgrade_question_loader(null);
|
||||
}
|
||||
|
||||
public function format_var($name, $var) {
|
||||
$out = var_export($var, true);
|
||||
$out = str_replace('<', '<', $out);
|
||||
$out = str_replace('ADOFetchObj::__set_state(array(', '(object) array(', $out);
|
||||
$out = str_replace('stdClass::__set_state(array(', '(object) array(', $out);
|
||||
$out = str_replace('array (', 'array(', $out);
|
||||
$out = preg_replace('/=> \n\s*/', '=> ', $out);
|
||||
$out = str_replace(')),', '),', $out);
|
||||
$out = str_replace('))', ')', $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n(?! )/', "\n ", $out);
|
||||
return " $name = $out;\n";
|
||||
}
|
||||
|
||||
public function display_convert_attempt_input($quiz, $attempt, $question, $qsession, $qstates) {
|
||||
echo $this->format_var('$quiz', $quiz);
|
||||
echo $this->format_var('$attempt', $attempt);
|
||||
echo $this->format_var('$question', $question);
|
||||
echo $this->format_var('$qsession', $qsession);
|
||||
echo $this->format_var('$qstates', $qstates);
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -15,7 +14,6 @@
|
||||
// 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 upgrade the attempts at a particular quiz, after confirmation.
|
||||
*
|
||||
@ -26,8 +24,9 @@
|
||||
*/
|
||||
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once(dirname(__FILE__) . '/../../config.php');
|
||||
require_once(dirname(__FILE__) . '/locallib.php');
|
||||
require_once(dirname(__FILE__) . '/afterupgradelib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
$quizid = required_param('quizid', PARAM_INT);
|
||||
@ -35,39 +34,41 @@ $confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
local_qeupgradehelper_url('convertquiz', array('quizid' => $quizid)));
|
||||
$PAGE->navbar->add(get_string('listtodo', 'local_qeupgradehelper'),
|
||||
local_qeupgradehelper_url('listtodo'));
|
||||
$PAGE->navbar->add(get_string('convertattempts', 'local_qeupgradehelper'));
|
||||
|
||||
$quizsummary = report_quizupgrade_get_quiz($quizid);
|
||||
$renderer = $PAGE->get_renderer('local_qeupgradehelper');
|
||||
|
||||
$quizsummary = local_qeupgradehelper_get_quiz($quizid);
|
||||
if (!$quizsummary) {
|
||||
print_error('invalidquizid', 'report_quizupgrade', report_quizupgrade_url('index.php'));
|
||||
print_error('invalidquizid', 'local_qeupgradehelper',
|
||||
local_qeupgradehelper_url('listtodo'));
|
||||
}
|
||||
$quizsummary->name = format_string($quizsummary->name);
|
||||
|
||||
admin_externalpage_setup('reportquizupgrade');
|
||||
$quizsummary->name = format_string($quizsummary->name);
|
||||
|
||||
if ($confirmed && data_submitted() && confirm_sesskey()) {
|
||||
// Actually do the conversion.
|
||||
admin_externalpage_print_header();
|
||||
print_heading(get_string('upgradingquizattempts', 'report_quizupgrade', $quizsummary));
|
||||
echo $renderer->header();
|
||||
echo $renderer->heading(get_string(
|
||||
'upgradingquizattempts', 'local_qeupgradehelper', $quizsummary));
|
||||
|
||||
$upgrader = new report_quizupgrade_attempt_upgrader($quizsummary->id, $quizsummary->numtoconvert);
|
||||
$upgrader = new local_qeupgradehelper_attempt_upgrader(
|
||||
$quizsummary->id, $quizsummary->numtoconvert);
|
||||
$upgrader->convert_all_quiz_attempts();
|
||||
|
||||
print_heading(get_string('conversioncomplete', 'report_quizupgrade'));
|
||||
echo '<p><a href="' . $CFG->wwwroot . '/mod/quiz/report.php?q=' . $quizsummary->id .
|
||||
'">' . get_string('gotoquizreport', 'report_quizupgrade') . '</a></p>';
|
||||
print_continue(report_quizupgrade_url('index.php'));
|
||||
echo $renderer->heading(get_string('conversioncomplete', 'local_qeupgradehelper'));
|
||||
echo $renderer->end_of_page_link(
|
||||
new moodle_url('/mod/quiz/report.php', array('q' => $quizsummary->id)),
|
||||
get_string('gotoquizreport', 'local_qeupgradehelper'));
|
||||
echo $renderer->end_of_page_link(local_qeupgradehelper_url('listtodo'),
|
||||
get_string('listtodo', 'local_qeupgradehelper'));
|
||||
|
||||
admin_externalpage_print_footer();
|
||||
echo $renderer->footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Print an are-you-sure page.
|
||||
admin_externalpage_print_header();
|
||||
print_heading(get_string('areyousure', 'report_quizupgrade'));
|
||||
|
||||
$message = get_string('areyousuremessage', 'report_quizupgrade', $quizsummary);
|
||||
$params = array('quizid' => $quizsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
|
||||
notice_yesno($message, report_quizupgrade_url('convertquiz.php'),
|
||||
report_quizupgrade_url('index.php'), $params, null, 'post', 'get');
|
||||
|
||||
admin_externalpage_print_footer();
|
||||
echo $renderer->convert_quiz_are_you_sure($quizsummary);
|
||||
|
40
local/qeupgradehelper/cronsetup.php
Executable file
40
local/qeupgradehelper/cronsetup.php
Executable file
@ -0,0 +1,40 @@
|
||||
<?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 set up cron to complete the upgrade automatically.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
* @copyright 2010 The Open University
|
||||
* @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_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
local_qeupgradehelper_url('cronsetup'));
|
||||
$PAGE->navbar->add(get_string('cronsetup', 'local_qeupgradehelper'));
|
||||
|
||||
|
||||
$renderer = $PAGE->get_renderer('local_qeupgradehelper');
|
||||
|
||||
echo $renderer->simple_message_page('Not implemented yet. Sorry.');
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -15,14 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Ad-hoc quiz upgrade plugin.
|
||||
* This plugin can help upgrade site with a large number of question attempts
|
||||
* from Moodle 2.0 to 2.1.
|
||||
*
|
||||
* Allows the attempt data for quizzes that were not upgraded during the main
|
||||
* upgrade to be upgraded at any time.
|
||||
*
|
||||
* This screen lists all the quizzes that still need to be upgraded.
|
||||
* This screen is the main entry-point to the plugin, it gives the admin a list
|
||||
* of options available to them.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
@ -30,53 +27,29 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once(dirname(__FILE__) . '/../../config.php');
|
||||
require_once(dirname(__FILE__) . '/locallib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
admin_externalpage_setup('qeupgradehelper');
|
||||
|
||||
// Start the page.
|
||||
admin_externalpage_setup('reportquizupgrade');
|
||||
admin_externalpage_print_header();
|
||||
$renderer = $PAGE->get_renderer('local_qeupgradehelper');
|
||||
|
||||
$quizzes = report_quizupgrade_get_upgradable_quizzes();
|
||||
|
||||
if (empty($quizzes)) {
|
||||
print_heading(get_string('alreadydone', 'report_quizupgrade'));
|
||||
$actions = array();
|
||||
if (local_qeupgradehelper_isupgraded()) {
|
||||
$detected = get_string('upgradedsitedetected', 'local_qeupgradehelper');
|
||||
$actions[] = local_qeupgradehelper_action::make('listtodo');
|
||||
$actions[] = local_qeupgradehelper_action::make('listupgraded');
|
||||
$actions[] = local_qeupgradehelper_action::make('cronsetup');
|
||||
|
||||
} else {
|
||||
print_heading(get_string('quizzeswithunconverted', 'report_quizupgrade'));
|
||||
print_box(get_string('intro', 'report_quizupgrade'));
|
||||
|
||||
$table = new stdClass;
|
||||
$table->head = array(
|
||||
get_string('quizid', 'report_quizupgrade'),
|
||||
get_string('course'),
|
||||
get_string('modulename', 'quiz'),
|
||||
get_string('attemptstoconvert', 'report_quizupgrade'),
|
||||
get_string('actions', 'report_quizupgrade'),
|
||||
);
|
||||
|
||||
foreach ($quizzes as $quiz) {
|
||||
$table->data[] = array(
|
||||
$quiz->id,
|
||||
'<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $quiz->courseid .
|
||||
'">' . format_string($quiz->shortname) . '</a>',
|
||||
'<a href="' . $CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id .
|
||||
'">' . format_string($quiz->name) . '</a>',
|
||||
$quiz->numtoconvert,
|
||||
'<a href="' . report_quizupgrade_url('convertquiz.php?quizid=' . $quiz->id) .
|
||||
'">' . get_string('convertattempts', 'report_quizupgrade') . '</a>',
|
||||
);
|
||||
}
|
||||
|
||||
print_table($table);
|
||||
$detected = get_string('oldsitedetected', 'local_qeupgradehelper');
|
||||
$actions[] = local_qeupgradehelper_action::make('listpreupgrade');
|
||||
$actions[] = local_qeupgradehelper_action::make('extracttestcase');
|
||||
$actions[] = local_qeupgradehelper_action::make('pretendupgrade');
|
||||
$actions[] = local_qeupgradehelper_action::make('cronsetup');
|
||||
}
|
||||
|
||||
echo '<p><a href="' . report_quizupgrade_url('resetindex.php') . '">' .
|
||||
get_string('gotoresetlink', 'report_quizupgrade') . '</a></p>';
|
||||
|
||||
admin_externalpage_print_footer();
|
||||
echo $renderer->index_page($detected, $actions);
|
||||
|
@ -1,10 +1,26 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Lang strings for admin/report/customsql
|
||||
* Question engine upgrade helper langauge strings.
|
||||
*
|
||||
* @package report_customsql
|
||||
* @copyright © 2009 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
@ -13,21 +29,32 @@ $string['alreadydone'] = 'Everything has already been converted';
|
||||
$string['areyousure'] = 'Are you sure?';
|
||||
$string['areyousuremessage'] = 'Do you wish to proceed with upgrading all {$a->numtoconvert} attempts at quiz \'{$a->name}\' in course {$a->shortname}?';
|
||||
$string['areyousureresetmessage'] = 'Quiz \'{$a->name}\' in course {$a->shortname} has {$a->totalattempts} attempts, of which {$a->convertedattempts} were upgraded from the old system. Of those, {$a->resettableattempts} can be reset, for later re-conversion. Do you want to proceed with this?';
|
||||
$string['attemptstoconvert'] = 'Attempts to convert';
|
||||
$string['attemptstoconvert'] = 'Attempts needing conversion';
|
||||
$string['backtoindex'] = 'Back to the main page';
|
||||
$string['conversioncomplete'] = 'Conversion complete';
|
||||
$string['convertattempts'] = 'Convert attempts...';
|
||||
$string['convertattempts'] = 'Convert attempts';
|
||||
$string['convertquiz'] = 'Convert attempts...';
|
||||
$string['convertedattempts'] = 'Converted attempts';
|
||||
$string['cronsetup'] = 'Configure cron';
|
||||
$string['cronsetup_desc'] = 'You can configure cron to complete the upgrade of quiz attempt data automatically.';
|
||||
$string['gotoindex'] = 'Back to the list of quizzes that can be upgraded';
|
||||
$string['gotoquizreport'] = 'Go to the reports for this quiz, to check the upgrade';
|
||||
$string['gotoresetlink'] = 'Go to the list of quizzes that can be reset';
|
||||
$string['intro'] = 'Please do not convert any attempts unless you have discussed it with Phil Butcher or Tim Hunt.';
|
||||
$string['invalidquizid'] = 'Invaid quiz id. Either the quiz does not exist, or it has no attempts to convert.';
|
||||
$string['listtodo'] = 'List quizzes still to upgrade';
|
||||
$string['listtodo_desc'] = 'This will show a report of all the quizzes on the system (if any) that have attempts that still need to be upgraded to the new question engine.';
|
||||
$string['listtodointro'] = 'These are all the quizzes with attempt data that still needs to be converted. You can convert the attempts by clicking the link.';
|
||||
$string['listupgraded'] = 'List already upgrade quizzes that can be reset';
|
||||
$string['listupgraded_desc'] = 'This will show a report of all the quizzes on the system whose attepmts have been upgraded, and where the old data is still present so the upgrade could be reset and redone.';
|
||||
$string['nothingupgradedyet'] = 'No upgraded attempts that can be reset';
|
||||
$string['oldsitedetected'] = 'This appears to be a site that has not yet been upgraded to include the new question engine.';
|
||||
$string['pluginname'] = 'Question engine upgrade helper';
|
||||
$string['quizid'] = 'Quiz id';
|
||||
$string['quizupgrade'] = 'Quiz upgrade status';
|
||||
$string['quizzeswithunconverted'] = 'The following quizzes have attempts that need to be converted';
|
||||
$string['quizzesthatcanbereset'] = 'The following quizzes have converted attempts that you may be able to reset';
|
||||
$string['resetattempts'] = 'Reset attempts...';
|
||||
$string['resetquiz'] = 'Reset attempts...';
|
||||
$string['resetcomplete'] = 'Reset complete';
|
||||
$string['resettingquizattempts'] = 'Resetting quiz attempts';
|
||||
$string['upgradingquizattempts'] = 'Upgrading the attempts for quiz \'{$a->name}\' in course {$a->shortname}';
|
||||
$string['upgradedsitedetected'] = 'This appears to be a site that has been upgraded to include the new question engine.';
|
||||
|
47
local/qeupgradehelper/listtodo.php
Executable file
47
local/qeupgradehelper/listtodo.php
Executable file
@ -0,0 +1,47 @@
|
||||
<?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 quizzes with attempts that still need to be upgraded
|
||||
* after the main upgrade.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
* @copyright 2010 The Open University
|
||||
* @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_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
local_qeupgradehelper_url('listtodo'));
|
||||
$PAGE->navbar->add(get_string('listtodo', 'local_qeupgradehelper'));
|
||||
|
||||
$renderer = $PAGE->get_renderer('local_qeupgradehelper');
|
||||
|
||||
$quizzes = local_qeupgradehelper_get_upgradable_quizzes();
|
||||
|
||||
if (empty($quizzes)) {
|
||||
echo $renderer->simple_message_page(get_string('alreadydone', 'local_qeupgradehelper'));
|
||||
|
||||
} else {
|
||||
echo $renderer->list_quizzes_todo($quizzes);
|
||||
}
|
48
local/qeupgradehelper/listupgraded.php
Executable file
48
local/qeupgradehelper/listupgraded.php
Executable file
@ -0,0 +1,48 @@
|
||||
<?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 quizzes with attempts that have been upgraded
|
||||
* after the main upgrade. With an option to reset the conversion, so it can be
|
||||
* re-done if necessary.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
* @copyright 2010 The Open University
|
||||
* @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_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
local_qeupgradehelper_url('listupgraded'));
|
||||
$PAGE->navbar->add(get_string('listupgraded', 'local_qeupgradehelper'));
|
||||
|
||||
$renderer = $PAGE->get_renderer('local_qeupgradehelper');
|
||||
|
||||
$quizzes = local_qeupgradehelper_get_resettable_quizzes();
|
||||
|
||||
if (empty($quizzes)) {
|
||||
echo $renderer->simple_message_page(get_string('nothingupgradedyet', 'local_qeupgradehelper'));
|
||||
|
||||
} else {
|
||||
echo $renderer->list_quizzes_upgraded($quizzes);
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -15,9 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Library code for the Quiz upgrade status report.
|
||||
* Question engine upgrade helper library code.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
@ -26,36 +24,83 @@
|
||||
*/
|
||||
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/upgradefromoldqe/upgrade.php');
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* @param string $localurl part to go at the end of the URL.
|
||||
* @return string the full URL of that page within this report.
|
||||
* Detect whether this site has been upgraded to the new question engine yet.
|
||||
*/
|
||||
function report_quizupgrade_url($localurl) {
|
||||
function local_qeupgradehelper_isupgraded() {
|
||||
global $CFG;
|
||||
return $CFG->wwwroot . '/' . $CFG->admin . '/report/quizupgrade/' . $localurl;
|
||||
return is_readable($CFG->dirroot . '/question/engine/upgrade/upgradelib.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
function local_qeupgradehelper_url($script, $params = array()) {
|
||||
return new moodle_url('/local/qeupgradehelper/' . $script . '.php', $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class to encapsulate one of the functionalities that this plugin offers.
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class local_qeupgradehelper_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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public static function make($shortname, $params = array()) {
|
||||
return new self(
|
||||
get_string($shortname, 'local_qeupgradehelper'),
|
||||
local_qeupgradehelper_url($shortname, $params),
|
||||
get_string($shortname . '_desc', 'local_qeupgradehelper'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the information about a quizzes that can be upgraded.
|
||||
* @return array of objects with information about the quizzes that need upgrading.
|
||||
* has fields quiz id, quiz name, course shortname, couresid and number of
|
||||
* attempts that need converting.
|
||||
*/
|
||||
function report_quizupgrade_get_upgradable_quizzes() {
|
||||
global $CFG;
|
||||
return get_records_sql("
|
||||
function local_qeupgradehelper_get_upgradable_quizzes() {
|
||||
global $DB;
|
||||
return $DB->get_records_sql("
|
||||
SELECT
|
||||
quiz.id,
|
||||
quiz.name,
|
||||
c.shortname,
|
||||
c.id AS courseid,
|
||||
COUNT(1) AS numtoconvert
|
||||
COUNT(1) AS attemptcount
|
||||
|
||||
FROM {$CFG->prefix}quiz_attempts quiza
|
||||
JOIN {$CFG->prefix}quiz quiz ON quiz.id = quiza.quiz
|
||||
JOIN {$CFG->prefix}course c ON c.id = quiz.course
|
||||
FROM {quiz_attempts} quiza
|
||||
JOIN {quiz} quiz ON quiz.id = quiza.quiz
|
||||
JOIN {course} c ON c.id = quiz.course
|
||||
|
||||
WHERE quiza.preview = 0
|
||||
AND quiza.needsupgradetonewqe = 1
|
||||
@ -69,11 +114,11 @@ function report_quizupgrade_get_upgradable_quizzes() {
|
||||
* Get the information about a quiz to be upgraded.
|
||||
* @param integer $quizid the quiz id.
|
||||
* @return object the information about that quiz, as for
|
||||
* {@link report_quizupgrade_get_upgradable_quizzes()}.
|
||||
* {@link local_qeupgradehelper_get_upgradable_quizzes()}.
|
||||
*/
|
||||
function report_quizupgrade_get_quiz($quizid) {
|
||||
global $CFG;
|
||||
return get_record_sql("
|
||||
function local_qeupgradehelper_get_quiz($quizid) {
|
||||
global $DB;
|
||||
return $DB->get_record_sql("
|
||||
SELECT
|
||||
quiz.id,
|
||||
quiz.name,
|
||||
@ -81,17 +126,17 @@ function report_quizupgrade_get_quiz($quizid) {
|
||||
c.id AS courseid,
|
||||
COUNT(1) AS numtoconvert
|
||||
|
||||
FROM {$CFG->prefix}quiz_attempts quiza
|
||||
JOIN {$CFG->prefix}quiz quiz ON quiz.id = quiza.quiz
|
||||
JOIN {$CFG->prefix}course c ON c.id = quiz.course
|
||||
FROM {quiz_attempts} quiza
|
||||
JOIN {quiz} quiz ON quiz.id = quiza.quiz
|
||||
JOIN {course} c ON c.id = quiz.course
|
||||
|
||||
WHERE quiza.preview = 0
|
||||
AND quiza.needsupgradetonewqe = 1
|
||||
AND quiz.id = {$quizid}
|
||||
AND quiz.id = ?
|
||||
|
||||
GROUP BY quiz.id, quiz.name, c.shortname, c.id
|
||||
|
||||
ORDER BY c.shortname, quiz.name, quiz.id");
|
||||
ORDER BY c.shortname, quiz.name, quiz.id", array($quizid));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,23 +145,23 @@ function report_quizupgrade_get_quiz($quizid) {
|
||||
* has fields quiz id, quiz name, course shortname, couresid and number of
|
||||
* converted attempts.
|
||||
*/
|
||||
function report_quizupgrade_get_resettable_quizzes() {
|
||||
global $CFG;
|
||||
return get_records_sql("
|
||||
function local_qeupgradehelper_get_resettable_quizzes() {
|
||||
global $DB;
|
||||
return $DB->get_records_sql("
|
||||
SELECT
|
||||
quiz.id,
|
||||
quiz.name,
|
||||
c.shortname,
|
||||
c.id AS courseid,
|
||||
COUNT(1) AS convertedattempts
|
||||
COUNT(1) AS attemptcount
|
||||
|
||||
FROM {$CFG->prefix}quiz_attempts quiza
|
||||
JOIN {$CFG->prefix}quiz quiz ON quiz.id = quiza.quiz
|
||||
JOIN {$CFG->prefix}course c ON c.id = quiz.course
|
||||
FROM {quiz_attempts} quiza
|
||||
JOIN {quiz} quiz ON quiz.id = quiza.quiz
|
||||
JOIN {course} c ON c.id = quiz.course
|
||||
|
||||
WHERE quiza.preview = 0
|
||||
AND quiza.needsupgradetonewqe = 0
|
||||
AND EXISTS(SELECT 1 FROM {$CFG->prefix}question_states
|
||||
AND EXISTS(SELECT 1 FROM {question_states}
|
||||
WHERE attempt = quiza.uniqueid)
|
||||
|
||||
GROUP BY quiz.id, quiz.name, c.shortname, c.id
|
||||
@ -127,10 +172,10 @@ function report_quizupgrade_get_resettable_quizzes() {
|
||||
* Get the information about a quiz to be upgraded.
|
||||
* @param integer $quizid the quiz id.
|
||||
* @return object the information about that quiz, as for
|
||||
* {@link report_quizupgrade_get_resettable_quizzes()}, but with extra fields
|
||||
* {@link local_qeupgradehelper_get_resettable_quizzes()}, but with extra fields
|
||||
* totalattempts and resettableattempts.
|
||||
*/
|
||||
function report_quizupgrade_get_resettable_quiz($quizid) {
|
||||
function local_qeupgradehelper_get_resettable_quiz($quizid) {
|
||||
global $CFG;
|
||||
return get_record_sql("
|
||||
SELECT
|
||||
@ -165,146 +210,4 @@ function report_quizupgrade_get_resettable_quiz($quizid) {
|
||||
GROUP BY quiz.id, quiz.name, c.shortname, c.id");
|
||||
}
|
||||
|
||||
class report_quizupgrade_attempt_upgrader extends question_engine_attempt_upgrader {
|
||||
public $quizid;
|
||||
public $attemptsdone = 0;
|
||||
public $attemptstodo;
|
||||
|
||||
public function __construct($quizid, $attemptstodo) {
|
||||
$this->quizid = $quizid;
|
||||
$this->attemptstodo = $attemptstodo;
|
||||
}
|
||||
|
||||
protected function get_quiz_ids() {
|
||||
return array($this->quizid => 1);
|
||||
}
|
||||
|
||||
protected function print_progress($done, $outof, $quizid) {
|
||||
}
|
||||
|
||||
protected function convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs) {
|
||||
$this->attemptsdone += 1;
|
||||
print_progress($this->attemptsdone, $this->attemptstodo);
|
||||
return parent::convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs);
|
||||
}
|
||||
|
||||
protected function get_resettable_attempts($quiz) {
|
||||
global $CFG;
|
||||
return get_records_sql("
|
||||
SELECT
|
||||
quiza.*
|
||||
|
||||
FROM {$CFG->prefix}quiz_attempts quiza
|
||||
LEFT JOIN (
|
||||
SELECT attempt, MAX(timestamp) AS time
|
||||
FROM {$CFG->prefix}question_states
|
||||
GROUP BY attempt
|
||||
) AS oldtimemodified ON oldtimemodified.attempt = quiza.uniqueid
|
||||
LEFT JOIN (
|
||||
SELECT qa.questionusageid, MAX(qas.timecreated) AS time
|
||||
FROM {$CFG->prefix}question_attempts qa
|
||||
JOIN {$CFG->prefix}question_attempt_steps qas ON qas.questionattemptid = qa.id
|
||||
GROUP BY qa.questionusageid
|
||||
) AS newtimemodified ON newtimemodified.questionusageid = quiza.uniqueid
|
||||
|
||||
WHERE quiza.preview = 0
|
||||
AND quiza.needsupgradetonewqe = 0
|
||||
AND oldtimemodified.time >= newtimemodified.time
|
||||
AND quiza.quiz = {$quiz->id}");
|
||||
}
|
||||
|
||||
public function reset_all_resettable_attempts() {
|
||||
begin_sql();
|
||||
$quiz = get_record('quiz', 'id', $this->quizid);
|
||||
$attempts = $this->get_resettable_attempts($quiz);
|
||||
foreach ($attempts as $attempt) {
|
||||
$this->reset_attempt($quiz, $attempt);
|
||||
}
|
||||
commit_sql();
|
||||
}
|
||||
|
||||
protected function reset_attempt($quiz, $attempt) {
|
||||
global $CFG;
|
||||
|
||||
$this->attemptsdone += 1;
|
||||
print_progress($this->attemptsdone, $this->attemptstodo);
|
||||
|
||||
$questionids = explode(',', $quiz->questions);
|
||||
$slottoquestionid = array(0 => 0);
|
||||
foreach ($questionids as $questionid) {
|
||||
if ($questionid) {
|
||||
$slottoquestionid[] = $questionid;
|
||||
}
|
||||
}
|
||||
|
||||
$slotlayout = explode(',', $attempt->layout);
|
||||
$oldlayout = array();
|
||||
$ok = true;
|
||||
foreach ($slotlayout as $slot) {
|
||||
if (array_key_exists($slot, $slottoquestionid)) {
|
||||
$oldlayout[] = $slottoquestionid[$slot];
|
||||
} else {
|
||||
$ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
$layout = implode(',', $oldlayout);
|
||||
} else {
|
||||
$layout = $attempt->layout;
|
||||
}
|
||||
|
||||
delete_records_select('question_attempt_step_data', "attemptstepid IN (
|
||||
SELECT qas.id
|
||||
FROM {$CFG->prefix}question_attempts qa
|
||||
JOIN {$CFG->prefix}question_attempt_steps qas ON qas.questionattemptid = qa.id
|
||||
WHERE questionusageid = {$attempt->uniqueid})");
|
||||
delete_records_select('question_attempt_steps', "questionattemptid IN (
|
||||
SELECT qa.id
|
||||
FROM {$CFG->prefix}question_attempts qa
|
||||
WHERE questionusageid = {$attempt->uniqueid})");
|
||||
delete_records('question_attempts', 'questionusageid', $attempt->uniqueid);
|
||||
|
||||
set_field('question_usages', 'preferredbehaviour', 'to_be_set_later',
|
||||
'id', $attempt->uniqueid);
|
||||
set_field('quiz_attempts', 'layout', $layout,
|
||||
'uniqueid', $attempt->uniqueid);
|
||||
set_field('quiz_attempts', 'needsupgradetonewqe', 1,
|
||||
'uniqueid', $attempt->uniqueid);
|
||||
}
|
||||
}
|
||||
|
||||
class grabber_question_engine_attempt_upgrader extends question_engine_attempt_upgrader {
|
||||
public function __construct() {
|
||||
$this->questionloader = new question_engine_upgrade_question_loader(null);
|
||||
}
|
||||
|
||||
public function format_var($name, $var) {
|
||||
$out = var_export($var, true);
|
||||
$out = str_replace('<', '<', $out);
|
||||
$out = str_replace('ADOFetchObj::__set_state(array(', '(object) array(', $out);
|
||||
$out = str_replace('stdClass::__set_state(array(', '(object) array(', $out);
|
||||
$out = str_replace('array (', 'array(', $out);
|
||||
$out = preg_replace('/=> \n\s*/', '=> ', $out);
|
||||
$out = str_replace(')),', '),', $out);
|
||||
$out = str_replace('))', ')', $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n (?! )/', "\n ", $out);
|
||||
$out = preg_replace('/\n(?! )/', "\n ", $out);
|
||||
return " $name = $out;\n";
|
||||
}
|
||||
|
||||
public function display_convert_attempt_input($quiz, $attempt, $question, $qsession, $qstates) {
|
||||
echo $this->format_var('$quiz', $quiz);
|
||||
echo $this->format_var('$attempt', $attempt);
|
||||
echo $this->format_var('$question', $question);
|
||||
echo $this->format_var('$qsession', $qsession);
|
||||
echo $this->format_var('$qstates', $qstates);
|
||||
}
|
||||
}
|
||||
|
201
local/qeupgradehelper/renderer.php
Executable file
201
local/qeupgradehelper/renderer.php
Executable file
@ -0,0 +1,201 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Defines the renderer for the question engine upgrade helper plugin.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Renderer for the question engine upgrade helper plugin.
|
||||
*
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class local_qeupgradehelper_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Render the index page.
|
||||
* @param string $detected information about what sort of site was detected.
|
||||
* @param array $actions list of actions to show on this page.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function index_page($detected, array $actions) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('pluginname', 'local_qeupgradehelper'));
|
||||
$output .= $this->box($detected);
|
||||
$output .= html_writer::start_tag('ul');
|
||||
foreach ($actions as $action) {
|
||||
$output .= html_writer::tag('li',
|
||||
html_writer::link($action->url, $action->name) . ' - ' .
|
||||
$action->description);
|
||||
}
|
||||
$output .= html_writer::end_tag('ul');
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a page that is just a simple message.
|
||||
* @param string $message the message to display.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function simple_message_page($message) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading($message);
|
||||
$output .= $this->back_to_index();
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a table listing quizzes with other information.
|
||||
* @param array $quizzes of data about quizzes.
|
||||
* @param string $countheader
|
||||
* @param unknown_type $actionscript
|
||||
* @return string
|
||||
*/
|
||||
public function quizzes_table($quizzes, $countheader, $actionscript) {
|
||||
$table = new html_table();
|
||||
$table->head = array(
|
||||
get_string('quizid', 'local_qeupgradehelper'),
|
||||
get_string('course'),
|
||||
get_string('pluginname', 'quiz'),
|
||||
$countheader,
|
||||
get_string('actions', 'local_qeupgradehelper'),
|
||||
);
|
||||
|
||||
foreach ($quizzes as $quiz) {
|
||||
$table->data[] = array(
|
||||
$quiz->id,
|
||||
html_writer::link(new moodle_url('/course/view.php',
|
||||
array('id' => $quiz->courseid)), format_string($quiz->shortname)),
|
||||
html_writer::link(new moodle_url('/mod/quiz/view.php',
|
||||
array('id' => $quiz->name)), format_string($quiz->name)),
|
||||
$quiz->attemptcount,
|
||||
html_writer::link(local_qeupgradehelper_url($actionscript, array('quizid' => $quiz->id)),
|
||||
get_string($actionscript, 'local_qeupgradehelper')),
|
||||
);
|
||||
}
|
||||
|
||||
return html_writer::table($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the list of quizzes that still need to be upgraded page.
|
||||
* @param array $quizzes of data about quizzes.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function list_quizzes_todo($quizzes) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('quizzeswithunconverted', 'local_qeupgradehelper'));
|
||||
$output .= $this->box(get_string('listtodointro', 'local_qeupgradehelper'));
|
||||
|
||||
$output .= $this->quizzes_table($quizzes,
|
||||
get_string('attemptstoconvert', 'local_qeupgradehelper'), 'convertquiz');
|
||||
|
||||
$output .= $this->back_to_index();
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the list of quizzes that can have the upgrade reset.
|
||||
* @param array $quizzes of data about quizzes.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function list_quizzes_upgraded($quizzes) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('quizzesthatcanbereset', 'local_qeupgradehelper'));
|
||||
$output .= $this->box(get_string('listupgradedintro', 'local_qeupgradehelper'));
|
||||
|
||||
$output .= $this->quizzes_table($quizzes,
|
||||
get_string('convertedattempts', 'local_qeupgradehelper'), 'resetattempts');
|
||||
|
||||
$output .= $this->back_to_index();
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the are-you-sure page to confirm a manual upgrade.
|
||||
* @param object $quizsummary data about the quiz to upgrade.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function convert_quiz_are_you_sure($quizsummary) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('areyousure', 'local_qeupgradehelper'));
|
||||
|
||||
$params = array('quizid' => $quizsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
|
||||
$output .= $this->confirm(get_string('areyousuremessage', 'local_qeupgradehelper', $quizsummary),
|
||||
new single_button(local_qeupgradehelper_url('convertquiz', $params), get_string('yes')),
|
||||
local_qeupgradehelper_url('listtodo'));
|
||||
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the are-you-sure page to confirm a manual reset.
|
||||
* @param object $quizsummary data about the quiz to reset.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function reset_quiz_are_you_sure($quizsummary) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('areyousure', 'local_qeupgradehelper'));
|
||||
|
||||
$params = array('quizid' => $quizsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
|
||||
$output .= $this->confirm(get_string('areyousureresetmessage', 'local_qeupgradehelper', $quizsummary),
|
||||
new single_button(local_qeupgradehelper_url('resetquiz', $params), get_string('yes')),
|
||||
local_qeupgradehelper_url('listupgraded'));
|
||||
|
||||
$output .= $this->footer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a link in a div, such as the 'Back to plugin main page' link.
|
||||
* @param $url the link URL.
|
||||
* @param $text the link text.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function end_of_page_link($url, $text) {
|
||||
return html_writer::tag('div', html_writer::link($url ,$text),
|
||||
array('class' => 'mdl-align'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a link back to the plugin index page.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function back_to_index() {
|
||||
return $this->end_of_page_link(local_qeupgradehelper_url('index'),
|
||||
get_string('backtoindex', 'local_qeupgradehelper'));
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
|
||||
/**
|
||||
* Ad-hoc quiz upgrade plugin. This screen lists quizzes with attempts that can
|
||||
* be reset.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
* @copyright 2010 The Open University
|
||||
* @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_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
|
||||
// Start the page.
|
||||
admin_externalpage_setup('reportquizupgrade');
|
||||
admin_externalpage_print_header();
|
||||
|
||||
$quizzes = report_quizupgrade_get_resettable_quizzes();
|
||||
|
||||
if (empty($quizzes)) {
|
||||
print_heading(get_string('none'));
|
||||
|
||||
} else {
|
||||
print_heading(get_string('quizzesthatcanbereset', 'report_quizupgrade'));
|
||||
print_box(get_string('intro', 'report_quizupgrade'));
|
||||
|
||||
$table = new stdClass;
|
||||
$table->head = array(
|
||||
get_string('quizid', 'report_quizupgrade'),
|
||||
get_string('course'),
|
||||
get_string('modulename', 'quiz'),
|
||||
get_string('convertedattempts', 'report_quizupgrade'),
|
||||
get_string('actions', 'report_quizupgrade'),
|
||||
);
|
||||
|
||||
foreach ($quizzes as $quiz) {
|
||||
$table->data[] = array(
|
||||
$quiz->id,
|
||||
'<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $quiz->courseid .
|
||||
'">' . format_string($quiz->shortname) . '</a>',
|
||||
'<a href="' . $CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id .
|
||||
'">' . format_string($quiz->name) . '</a>',
|
||||
$quiz->convertedattempts,
|
||||
'<a href="' . $CFG->wwwroot . '/' . $CFG->admin .
|
||||
'/report/quizupgrade/resetquiz.php?quizid=' . $quiz->id .
|
||||
'">' . get_string('resetattempts', 'report_quizupgrade') . '</a>',
|
||||
);
|
||||
}
|
||||
|
||||
print_table($table);
|
||||
}
|
||||
|
||||
echo '<p><a href="' . report_quizupgrade_url('index.php') . '">' .
|
||||
get_string('gotoindex', 'report_quizupgrade') . '</a></p>';
|
||||
|
||||
admin_externalpage_print_footer();
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -15,9 +14,8 @@
|
||||
// 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 reset the attempts at a particular quiz, after confirmation.
|
||||
* Script to reset the upgrade of attempts at a particular quiz, after confirmation.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
@ -35,37 +33,38 @@ $confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
local_qeupgradehelper_url('resetquiz', array('quizid' => $quizid)));
|
||||
$PAGE->navbar->add(get_string('listupgraded', 'local_qeupgradehelper'),
|
||||
local_qeupgradehelper_url('listtodo'));
|
||||
$PAGE->navbar->add(get_string('resetattempts', 'local_qeupgradehelper'));
|
||||
|
||||
$quizsummary = report_quizupgrade_get_resettable_quiz($quizid);
|
||||
$renderer = $PAGE->get_renderer('local_qeupgradehelper');
|
||||
|
||||
$quizsummary = local_qeupgradehelper_get_resettable_quiz($quizid);
|
||||
if (!$quizsummary) {
|
||||
print_error('invalidquizid', 'report_quizupgrade', report_quizupgrade_url('index.php'));
|
||||
print_error('invalidquizid', 'local_qeupgradehelper',
|
||||
local_qeupgradehelper_url('listupgraded'));
|
||||
}
|
||||
$quizsummary->name = format_string($quizsummary->name);
|
||||
|
||||
admin_externalpage_setup('reportquizupgrade');
|
||||
$quizsummary->name = format_string($quizsummary->name);
|
||||
|
||||
if ($confirmed && data_submitted() && confirm_sesskey()) {
|
||||
// Actually do the conversion.
|
||||
admin_externalpage_print_header();
|
||||
print_heading(get_string('resettingquizattempts', 'report_quizupgrade', $quizsummary));
|
||||
echo $renderer->header();
|
||||
echo $renderer->heading(get_string(
|
||||
'resettingquizattempts', 'local_qeupgradehelper', $quizsummary));
|
||||
|
||||
$upgrader = new report_quizupgrade_attempt_upgrader($quizsummary->id, $quizsummary->resettableattempts);
|
||||
$upgrader = new local_qeupgradehelper_attempt_upgrader(
|
||||
$quizsummary->id, $quizsummary->resettableattempts);
|
||||
$upgrader->reset_all_resettable_attempts();
|
||||
|
||||
print_heading(get_string('resetcomplete', 'report_quizupgrade'));
|
||||
print_continue(report_quizupgrade_url('resetindex.php'));
|
||||
echo $renderer->heading(get_string('resetcomplete', 'local_qeupgradehelper'));
|
||||
echo $renderer->end_of_page_link(local_qeupgradehelper_url('listupgraded'),
|
||||
get_string('listupgraded', 'local_qeupgradehelper'));
|
||||
|
||||
admin_externalpage_print_footer();
|
||||
echo $renderer->footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Print an are-you-sure page.
|
||||
admin_externalpage_print_header();
|
||||
print_heading(get_string('areyousure', 'report_quizupgrade'));
|
||||
|
||||
$message = get_string('areyousureresetmessage', 'report_quizupgrade', $quizsummary);
|
||||
$params = array('quizid' => $quizsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
|
||||
notice_yesno($message, report_quizupgrade_url('resetquiz.php'),
|
||||
report_quizupgrade_url('resetindex.php'), $params, null, 'post', 'get');
|
||||
|
||||
admin_externalpage_print_footer();
|
||||
echo $renderer->reset_quiz_are_you_sure($quizsummary);
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Add page to admin menu.
|
||||
* Adds this plugin to the admin menu.
|
||||
*
|
||||
* @package local
|
||||
* @subpackage qeupgradehelper
|
||||
@ -28,5 +28,5 @@ defined('MOODLE_INTERNAL') || die;
|
||||
if ($hassiteconfig) { // needs this condition or there is error on login page
|
||||
$ADMIN->add('root', new admin_externalpage('qeupgradehelper',
|
||||
get_string('pluginname', 'local_qeupgradehelper'),
|
||||
new moodle_url('/local/qeupgradehelper/')));
|
||||
new moodle_url('/local/qeupgradehelper/index.php')));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user