From 4e8a07d28b8174965181bbe8ca1f4b0080d1d1da Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 13 Feb 2014 12:35:30 +0000 Subject: [PATCH] MDL-44118 remove the qeupgradehelper tool and associated code that was only used by it. --- admin/tool/qeupgradehelper/README.txt | 43 -- .../tool/qeupgradehelper/afterupgradelib.php | 164 ----- admin/tool/qeupgradehelper/cli/convert.php | 129 ---- admin/tool/qeupgradehelper/convertquiz.php | 76 -- admin/tool/qeupgradehelper/cronsetup.php | 69 -- admin/tool/qeupgradehelper/cronsetup_form.php | 66 -- admin/tool/qeupgradehelper/db/install.php | 31 - .../tool/qeupgradehelper/extracttestcase.php | 74 -- .../qeupgradehelper/extracttestcase_form.php | 73 -- admin/tool/qeupgradehelper/index.php | 55 -- .../lang/en/tool_qeupgradehelper.php | 83 --- admin/tool/qeupgradehelper/lib.php | 93 --- admin/tool/qeupgradehelper/listpreupgrade.php | 61 -- admin/tool/qeupgradehelper/listtodo.php | 49 -- admin/tool/qeupgradehelper/listupgraded.php | 50 -- admin/tool/qeupgradehelper/locallib.php | 674 ------------------ .../partialupgrade-example.php | 115 --- admin/tool/qeupgradehelper/renderer.php | 168 ----- admin/tool/qeupgradehelper/resetquiz.php | 72 -- admin/tool/qeupgradehelper/settings.php | 32 - admin/tool/qeupgradehelper/styles.css | 6 - admin/tool/qeupgradehelper/version.php | 30 - lib/db/upgrade.php | 9 + lib/upgradelib.php | 18 +- question/engine/upgrade/upgradelib.php | 178 ----- version.php | 2 +- 26 files changed, 20 insertions(+), 2400 deletions(-) delete mode 100644 admin/tool/qeupgradehelper/README.txt delete mode 100644 admin/tool/qeupgradehelper/afterupgradelib.php delete mode 100644 admin/tool/qeupgradehelper/cli/convert.php delete mode 100644 admin/tool/qeupgradehelper/convertquiz.php delete mode 100644 admin/tool/qeupgradehelper/cronsetup.php delete mode 100644 admin/tool/qeupgradehelper/cronsetup_form.php delete mode 100644 admin/tool/qeupgradehelper/db/install.php delete mode 100644 admin/tool/qeupgradehelper/extracttestcase.php delete mode 100644 admin/tool/qeupgradehelper/extracttestcase_form.php delete mode 100644 admin/tool/qeupgradehelper/index.php delete mode 100644 admin/tool/qeupgradehelper/lang/en/tool_qeupgradehelper.php delete mode 100644 admin/tool/qeupgradehelper/lib.php delete mode 100644 admin/tool/qeupgradehelper/listpreupgrade.php delete mode 100644 admin/tool/qeupgradehelper/listtodo.php delete mode 100644 admin/tool/qeupgradehelper/listupgraded.php delete mode 100644 admin/tool/qeupgradehelper/locallib.php delete mode 100644 admin/tool/qeupgradehelper/partialupgrade-example.php delete mode 100644 admin/tool/qeupgradehelper/renderer.php delete mode 100644 admin/tool/qeupgradehelper/resetquiz.php delete mode 100644 admin/tool/qeupgradehelper/settings.php delete mode 100644 admin/tool/qeupgradehelper/styles.css delete mode 100644 admin/tool/qeupgradehelper/version.php diff --git a/admin/tool/qeupgradehelper/README.txt b/admin/tool/qeupgradehelper/README.txt deleted file mode 100644 index b9ce983d4bd..00000000000 --- a/admin/tool/qeupgradehelper/README.txt +++ /dev/null @@ -1,43 +0,0 @@ -This plugin can help upgrade site with a large number of question attempts from -Moodle 2.0 to 2.1. - -With a lot of question attempts, doing the whole conversion on upgrade is very -slow. The plugin can help with that in various ways. - - -1. It provides a report of how much data there is to upgrade. - -2. It can extract test-cases from the database. This can help you report bugs -in the upgrade process to the developers. - -3. You can set up cron to complete the conversion of quiz attempts, if you have -configured a partial upgrade. - - -If this plugin is present during upgrade: - -4. then only a subset of attempts are upgraded. Read the instructions in the -partialupgrade-example.php script. - - -If this plugin is present in a Moodle 2.1 site after upgrade: - -5. If not all attempts have been upgraded in a 2.1 site, then this plugin -displays a list of how many quizzes still need to be upgraded - -6. ... and can be used to complete the upgrade manually ... - -7. or this plugin has a cron script that can be used to finish the upgrade -automatically after the main upgrade has finished. - -8. It can also reset any attempts that were upgraded (provided they have not -subsequently been modified) so you can re-upgrade them. This may allow you to -recover from a buggy upgrade. - -9. Finally, you can still use the extract test-cases script to help report bugs. - - -Manual upgrades can be processed via the web interface or the command line tool -cliupgrade.php. To run cliupgrade.php, use a command similar to: -sudo -u www-data /usr/bin/php admin/tool/qeupgradehelper/cli/convert.php -h -The -h flag will show the options for running the tool. \ No newline at end of file diff --git a/admin/tool/qeupgradehelper/afterupgradelib.php b/admin/tool/qeupgradehelper/afterupgradelib.php deleted file mode 100644 index 5aeb316ac1d..00000000000 --- a/admin/tool/qeupgradehelper/afterupgradelib.php +++ /dev/null @@ -1,164 +0,0 @@ -. - - -/** - * Question engine upgrade helper library code that relies on other parts of the - * new question engine code. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -require_once($CFG->dirroot . '/question/engine/upgrade/upgradelib.php'); - - -class tool_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); - } - - protected function print_progress($done, $outof, $quizid) { - } - - protected function convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs) { - $this->attemptsdone += 1; - return parent::convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs); - } - - protected function reset_progress($done, $outof) { - if (is_null($this->progressbar)) { - $this->progressbar = new progress_bar('qe2reset'); - $this->progressbar->create(); - } - - gc_collect_cycles(); // This was really helpful in PHP 5.2. Perhaps remove. - $a = new stdClass(); - $a->done = $done; - $a->outof = $outof; - $this->progressbar->update($done, $outof, - get_string('resettingquizattemptsprogress', 'tool_qeupgradehelper', $a)); - } - - protected function get_resettable_attempts($quiz) { - global $DB; - return $DB->get_records_sql(" - SELECT - quiza.* - - FROM {quiz_attempts} quiza - LEFT JOIN ( - SELECT attempt, MAX(timestamp) AS time - FROM {question_states} - GROUP BY attempt - ) AS oldtimemodified ON oldtimemodified.attempt = quiza.uniqueid - LEFT JOIN ( - SELECT qa.questionusageid, MAX(qas.timecreated) AS time - FROM {question_attempts} qa - JOIN {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 (newtimemodified.time IS NULL OR oldtimemodified.time >= newtimemodified.time) - AND quiza.quiz = :quizid", array('quizid' => $quiz->id)); - } - - public function reset_all_resettable_attempts() { - global $DB; - - $transaction = $DB->start_delegated_transaction(); - - $quiz = $DB->get_record('quiz', array('id' => $this->quizid)); - $attempts = $this->get_resettable_attempts($quiz); - foreach ($attempts as $attempt) { - $this->reset_attempt($quiz, $attempt); - } - - $transaction->allow_commit(); - } - - protected function reset_attempt($quiz, $attempt) { - global $DB; - - $this->attemptsdone += 1; - $this->reset_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 if (in_array($slot, $questionids)) { - // OK there was probably a problem during the original upgrade. - $oldlayout[] = $slot; - } else { - $ok = false; - break; - } - } - - if ($ok) { - $layout = implode(',', $oldlayout); - } else { - $layout = $attempt->layout; - } - - $DB->delete_records_select('question_attempt_step_data', "attemptstepid IN ( - SELECT qas.id - FROM {question_attempts} qa - JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id - WHERE questionusageid = :uniqueid)", - array('uniqueid' => $attempt->uniqueid)); - $DB->delete_records_select('question_attempt_steps', "questionattemptid IN ( - SELECT qa.id - FROM {question_attempts} qa - WHERE questionusageid = :uniqueid)", - array('uniqueid' => $attempt->uniqueid)); - $DB->delete_records('question_attempts', - array('questionusageid' => $attempt->uniqueid)); - - $DB->set_field('question_usages', 'preferredbehaviour', 'to_be_set_later', - array('id' => $attempt->uniqueid)); - $DB->set_field('quiz_attempts', 'layout', $layout, - array('uniqueid' => $attempt->uniqueid)); - $DB->set_field('quiz_attempts', 'needsupgradetonewqe', 1, - array('uniqueid' => $attempt->uniqueid)); - } -} diff --git a/admin/tool/qeupgradehelper/cli/convert.php b/admin/tool/qeupgradehelper/cli/convert.php deleted file mode 100644 index 779442e80f9..00000000000 --- a/admin/tool/qeupgradehelper/cli/convert.php +++ /dev/null @@ -1,129 +0,0 @@ -. - -/** - * Script to allow upgrading of quizzes with attempts that were previously - * skipped. - * - * @package tool_qeupgradehelper - * @copyright 2012 Eric Merrill, Oakland Unversity - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -define('CLI_SCRIPT', true); - -require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config.php'); -require_once(dirname(dirname(__FILE__)) . '/locallib.php'); -require_once(dirname(dirname(__FILE__)) . '/lib.php'); -require_once($CFG->libdir.'/clilib.php'); // CLI only functions. - - -// Now get cli options. -list($options, $unrecognized) = cli_get_params(array('quiz'=>false, 'timelimit'=>false, 'countlimit'=>false, 'help'=>false), - array('c'=>'countlimit', 't'=>'timelimit', 'h'=>'help')); - -if ($unrecognized) { - $unrecognized = implode("\n ", $unrecognized); - cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); -} - - -if ($options['help']) { - $help = -"Question engine upgrade helper CLI tool. -Will upgrade all remaining question attempts if no options are specified. - -Options: --c, --countlimit= Process n number of quizzes then exit --t, --timelimit= Process quizzes for n number of seconds, then exit. A quiz - currently in progress will not be interrupted. ---quiz= Process quiz quizid only --h, --help Print out this help - -countlimit and timelimit can be used together. First one to trigger will stop execution. - -Example: -\$sudo -u www-data /usr/bin/php admin/tool/qeupgradehelper/cliupgrade.php -"; - - echo $help; - die; -} - - - - -if (!tool_qeupgradehelper_is_upgraded()) { - mtrace('qeupgradehelper: site not yet upgraded. Doing nothing.'); - return; -} - -require_once(dirname(dirname(__FILE__)) . '/afterupgradelib.php'); - - -$starttime = time(); - -// Setup the stop time. -if ($options['timelimit']) { - $stoptime = time() + $options['timelimit']; -} else { - $stoptime = false; -} - -// If we are doing a quiz id, limit to one. -if ($options['quiz']) { - $options['countlimit'] = 1; -} - -$count = 0; - - -mtrace('qeupgradehelper: processing ...'); - -/* This while statement does a few things - * Basically if an option is set to false, then that subsection will return - * true, and will short circuit the test condition for that option, and always - * being true. Both options are anded together, so either one can trigger to stop. - */ -while ((!$stoptime || (time() < $stoptime)) && (!$options['countlimit'] || ($count < $options['countlimit']))) { - if ($options['quiz']) { - $quizid = $options['quiz']; - } else { - $quiz = tool_qeupgradehelper_get_quiz_for_upgrade(); - if (!$quiz) { - mtrace('qeupgradehelper: No more quizzes to process.'); - break; // No more to do. - } - - $quizid = $quiz->id; - } - $quizsummary = tool_qeupgradehelper_get_quiz($quizid); - if ($quizsummary) { - mtrace(' starting upgrade of attempts at quiz ' . $quizid); - $upgrader = new tool_qeupgradehelper_attempt_upgrader( - $quizsummary->id, $quizsummary->numtoconvert); - $upgrader->convert_all_quiz_attempts(); - mtrace(' upgrade of quiz ' . $quizid . ' complete.'); - } else { - mtrace('quiz ' . $quizid . ' not found or already upgraded.'); - } - - $count++; -} - - -mtrace('qeupgradehelper: Done. Processed '.$count.' quizes in '.(time()-$starttime).' seconds'); -return; diff --git a/admin/tool/qeupgradehelper/convertquiz.php b/admin/tool/qeupgradehelper/convertquiz.php deleted file mode 100644 index d12fc992703..00000000000 --- a/admin/tool/qeupgradehelper/convertquiz.php +++ /dev/null @@ -1,76 +0,0 @@ -. - -/** - * Script to upgrade the attempts at a particular quiz, after confirmation. - * - * @package tool - * @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(dirname(__FILE__) . '/afterupgradelib.php'); -require_once($CFG->libdir . '/adminlib.php'); - -$quizid = required_param('quizid', PARAM_INT); -$confirmed = optional_param('confirmed', false, PARAM_BOOL); - -require_login(); -require_capability('moodle/site:config', context_system::instance()); -tool_qeupgradehelper_require_upgraded(); - -admin_externalpage_setup('qeupgradehelper', '', array(), - tool_qeupgradehelper_url('convertquiz', array('quizid' => $quizid))); -$PAGE->navbar->add(get_string('listtodo', 'tool_qeupgradehelper'), - tool_qeupgradehelper_url('listtodo')); -$PAGE->navbar->add(get_string('convertattempts', 'tool_qeupgradehelper')); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$quizsummary = tool_qeupgradehelper_get_quiz($quizid); -if (!$quizsummary) { - print_error('invalidquizid', 'tool_qeupgradehelper', - tool_qeupgradehelper_url('listtodo')); -} - -$quizsummary->name = format_string($quizsummary->name); - -if ($confirmed && data_submitted() && confirm_sesskey()) { - // Actually do the conversion. - echo $renderer->header(); - echo $renderer->heading(get_string( - 'upgradingquizattempts', 'tool_qeupgradehelper', $quizsummary)); - - $upgrader = new tool_qeupgradehelper_attempt_upgrader( - $quizsummary->id, $quizsummary->numtoconvert); - $upgrader->convert_all_quiz_attempts(); - - echo $renderer->heading(get_string('conversioncomplete', 'tool_qeupgradehelper')); - echo $renderer->end_of_page_link( - new moodle_url('/mod/quiz/report.php', array('q' => $quizsummary->id)), - get_string('gotoquizreport', 'tool_qeupgradehelper')); - echo $renderer->end_of_page_link(tool_qeupgradehelper_url('listtodo'), - get_string('listtodo', 'tool_qeupgradehelper')); - - echo $renderer->footer(); - exit; -} - -echo $renderer->convert_quiz_are_you_sure($quizsummary); diff --git a/admin/tool/qeupgradehelper/cronsetup.php b/admin/tool/qeupgradehelper/cronsetup.php deleted file mode 100644 index 2523ee5c565..00000000000 --- a/admin/tool/qeupgradehelper/cronsetup.php +++ /dev/null @@ -1,69 +0,0 @@ -. - -/** - * Script to set up cron to complete the upgrade automatically. - * - * @package tool - * @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(dirname(__FILE__) . '/cronsetup_form.php'); -require_once($CFG->libdir . '/adminlib.php'); - -require_login(); -require_capability('moodle/site:config', context_system::instance()); - -admin_externalpage_setup('qeupgradehelper', '', array(), - tool_qeupgradehelper_url('cronsetup')); -$PAGE->navbar->add(get_string('cronsetup', 'tool_qeupgradehelper')); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$form = new tool_qeupgradehelper_cron_setup_form( - new moodle_url('/admin/tool/qeupgradehelper/cronsetup.php')); -$form->set_data(get_config('tool_qeupgradehelper')); - -if ($form->is_cancelled()) { - redirect(tool_qeupgradehelper_url('index')); - -} else if ($fromform = $form->get_data()) { - if ($fromform->cronenabled) { - set_config('cronenabled', $fromform->cronenabled, 'tool_qeupgradehelper'); - set_config('starthour', $fromform->starthour, 'tool_qeupgradehelper'); - set_config('stophour', $fromform->stophour, 'tool_qeupgradehelper'); - set_config('procesingtime', $fromform->procesingtime, 'tool_qeupgradehelper'); - - } else { - unset_config('cronenabled', 'tool_qeupgradehelper'); - unset_config('starthour', 'tool_qeupgradehelper'); - unset_config('stophour', 'tool_qeupgradehelper'); - unset_config('procesingtime', 'tool_qeupgradehelper'); - } - redirect(tool_qeupgradehelper_url('index')); - -} - -echo $renderer->header(); -echo $renderer->heading(get_string('cronsetup', 'tool_qeupgradehelper')); -echo $renderer->box(get_string('croninstructions', 'tool_qeupgradehelper')); -$form->display(); -echo $renderer->footer(); diff --git a/admin/tool/qeupgradehelper/cronsetup_form.php b/admin/tool/qeupgradehelper/cronsetup_form.php deleted file mode 100644 index 60473f5bb95..00000000000 --- a/admin/tool/qeupgradehelper/cronsetup_form.php +++ /dev/null @@ -1,66 +0,0 @@ -. - -/** - * Settings form for cronsetup.php. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir . '/formslib.php'); - - -/** - * Cron setup form. - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class tool_qeupgradehelper_cron_setup_form extends moodleform { - public function definition() { - $mform = $this->_form; - - $mform->addElement('selectyesno', 'cronenabled', - get_string('cronenabled', 'tool_qeupgradehelper')); - $mform->setType('cronenabled', PARAM_BOOL); - - $mform->addElement('select', 'starthour', - get_string('cronstarthour', 'tool_qeupgradehelper'), range(0, 23)); - $mform->setType('starthour', PARAM_INT); - - $mform->addElement('select', 'stophour', - get_string('cronstophour', 'tool_qeupgradehelper'), - array_combine(range(1, 24), range(1, 24))); - $mform->setType('stophour', PARAM_INT); - $mform->setDefault('stophour', 24); - - $mform->addElement('duration', 'procesingtime', - get_string('cronprocesingtime', 'tool_qeupgradehelper')); - $mform->setType('procesingtime', PARAM_INT); - $mform->setDefault('procesingtime', 60); - - $mform->disabledIf('starthour', 'cronenabled', 'eq', 0); - $mform->disabledIf('stophour', 'cronenabled', 'eq', 0); - $mform->disabledIf('procesingtime', 'cronenabled', 'eq', 0); - - $this->add_action_buttons(); - } -} diff --git a/admin/tool/qeupgradehelper/db/install.php b/admin/tool/qeupgradehelper/db/install.php deleted file mode 100644 index 7e26253742e..00000000000 --- a/admin/tool/qeupgradehelper/db/install.php +++ /dev/null @@ -1,31 +0,0 @@ -. - -/** - * Post installation and migration code. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2011 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -function xmldb_tool_qeupgradehelper_install() { - global $CFG; - -} diff --git a/admin/tool/qeupgradehelper/extracttestcase.php b/admin/tool/qeupgradehelper/extracttestcase.php deleted file mode 100644 index 902418f1730..00000000000 --- a/admin/tool/qeupgradehelper/extracttestcase.php +++ /dev/null @@ -1,74 +0,0 @@ -. - -/** - * Script to help create unit tests for the upgrade using example data from the - * database. - * - * (The theory is that if the upgrade dies with an error, you can restore the - * database from backup, and then use this script to extract the problem case - * as a unit test. Then you can fix that unit tests. Then you can repeat the upgrade.) - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2009 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(dirname(__FILE__) . '/extracttestcase_form.php'); -require_once($CFG->libdir . '/questionlib.php'); -require_once($CFG->libdir . '/adminlib.php'); - - -require_login(); -require_capability('moodle/site:config', context_system::instance()); - -admin_externalpage_setup('qeupgradehelper', '', array(), - tool_qeupgradehelper_url('extracttestcase')); -$PAGE->navbar->add(get_string('extracttestcase', 'tool_qeupgradehelper')); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$mform = new tool_qeupgradehelper_extract_options_form( - new moodle_url('/admin/tool/qeupgradehelper/extracttestcase.php'), null, 'get'); - -echo $OUTPUT->header(); -if ($fromform = $mform->get_data()) { - $qsid = null; - if (!empty($fromform->attemptid) && !empty($fromform->questionid)) { - $qsid = tool_qeupgradehelper_get_session_id($fromform->attemptid, $fromform->questionid); - $name = 'qsession' . $qsid; - - } else if (!empty($fromform->statehistory)) { - notify('Searching ...', 'notifysuccess'); - flush(); - $qsid = tool_qeupgradehelper_find_test_case($fromform->behaviour, $fromform->statehistory, - $fromform->qtype, $fromform->extratests); - $name = 'history' . $fromform->statehistory; - } - - if ($qsid) { - tool_qeupgradehelper_generate_unit_test($qsid, $name); - } else { - notify('No suitable attempts found.'); - } -} - -$mform->display(); -echo $OUTPUT->footer(); diff --git a/admin/tool/qeupgradehelper/extracttestcase_form.php b/admin/tool/qeupgradehelper/extracttestcase_form.php deleted file mode 100644 index ca8619ed20e..00000000000 --- a/admin/tool/qeupgradehelper/extracttestcase_form.php +++ /dev/null @@ -1,73 +0,0 @@ -. - -/** - * Settings form for extracttestcase.php. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir . '/formslib.php'); - - -/** - * Options form. - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class tool_qeupgradehelper_extract_options_form extends moodleform { - public function definition() { - $mform = $this->_form; - - $behaviour = array( - 'deferredfeedback' => 'Deferred feedback', - 'adaptive' => 'Adaptive', - 'adaptivenopenalty' => 'Adaptive (no penalties)', - ); - - $qtypes = core_component::get_plugin_list('qtype'); - foreach ($qtypes as $qtype => $notused) { - $qtypes[$qtype] = get_string('pluginname', 'qtype_' . $qtype); - } - - $mform->addElement('header', 'h1', 'Either extract a specific question_session'); - $mform->addElement('text', 'attemptid', 'Quiz attempt id', array('size' => '10')); - $mform->setType('attemptid', PARAM_INT); - - $mform->addElement('text', 'questionid', 'Question id', array('size' => '10')); - $mform->setType('questionid', PARAM_INT); - - $mform->addElement('header', 'h2', 'Or find and extract an example by type'); - $mform->addElement('select', 'behaviour', 'Behaviour', $behaviour); - $mform->setType('behaviour', PARAM_ALPHA); - - $mform->addElement('text', 'statehistory', 'State history', array('size' => '10')); - $mform->setType('statehistory', PARAM_RAW); - - $mform->addElement('select', 'qtype', 'Question type', $qtypes); - $mform->setType('qtype', PARAM_PLUGIN); - - $mform->addElement('text', 'extratests', 'Extra conditions', array('size' => '50')); - $mform->setType('extratests', PARAM_RAW); - $this->add_action_buttons(false, 'Create test case'); - } -} diff --git a/admin/tool/qeupgradehelper/index.php b/admin/tool/qeupgradehelper/index.php deleted file mode 100644 index 776645a73ce..00000000000 --- a/admin/tool/qeupgradehelper/index.php +++ /dev/null @@ -1,55 +0,0 @@ -. - -/** - * This plugin can help upgrade site with a large number of question attempts - * from Moodle 2.0 to 2.1. - * - * This screen is the main entry-point to the plugin, it gives the admin a list - * of options available to them. - * - * @package tool - * @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', context_system::instance()); -admin_externalpage_setup('qeupgradehelper'); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$actions = array(); -if (tool_qeupgradehelper_is_upgraded()) { - $detected = get_string('upgradedsitedetected', 'tool_qeupgradehelper'); - $actions[] = tool_qeupgradehelper_action::make('listtodo'); - $actions[] = tool_qeupgradehelper_action::make('listupgraded'); - $actions[] = tool_qeupgradehelper_action::make('extracttestcase'); - $actions[] = tool_qeupgradehelper_action::make('cronsetup'); - -} else { - $detected = get_string('oldsitedetected', 'tool_qeupgradehelper'); - $actions[] = tool_qeupgradehelper_action::make('listpreupgrade'); - $actions[] = tool_qeupgradehelper_action::make('extracttestcase'); - $actions[] = tool_qeupgradehelper_action::make('cronsetup'); -} - -echo $renderer->index_page($detected, $actions); diff --git a/admin/tool/qeupgradehelper/lang/en/tool_qeupgradehelper.php b/admin/tool/qeupgradehelper/lang/en/tool_qeupgradehelper.php deleted file mode 100644 index 7bd7c130666..00000000000 --- a/admin/tool/qeupgradehelper/lang/en/tool_qeupgradehelper.php +++ /dev/null @@ -1,83 +0,0 @@ -. - -/** - * Question engine upgrade helper langauge strings. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -$string['action'] = 'Action'; -$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 needing conversion'; -$string['backtoindex'] = 'Back to the main page'; -$string['conversioncomplete'] = 'Conversion complete'; -$string['convertattempts'] = 'Convert attempts'; -$string['convertquiz'] = 'Convert attempts...'; -$string['convertedattempts'] = 'Converted attempts'; -$string['cronenabled'] = 'Cron enabled'; -$string['croninstructions'] = 'You can enable cron to automatically complete the upgrade following a partial upgrade. Cron will run between set hours on the day (according to server local time). Each time cron runs, it will process a number of attempts until Time limit amount of time has been used, then it will stop and wait for the next cron run. Even if you have set up cron, it will not do anything unless it detects that the main upgrade to 2.1 has been completed.'; -$string['cronprocesingtime'] = 'Processing time each cron run'; -$string['cronsetup'] = 'Configure cron'; -$string['cronsetup_desc'] = 'You can configure cron to complete the upgrade of quiz attempt data automatically.'; -$string['cronstarthour'] = 'Start hour'; -$string['cronstophour'] = 'Stop hour'; -$string['extracttestcase'] = 'Extract test case'; -$string['extracttestcase_desc'] = 'Use example data from the database to help create unit tests that can be used to test the upgrade.'; -$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['includedintheupgrade'] = 'Included in the upgrade?'; -$string['invalidquizid'] = 'Invalid quiz id. Either the quiz does not exist, or it has no attempts to convert.'; -$string['listpreupgrade'] = 'List quizzes and attempts'; -$string['listpreupgrade_desc'] = 'This will show a report of all the quizzes on the system and how many attempts they have. This will give you an idea of the scope of the upgrade you have to do.'; -$string['listpreupgradeintro'] = 'These are the number of quiz attempts that will need to be processed when you upgrade your site. A few tens of thousands is no worry. Much beyond that and you need to think about how long the upgrade will take.'; -$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 upgraded quizzes that can be reset'; -$string['listupgraded_desc'] = 'This will show a report of all the quizzes on the system whose attempts have been upgraded, and where the old data is still present so the upgrade could be reset and redone.'; -$string['listupgradedintro'] = 'These are all the quizzes that have attempts that were upgraded, and where the old attempt data is still there, so they could be reset, and the upgrade re-done.'; -$string['noquizattempts'] = 'Your site does not have any quiz attempts at all!'; -$string['nothingupgradedyet'] = 'No upgraded attempts that can be reset'; -$string['notupgradedsiterequired'] = 'This script can only work before the site has been upgraded.'; -$string['numberofattempts'] = 'Number of quiz attempts'; -$string['oldsitedetected'] = 'This appears to be a site that has not yet been upgraded to include the new question engine.'; -$string['outof'] = '{$a->some} out of {$a->total}'; -$string['pluginname'] = 'Question engine upgrade helper'; -$string['pretendupgrade'] = 'Do a dry-run of the attempts upgrade'; -$string['pretendupgrade_desc'] = 'The upgrade does three things: Load the existing data from the database; transform it; then write the transformed data to the DB. This script will test the first two parts of the process.'; -$string['questionsessions'] = 'Question sessions'; -$string['quizid'] = 'Quiz id'; -$string['quizupgrade'] = 'Quiz upgrade status'; -$string['quizzesthatcanbereset'] = 'The following quizzes have converted attempts that you may be able to reset'; -$string['quizzestobeupgraded'] = 'All quizzes with attempts'; -$string['quizzeswithunconverted'] = 'The following quizzes have attempts that need to be converted'; -$string['resetquiz'] = 'Reset attempts...'; -$string['resetcomplete'] = 'Reset complete'; -$string['resettingquizattempts'] = 'Resetting quiz attempts'; -$string['resettingquizattemptsprogress'] = 'Resetting attempt {$a->done} / {$a->outof}'; -$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.'; -$string['upgradedsiterequired'] = 'This script can only work after the site has been upgraded.'; -$string['veryoldattemtps'] = 'Your site has {$a} quiz attempts that were never completely updated during the upgrade from Moodle 1.4 to Moodle 1.5. These attempts will be dealt with before the main upgrade. You need to to consider the extra time required for this.'; diff --git a/admin/tool/qeupgradehelper/lib.php b/admin/tool/qeupgradehelper/lib.php deleted file mode 100644 index a6fc0342206..00000000000 --- a/admin/tool/qeupgradehelper/lib.php +++ /dev/null @@ -1,93 +0,0 @@ -. - -/** - * Lib functions (cron) to automatically complete the question engine upgrade - * if it was not done all at once during the main upgrade. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -/** - * Standard cron function - */ -function tool_qeupgradehelper_cron() { - $settings = get_config('tool_qeupgradehelper'); - if (empty($settings->cronenabled)) { - return; - } - - mtrace('qeupgradehelper: tool_qeupgradehelper_cron() started at '. date('H:i:s')); - try { - tool_qeupgradehelper_process($settings); - } catch (Exception $e) { - mtrace('qeupgradehelper: tool_qeupgradehelper_cron() failed with an exception:'); - mtrace($e->getMessage()); - } - mtrace('qeupgradehelper: tool_qeupgradehelper_cron() finished at ' . date('H:i:s')); -} - -/** - * This function does the cron process within the time range according to settings. - */ -function tool_qeupgradehelper_process($settings) { - global $CFG; - require_once(dirname(__FILE__) . '/locallib.php'); - - if (!tool_qeupgradehelper_is_upgraded()) { - mtrace('qeupgradehelper: site not yet upgraded. Doing nothing.'); - return; - } - - require_once(dirname(__FILE__) . '/afterupgradelib.php'); - - $hour = (int) date('H'); - if ($hour < $settings->starthour || $hour >= $settings->stophour) { - mtrace('qeupgradehelper: not between starthour and stophour, so doing nothing (hour = ' . - $hour . ').'); - return; - } - - $stoptime = time() + $settings->procesingtime; - - mtrace('qeupgradehelper: processing ...'); - while (time() < $stoptime) { - - $quiz = tool_qeupgradehelper_get_quiz_for_upgrade(); - if (!$quiz) { - mtrace('qeupgradehelper: No more quizzes to process. You should probably disable the qeupgradehelper cron settings now.'); - break; // No more to do; - } - - $quizid = $quiz->id; - $quizsummary = tool_qeupgradehelper_get_quiz($quizid); - if ($quizsummary) { - mtrace(' starting upgrade of attempts at quiz ' . $quizid); - $upgrader = new tool_qeupgradehelper_attempt_upgrader( - $quizsummary->id, $quizsummary->numtoconvert); - $upgrader->convert_all_quiz_attempts(); - mtrace(' upgrade of quiz ' . $quizid . ' complete.'); - } - } - - mtrace('qeupgradehelper: Done.'); - return; -} diff --git a/admin/tool/qeupgradehelper/listpreupgrade.php b/admin/tool/qeupgradehelper/listpreupgrade.php deleted file mode 100644 index ee15a094a80..00000000000 --- a/admin/tool/qeupgradehelper/listpreupgrade.php +++ /dev/null @@ -1,61 +0,0 @@ -. - -/** - * Script to show all the quizzes in the site with how many attempts they have - * that will need to be upgraded. - * - * @package tool - * @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', context_system::instance()); -tool_qeupgradehelper_require_not_upgraded(); - -admin_externalpage_setup('qeupgradehelper', '', array(), tool_qeupgradehelper_url('')); -$PAGE->navbar->add(get_string('listpreupgrade', 'tool_qeupgradehelper')); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$quizzes = new tool_qeupgradehelper_pre_upgrade_quiz_list(); - -// Look to see if the admin has set things up to only upgrade certain attempts. -$partialupgradefile = $CFG->dirroot . '/' . $CFG->admin . '/tool/qeupgradehelper/partialupgrade.php'; -$partialupgradefunction = 'tool_qeupgradehelper_get_quizzes_to_upgrade'; -if (is_readable($partialupgradefile)) { - include_once($partialupgradefile); - if (function_exists($partialupgradefunction)) { - $quizzes = new tool_qeupgradehelper_pre_upgrade_quiz_list_restricted( - $partialupgradefunction()); - } -} - -$numveryoldattemtps = tool_qeupgradehelper_get_num_very_old_attempts(); - -if ($quizzes->is_empty()) { - echo $renderer->simple_message_page(get_string('noquizattempts', 'tool_qeupgradehelper')); - -} else { - echo $renderer->quiz_list_page($quizzes, $numveryoldattemtps); -} diff --git a/admin/tool/qeupgradehelper/listtodo.php b/admin/tool/qeupgradehelper/listtodo.php deleted file mode 100644 index 83062ea7a52..00000000000 --- a/admin/tool/qeupgradehelper/listtodo.php +++ /dev/null @@ -1,49 +0,0 @@ -. - -/** - * Script to show all the quizzes with attempts that still need to be upgraded - * after the main upgrade. - * - * @package tool - * @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', context_system::instance()); -tool_qeupgradehelper_require_upgraded(); - -admin_externalpage_setup('qeupgradehelper', '', array(), - tool_qeupgradehelper_url('listtodo')); -$PAGE->navbar->add(get_string('listtodo', 'tool_qeupgradehelper')); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$quizzes = new tool_qeupgradehelper_upgradable_quiz_list(); - -if ($quizzes->is_empty()) { - echo $renderer->simple_message_page(get_string('alreadydone', 'tool_qeupgradehelper')); - -} else { - echo $renderer->quiz_list_page($quizzes); -} diff --git a/admin/tool/qeupgradehelper/listupgraded.php b/admin/tool/qeupgradehelper/listupgraded.php deleted file mode 100644 index 187f75e984d..00000000000 --- a/admin/tool/qeupgradehelper/listupgraded.php +++ /dev/null @@ -1,50 +0,0 @@ -. - -/** - * 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 tool - * @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', context_system::instance()); -tool_qeupgradehelper_require_upgraded(); - -admin_externalpage_setup('qeupgradehelper', '', array(), - tool_qeupgradehelper_url('listupgraded')); -$PAGE->navbar->add(get_string('listupgraded', 'tool_qeupgradehelper')); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$quizzes = new tool_qeupgradehelper_resettable_quiz_list(); - -if ($quizzes->is_empty()) { - echo $renderer->simple_message_page(get_string('nothingupgradedyet', 'tool_qeupgradehelper')); - -} else { - echo $renderer->quiz_list_page($quizzes); -} diff --git a/admin/tool/qeupgradehelper/locallib.php b/admin/tool/qeupgradehelper/locallib.php deleted file mode 100644 index 2c1d933f69c..00000000000 --- a/admin/tool/qeupgradehelper/locallib.php +++ /dev/null @@ -1,674 +0,0 @@ -. - -/** - * Question engine upgrade helper library code. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -defined('MOODLE_INTERNAL') || die(); - - -/** - * Detect whether this site has been upgraded to the new question engine yet. - * @return bool whether the site has been upgraded. - */ -function tool_qeupgradehelper_is_upgraded() { - global $CFG, $DB; - $dbman = $DB->get_manager(); - return is_readable($CFG->dirroot . '/question/engine/upgrade/upgradelib.php') && - $dbman->table_exists('question_usages'); -} - -/** - * If the site has not yet been upgraded, display an error. - */ -function tool_qeupgradehelper_require_upgraded() { - if (!tool_qeupgradehelper_is_upgraded()) { - throw new moodle_exception('upgradedsiterequired', 'tool_qeupgradehelper', - tool_qeupgradehelper_url('index')); - } -} - -/** - * If the site has been upgraded, display an error. - */ -function tool_qeupgradehelper_require_not_upgraded() { - if (tool_qeupgradehelper_is_upgraded()) { - throw new moodle_exception('notupgradedsiterequired', 'tool_qeupgradehelper', - tool_qeupgradehelper_url('index')); - } -} - -/** - * 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 tool_qeupgradehelper_url($script, $params = array()) { - return new moodle_url('/admin/tool/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 tool_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, 'tool_qeupgradehelper'), - tool_qeupgradehelper_url($shortname, $params), - get_string($shortname . '_desc', 'tool_qeupgradehelper')); - } -} - - -/** - * A class to represent a list of quizzes with various information about - * attempts that can be displayed as a table. - * - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -abstract class tool_qeupgradehelper_quiz_list { - public $title; - public $intro; - public $quizacolheader; - public $sql; - public $quizlist = null; - public $totalquizas = 0; - public $totalqas = 0; - - protected function __construct($title, $intro, $quizacolheader) { - global $DB; - $this->title = get_string($title, 'tool_qeupgradehelper'); - $this->intro = get_string($intro, 'tool_qeupgradehelper'); - $this->quizacolheader = get_string($quizacolheader, 'tool_qeupgradehelper'); - $this->build_sql(); - $this->quizlist = $DB->get_records_sql($this->sql); - } - - protected function build_sql() { - $this->sql = ' - SELECT - quiz.id, - quiz.name, - c.shortname, - c.id AS courseid, - COUNT(1) AS attemptcount, - SUM(qsesscounts.num) AS questionattempts - - FROM {quiz_attempts} quiza - JOIN {quiz} quiz ON quiz.id = quiza.quiz - JOIN {course} c ON c.id = quiz.course - LEFT JOIN ( - SELECT attemptid, COUNT(1) AS num - FROM {question_sessions} - GROUP BY attemptid - ) qsesscounts ON qsesscounts.attemptid = quiza.uniqueid - - WHERE quiza.preview = 0 - ' . $this->extra_where_clause() . ' - - GROUP BY quiz.id, quiz.name, c.shortname, c.id - - ORDER BY c.shortname, quiz.name, quiz.id'; - } - - abstract protected function extra_where_clause(); - - public function get_col_headings() { - return array( - get_string('quizid', 'tool_qeupgradehelper'), - get_string('course'), - get_string('pluginname', 'quiz'), - $this->quizacolheader, - get_string('questionsessions', 'tool_qeupgradehelper'), - ); - } - - public function get_row($quizinfo) { - $this->totalquizas += $quizinfo->attemptcount; - $this->totalqas += $quizinfo->questionattempts; - return array( - $quizinfo->id, - html_writer::link(new moodle_url('/course/view.php', - array('id' => $quizinfo->courseid)), format_string($quizinfo->shortname)), - html_writer::link(new moodle_url('/mod/quiz/view.php', - array('q' => $quizinfo->id)), format_string($quizinfo->name)), - $quizinfo->attemptcount, - $quizinfo->questionattempts ? $quizinfo->questionattempts : 0, - ); - } - - public function get_row_class($quizinfo) { - return null; - } - - public function get_total_row() { - return array( - '', - html_writer::tag('b', get_string('total')), - '', - html_writer::tag('b', $this->totalquizas), - html_writer::tag('b', $this->totalqas), - ); - } - - public function is_empty() { - return empty($this->quizlist); - } -} - - -/** - * A list of quizzes that still need to be upgraded after the main upgrade. - * - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class tool_qeupgradehelper_upgradable_quiz_list extends tool_qeupgradehelper_quiz_list { - public function __construct() { - parent::__construct('quizzeswithunconverted', 'listtodointro', 'attemptstoconvert'); - } - - protected function extra_where_clause() { - return 'AND quiza.needsupgradetonewqe = 1'; - } - - public function get_col_headings() { - $headings = parent::get_col_headings(); - $headings[] = get_string('action', 'tool_qeupgradehelper'); - return $headings; - } - - public function get_row($quizinfo) { - $row = parent::get_row($quizinfo); - $row[] = html_writer::link(tool_qeupgradehelper_url('convertquiz', array('quizid' => $quizinfo->id)), - get_string('convertquiz', 'tool_qeupgradehelper')); - return $row; - } -} - - -/** - * A list of quizzes that still need to be upgraded after the main upgrade. - * - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class tool_qeupgradehelper_resettable_quiz_list extends tool_qeupgradehelper_quiz_list { - public function __construct() { - parent::__construct('quizzesthatcanbereset', 'listupgradedintro', 'convertedattempts'); - } - - protected function extra_where_clause() { - return 'AND quiza.needsupgradetonewqe = 0 - AND EXISTS(SELECT 1 FROM {question_states} - WHERE attempt = quiza.uniqueid)'; - } - - public function get_col_headings() { - $headings = parent::get_col_headings(); - $headings[] = get_string('action', 'tool_qeupgradehelper'); - return $headings; - } - - public function get_row($quizinfo) { - $row = parent::get_row($quizinfo); - $row[] = html_writer::link(tool_qeupgradehelper_url('resetquiz', array('quizid' => $quizinfo->id)), - get_string('resetquiz', 'tool_qeupgradehelper')); - return $row; - } -} - - -/** - * A list of quizzes that will be upgraded during the main upgrade. - * - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class tool_qeupgradehelper_pre_upgrade_quiz_list extends tool_qeupgradehelper_quiz_list { - public function __construct() { - parent::__construct('quizzestobeupgraded', 'listpreupgradeintro', 'numberofattempts'); - } - - protected function extra_where_clause() { - return ''; - } -} - - -/** - * A list of quizzes that will be upgraded during the main upgrade, when the - * partialupgrade.php script is being used. - * - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class tool_qeupgradehelper_pre_upgrade_quiz_list_restricted extends tool_qeupgradehelper_pre_upgrade_quiz_list { - protected $quizids; - protected $restrictedtotalquizas = 0; - protected $restrictedtotalqas = 0; - - public function __construct($quizids) { - parent::__construct(); - $this->quizids = $quizids; - } - - public function get_row_class($quizinfo) { - if (!in_array($quizinfo->id, $this->quizids)) { - return 'dimmed'; - } else { - return parent::get_row_class($quizinfo); - } - } - - public function get_col_headings() { - $headings = parent::get_col_headings(); - $headings[] = get_string('includedintheupgrade', 'tool_qeupgradehelper'); - return $headings; - } - - public function get_row($quizinfo) { - $row = parent::get_row($quizinfo); - if (in_array($quizinfo->id, $this->quizids)) { - $this->restrictedtotalquizas += $quizinfo->attemptcount; - $this->restrictedtotalqas += $quizinfo->questionattempts; - $row[] = get_string('yes'); - } else { - $row[] = get_string('no'); - } - return $row; - } - - protected function out_of($restrictedtotal, $fulltotal) { - $a = new stdClass(); - $a->some = $a->some = html_writer::tag('b', $restrictedtotal); - $a->total = $fulltotal; - return get_string('outof', 'tool_qeupgradehelper', $a); - } - - public function get_total_row() { - return array( - '', - html_writer::tag('b', get_string('total')), - '', - $this->out_of($this->restrictedtotalquizas, $this->totalquizas), - $this->out_of($this->restrictedtotalqas, $this->totalqas), - ); - } -} - - -/** - * List the number of quiz attempts that were never upgraded from 1.4 -> 1.5. - * @return int the number of such attempts. - */ -function tool_qeupgradehelper_get_num_very_old_attempts() { - global $DB; - return $DB->count_records_sql(' - SELECT COUNT(1) - FROM {quiz_attempts} quiza - WHERE uniqueid IN ( - SELECT DISTINCT qst.attempt - FROM {question_states} qst - LEFT JOIN {question_sessions} qsess ON - qst.question = qsess.questionid AND qst.attempt = qsess.attemptid - WHERE qsess.id IS NULL)'); -} - -/** - * 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 tool_qeupgradehelper_get_upgradable_quizzes()}. - */ -function tool_qeupgradehelper_get_quiz($quizid) { - global $DB; - return $DB->get_record_sql(" - SELECT - quiz.id, - quiz.name, - c.shortname, - c.id AS courseid, - COUNT(1) AS numtoconvert - - 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 = ? - - GROUP BY quiz.id, quiz.name, c.shortname, c.id - - ORDER BY c.shortname, quiz.name, quiz.id", array($quizid)); -} - -/** - * 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 tool_qeupgradehelper_get_resettable_quizzes()}, but with extra fields - * totalattempts and resettableattempts. - */ -function tool_qeupgradehelper_get_resettable_quiz($quizid) { - global $DB; - return $DB->get_record_sql(" - SELECT - quiz.id, - quiz.name, - c.shortname, - c.id AS courseid, - COUNT(1) AS totalattempts, - SUM(CASE WHEN quiza.needsupgradetonewqe = 0 AND - oldtimemodified.time IS NOT NULL THEN 1 ELSE 0 END) AS convertedattempts, - SUM(CASE WHEN quiza.needsupgradetonewqe = 0 AND - newtimemodified.time IS NULL OR oldtimemodified.time >= newtimemodified.time - THEN 1 ELSE 0 END) AS resettableattempts - - FROM {quiz_attempts} quiza - JOIN {quiz} quiz ON quiz.id = quiza.quiz - JOIN {course} c ON c.id = quiz.course - LEFT JOIN ( - SELECT attempt, MAX(timestamp) AS time - FROM {question_states} - GROUP BY attempt - ) AS oldtimemodified ON oldtimemodified.attempt = quiza.uniqueid - LEFT JOIN ( - SELECT qa.questionusageid, MAX(qas.timecreated) AS time - FROM {question_attempts} qa - JOIN {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 quiz.id = ? - - GROUP BY quiz.id, quiz.name, c.shortname, c.id", array($quizid)); -} - -/** - * Get a question session id form a quiz attempt id and a question id. - * @param int $attemptid a quiz attempt id. - * @param int $questionid a question id. - * @return int the question session id. - */ -function tool_qeupgradehelper_get_session_id($attemptid, $questionid) { - global $DB; - $attempt = $DB->get_record('quiz_attempts', array('id' => $attemptid)); - if (!$attempt) { - return null; - } - return $DB->get_field('question_sessions', 'id', - array('attemptid' => $attempt->uniqueid, 'questionid' => $questionid)); -} - -/** - * Identify the question session id of a question attempt matching certain - * requirements. - * @param integer $behaviour 0 = deferred feedback, 1 = interactive. - * @param string $statehistory of states, last first. E.g. 620. - * @param string $qtype question type. - * @return integer question_session.id. - */ -function tool_qeupgradehelper_find_test_case($behaviour, $statehistory, $qtype, $extratests) { - global $DB; - - $params = array( - 'qtype' => $qtype, - 'statehistory' => $statehistory - ); - - if ($behaviour == 'deferredfeedback') { - $extrawhere = ''; - $params['optionflags'] = 0; - - } else if ($behaviour == 'adaptive') { - $extrawhere = 'AND penaltyscheme = :penaltyscheme'; - $params['optionflags'] = 0; - $params['penaltyscheme'] = 0; - - } else { - $extrawhere = 'AND penaltyscheme = :penaltyscheme'; - $params['optionflags'] = 0; - $params['penaltyscheme'] = 1; - } - - $possibleids = $DB->get_records_sql_menu(' - SELECT - qsess.id, - 1 - - FROM {question_sessions} qsess - JOIN {question_states} qst ON qst.attempt = qsess.attemptid - AND qst.question = qsess.questionid - JOIN {quiz_attempts} quiza ON quiza.uniqueid = qsess.attemptid - JOIN {quiz} quiz ON quiz.id = quiza.quiz - JOIN {question} q ON q.id = qsess.questionid - - WHERE q.qtype = :qtype - AND quiz.optionflags = :optionflags - ' . $extrawhere . ' - - GROUP BY - qsess.id - - HAVING SUM( - (CASE WHEN qst.event = 10 THEN 1 ELSE qst.event END) * - POWER(10, CAST(qst.seq_number AS NUMERIC(110,0))) - ) = :statehistory' . $extratests, $params, 0, 100); - - if (!$possibleids) { - return null; - } - - return array_rand($possibleids); -} - -/** - * Grab all the data that upgrade will need for upgrading one - * attempt at one question from the old DB. - */ -function tool_qeupgradehelper_generate_unit_test($questionsessionid, $namesuffix) { - global $DB; - - $qsession = $DB->get_record('question_sessions', array('id' => $questionsessionid)); - $attempt = $DB->get_record('quiz_attempts', array('uniqueid' => $qsession->attemptid)); - $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz)); - $qstates = $DB->get_records('question_states', - array('attempt' => $qsession->attemptid, 'question' => $qsession->questionid), - 'seq_number, id'); - - $question = tool_qeupgradehelper_load_question($qsession->questionid, $quiz->id); - - if (!tool_qeupgradehelper_is_upgraded()) { - if (!$quiz->optionflags) { - $quiz->preferredbehaviour = 'deferredfeedback'; - } else if ($quiz->penaltyscheme) { - $quiz->preferredbehaviour = 'adaptive'; - } else { - $quiz->preferredbehaviour = 'adaptivenopenalty'; - } - unset($quiz->optionflags); - unset($quiz->penaltyscheme); - - $question->defaultmark = $question->defaultgrade; - unset($question->defaultgrade); - } - - $attempt->needsupgradetonewqe = 1; - - echo ''; -} - -function tool_qeupgradehelper_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); - $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('/\bNULL\b/', 'null', $out); - return " $name = $out;\n"; -} - -function tool_qeupgradehelper_display_convert_attempt_input($quiz, $attempt, - $question, $qsession, $qstates) { - echo tool_qeupgradehelper_format_var('$quiz', $quiz); - echo tool_qeupgradehelper_format_var('$attempt', $attempt); - echo tool_qeupgradehelper_format_var('$question', $question); - echo tool_qeupgradehelper_format_var('$qsession', $qsession); - echo tool_qeupgradehelper_format_var('$qstates', $qstates); -} - -function tool_qeupgradehelper_load_question($questionid, $quizid) { - global $CFG, $DB; - - $question = $DB->get_record_sql(' - SELECT q.*, qqi.maxmark - FROM {question} q - JOIN {quiz_question_instances} qqi ON qqi.questionid = q.id - WHERE q.id = :questionid AND qqi.quizid = :quizid', - array('questionid' => $questionid, 'quizid' => $quizid)); - - if (tool_qeupgradehelper_is_upgraded()) { - require_once($CFG->dirroot . '/question/engine/bank.php'); - $qtype = question_bank::get_qtype($question->qtype, false); - } else { - global $QTYPES; - if (!array_key_exists($question->qtype, $QTYPES)) { - $question->qtype = 'missingtype'; - $question->questiontext = '

' . get_string('warningmissingtype', 'quiz') . '

' . $question->questiontext; - } - $qtype = $QTYPES[$question->qtype]; - } - - $qtype->get_question_options($question); - - return $question; -} - -function tool_qeupgradehelper_get_quiz_for_upgrade() { - global $DB; - - return $DB->get_record_sql("SELECT quiz.id - 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 - GROUP BY quiz.id, quiz.name, c.shortname, c.id - ORDER BY MAX(quiza.timemodified) DESC", array(), IGNORE_MULTIPLE); -} diff --git a/admin/tool/qeupgradehelper/partialupgrade-example.php b/admin/tool/qeupgradehelper/partialupgrade-example.php deleted file mode 100644 index 3617b5aa713..00000000000 --- a/admin/tool/qeupgradehelper/partialupgrade-example.php +++ /dev/null @@ -1,115 +0,0 @@ -. - -/** - * Example script, showing how it is possible to only do a part-upgrade of the - * attempt data during the main upgrade, and then finish the job off later. - * - * If you want to use this facility, then you need to: - * - * 1. Rename this script to partialupgrade.php. - * 2. Look at the various example functions below for controlling the upgrade, - * chooose one you like, and un-comment it. Alternatively, write your own - * custom function. - * 3. Use the List quizzes and attempts options in this plugin, which should now - * display updated information. - * 4. Once you are sure that works, you can proceed with the upgrade as usual. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -/** - * This is a very simple example that just uses a hard-coded array to control - * which attempts are upgraded. - * - * @return array of quiz ids that are the ones to upgrade during the main - * upgrade from 2.0 to 2.1. Attempts at other quizzes are left alone, you will - * have to take steps to upgrade them yourself using the facilities provided by - * this plugin. - */ -//function tool_qeupgradehelper_get_quizzes_to_upgrade() { -// return array(1, 2, 3); -//} - - -/** - * This example function uses a list of quiz ids from a file. - * - * It is currently set to use the file quiz-ids-to-upgrade.txt in the same - * folder as this script, but you can change that if you like. - * - * That file should contain one quiz id per line, with no punctuation. Any line - * that does not look like an integer is ignored. - * - * @return array of quiz ids that are the ones to upgrade during the main - * upgrade from 2.0 to 2.1. Attempts at other quizzes are left alone, you will - * have to take steps to upgrade them yourself using the facilities provided by - * this plugin. - */ -//function tool_qeupgradehelper_get_quizzes_to_upgrade() { -// global $CFG; -// $rawids = file($CFG->dirroot . '/' . $CFG->admin . '/tool/qeupgradehelper/quiz-ids-to-upgrade.txt'); -// $cleanids = array(); -// foreach ($rawids as $id) { -// $id = clean_param($id, PARAM_INT); -// if ($id) { -// $cleanids[] = $id; -// } -// } -// return $cleanids; -//} - - -/** - * This example uses a complex SQL query to decide which attempts to upgrade. - * - * The particular example I have done here is to return the ids of all the quizzes - * in courses that started more recently than one year ago. Of coures, you can - * write any query you like to meet your needs. - * - * Remember that you can use the List quizzes and attempts options option provided - * by this plugin to verify that your query is selecting the quizzes you intend. - * - * @return array of quiz ids that are the ones to upgrade during the main - * upgrade from 2.0 to 2.1. Attempts at other quizzes are left alone, you will - * have to take steps to upgrade them yourself using the facilities provided by - * this plugin. - */ -//function tool_qeupgradehelper_get_quizzes_to_upgrade() { -// global $DB; -// -// $quizmoduleid = $DB->get_field('modules', 'id', array('name' => 'quiz')); -// -// $oneyearago = strtotime('-1 year'); -// -// return $DB->get_fieldset_sql(' -// SELECT DISTINCT quiz.id -// -// FROM {quiz} quiz -// JOIN {course_modules} cm ON cm.module = :quizmoduleid -// AND cm.instance = quiz.id -// JOIN {course} c ON quiz.course = c.id -// -// WHERE c.startdate > :cutoffdate -// -// ORDER BY quiz.id -// ', array('quizmoduleid' => $quizmoduleid, 'cutoffdate' => $oneyearago)); -// "); -//} diff --git a/admin/tool/qeupgradehelper/renderer.php b/admin/tool/qeupgradehelper/renderer.php deleted file mode 100644 index 6d291edfbd1..00000000000 --- a/admin/tool/qeupgradehelper/renderer.php +++ /dev/null @@ -1,168 +0,0 @@ -. - -/** - * Defines the renderer for the question engine upgrade helper plugin. - * - * @package tool - * @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 tool_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', 'tool_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 the list of quizzes that still need to be upgraded page. - * @param array $quizzes of data about quizzes. - * @param int $numveryoldattemtps only relevant before upgrade. - * @return string html to output. - */ - public function quiz_list_page(tool_qeupgradehelper_quiz_list $quizzes, - $numveryoldattemtps = null) { - $output = ''; - $output .= $this->header(); - $output .= $this->heading($quizzes->title); - $output .= $this->box($quizzes->intro); - - $table = new html_table(); - $table->head = $quizzes->get_col_headings(); - - $rowcount = 0; - foreach ($quizzes->quizlist as $quizinfo) { - $table->data[$rowcount] = $quizzes->get_row($quizinfo); - if ($class = $quizzes->get_row_class($quizinfo)) { - $table->rowclasses[$rowcount] = $class; - } - $rowcount += 1; - } - $table->data[] = $quizzes->get_total_row(); - $output .= html_writer::table($table); - - if ($numveryoldattemtps) { - $output .= $this->box(get_string('veryoldattemtps', 'tool_qeupgradehelper', - $numveryoldattemtps)); - } - - $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', 'tool_qeupgradehelper')); - - $params = array('quizid' => $quizsummary->id, 'confirmed' => 1, 'sesskey' => sesskey()); - $output .= $this->confirm(get_string('areyousuremessage', 'tool_qeupgradehelper', $quizsummary), - new single_button(tool_qeupgradehelper_url('convertquiz', $params), get_string('yes')), - tool_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', 'tool_qeupgradehelper')); - - $params = array('quizid' => $quizsummary->id, 'confirmed' => 1, 'sesskey' => sesskey()); - $output .= $this->confirm(get_string('areyousureresetmessage', 'tool_qeupgradehelper', $quizsummary), - new single_button(tool_qeupgradehelper_url('resetquiz', $params), get_string('yes')), - tool_qeupgradehelper_url('listupgraded')); - - $output .= $this->footer(); - return $output; - } - - /** - * 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(tool_qeupgradehelper_url('index'), - get_string('backtoindex', 'tool_qeupgradehelper')); - } -} diff --git a/admin/tool/qeupgradehelper/resetquiz.php b/admin/tool/qeupgradehelper/resetquiz.php deleted file mode 100644 index 1029cb23e24..00000000000 --- a/admin/tool/qeupgradehelper/resetquiz.php +++ /dev/null @@ -1,72 +0,0 @@ -. - -/** - * Script to reset the upgrade of attempts at a particular quiz, after confirmation. - * - * @package tool - * @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(dirname(__FILE__) . '/afterupgradelib.php'); -require_once($CFG->libdir . '/adminlib.php'); - -$quizid = required_param('quizid', PARAM_INT); -$confirmed = optional_param('confirmed', false, PARAM_BOOL); - -require_login(); -require_capability('moodle/site:config', context_system::instance()); -tool_qeupgradehelper_require_upgraded(); - -admin_externalpage_setup('qeupgradehelper', '', array(), - tool_qeupgradehelper_url('resetquiz', array('quizid' => $quizid))); -$PAGE->navbar->add(get_string('listupgraded', 'tool_qeupgradehelper'), - tool_qeupgradehelper_url('listtodo')); -$PAGE->navbar->add(get_string('resetquiz', 'tool_qeupgradehelper')); - -$renderer = $PAGE->get_renderer('tool_qeupgradehelper'); - -$quizsummary = tool_qeupgradehelper_get_resettable_quiz($quizid); -if (!$quizsummary) { - print_error('invalidquizid', 'tool_qeupgradehelper', - tool_qeupgradehelper_url('listupgraded')); -} - -$quizsummary->name = format_string($quizsummary->name); - -if ($confirmed && data_submitted() && confirm_sesskey()) { - // Actually do the conversion. - echo $renderer->header(); - echo $renderer->heading(get_string( - 'resettingquizattempts', 'tool_qeupgradehelper', $quizsummary)); - - $upgrader = new tool_qeupgradehelper_attempt_upgrader( - $quizsummary->id, $quizsummary->resettableattempts); - $upgrader->reset_all_resettable_attempts(); - - echo $renderer->heading(get_string('resetcomplete', 'tool_qeupgradehelper')); - echo $renderer->end_of_page_link(tool_qeupgradehelper_url('listupgraded'), - get_string('listupgraded', 'tool_qeupgradehelper')); - - echo $renderer->footer(); - exit; -} - -echo $renderer->reset_quiz_are_you_sure($quizsummary); diff --git a/admin/tool/qeupgradehelper/settings.php b/admin/tool/qeupgradehelper/settings.php deleted file mode 100644 index 8e88a01f808..00000000000 --- a/admin/tool/qeupgradehelper/settings.php +++ /dev/null @@ -1,32 +0,0 @@ -. - -/** - * Adds this plugin to the admin menu. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -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', 'tool_qeupgradehelper'), - new moodle_url('/admin/tool/qeupgradehelper/index.php'))); -} diff --git a/admin/tool/qeupgradehelper/styles.css b/admin/tool/qeupgradehelper/styles.css deleted file mode 100644 index 16ad9769c33..00000000000 --- a/admin/tool/qeupgradehelper/styles.css +++ /dev/null @@ -1,6 +0,0 @@ -#page-admin-tool-qeupgradehelper-index .dimmed { - color: grey; -} -#page-admin-tool-qeupgradehelper-index .dimmed a { - color: #88c; -} diff --git a/admin/tool/qeupgradehelper/version.php b/admin/tool/qeupgradehelper/version.php deleted file mode 100644 index 71db5b9b179..00000000000 --- a/admin/tool/qeupgradehelper/version.php +++ /dev/null @@ -1,30 +0,0 @@ -. - -/** - * Version details. - * - * @package tool - * @subpackage qeupgradehelper - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$plugin->version = 2013110500; -$plugin->requires = 2013110500; -$plugin->component = 'tool_qeupgradehelper'; // Full name of the plugin (used for diagnostics) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 973d4afa746..92507af1891 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2996,5 +2996,14 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2014020500.00); } + if ($oldversion < 2014021300.01) { + // Force uninstall of deleted tool. + if (!file_exists("$CFG->dirroot/$CFG->admin/tool/qeupgradehelper")) { + // Remove all other associated config. + unset_all_config_for_plugin('tool_qeupgradehelper'); + } + upgrade_main_savepoint(true, 2014021300.01); + } + return true; } diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 3f53612f670..d323d743050 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -348,27 +348,29 @@ function upgrade_stale_php_files_present() { global $CFG; $someexamplesofremovedfiles = array( - // removed in 2.6dev + // Removed in 2.7. + '/admin/tool/qeupgradehelper/version.php', + // Removed in 2.6. '/admin/block.php', '/admin/oacleanup.php', - // removed in 2.5dev + // Removed in 2.5. '/backup/lib.php', '/backup/bb/README.txt', '/lib/excel/test.php', - // removed in 2.4dev + // Removed in 2.4. '/admin/tool/unittest/simpletestlib.php', - // removed in 2.3dev + // Removed in 2.3. '/lib/minify/builder/', - // removed in 2.2dev + // Removed in 2.2. '/lib/yui/3.4.1pr1/', - // removed in 2.2 + // Removed in 2.2. '/search/cron_php5.php', '/course/report/log/indexlive.php', '/admin/report/backups/index.php', '/admin/generator.php', - // removed in 2.1 + // Removed in 2.1. '/lib/yui/2.8.0r4/', - // removed in 2.0 + // Removed in 2.0. '/blocks/admin/block_admin.php', '/blocks/admin_tree/block_admin_tree.php', ); diff --git a/question/engine/upgrade/upgradelib.php b/question/engine/upgrade/upgradelib.php index 249e1f1e9dd..f22683cb2d8 100644 --- a/question/engine/upgrade/upgradelib.php +++ b/question/engine/upgrade/upgradelib.php @@ -45,182 +45,6 @@ class question_engine_attempt_upgrader { protected $questionloader; /** @var question_engine_assumption_logger */ protected $logger; - /** @var int used by {@link prevent_timeout()}. */ - protected $dotcounter = 0; - /** @var progress_bar */ - protected $progressbar = null; - /** @var boolean */ - protected $doingbackup = false; - - /** - * Called before starting to upgrade all the attempts at a particular quiz. - * @param int $done the number of quizzes processed so far. - * @param int $outof the total number of quizzes to process. - * @param int $quizid the id of the quiz that is about to be processed. - */ - protected function print_progress($done, $outof, $quizid) { - if (is_null($this->progressbar)) { - $this->progressbar = new progress_bar('qe2upgrade'); - $this->progressbar->create(); - } - - gc_collect_cycles(); // This was really helpful in PHP 5.2. Perhaps remove. - $a = new stdClass(); - $a->done = $done; - $a->outof = $outof; - $a->info = $quizid; - $this->progressbar->update($done, $outof, get_string('upgradingquizattempts', 'quiz', $a)); - } - - protected function prevent_timeout() { - core_php_time_limit::raise(300); - if ($this->doingbackup) { - return; - } - echo '.'; - $this->dotcounter += 1; - if ($this->dotcounter % 100 == 0) { - echo '
'; - } - } - - protected function get_quiz_ids() { - global $CFG, $DB; - - // Look to see if the admin has set things up to only upgrade certain attempts. - $partialupgradefile = $CFG->dirroot . '/' . $CFG->admin . - '/tool/qeupgradehelper/partialupgrade.php'; - $partialupgradefunction = 'tool_qeupgradehelper_get_quizzes_to_upgrade'; - if (is_readable($partialupgradefile)) { - include_once($partialupgradefile); - if (function_exists($partialupgradefunction)) { - $quizids = $partialupgradefunction(); - - // Ignore any quiz ids that do not acually exist. - if (empty($quizids)) { - return array(); - } - list($test, $params) = $DB->get_in_or_equal($quizids); - return $DB->get_fieldset_sql(" - SELECT id - FROM {quiz} - WHERE id $test - ORDER BY id", $params); - } - } - - // Otherwise, upgrade all attempts. - return $DB->get_fieldset_sql('SELECT id FROM {quiz} ORDER BY id'); - } - - public function convert_all_quiz_attempts() { - global $DB; - - $quizids = $this->get_quiz_ids(); - if (empty($quizids)) { - return true; - } - - $done = 0; - $outof = count($quizids); - $this->logger = new question_engine_assumption_logger(); - - foreach ($quizids as $quizid) { - $this->print_progress($done, $outof, $quizid); - - $quiz = $DB->get_record('quiz', array('id' => $quizid), '*', MUST_EXIST); - $this->update_all_attempts_at_quiz($quiz); - - $done += 1; - } - - $this->print_progress($outof, $outof, 'All done!'); - $this->logger = null; - } - - public function get_attempts_extra_where() { - return ' AND needsupgradetonewqe = 1'; - } - - public function update_all_attempts_at_quiz($quiz) { - global $DB; - - // Wipe question loader cache. - $this->questionloader = new question_engine_upgrade_question_loader($this->logger); - - $transaction = $DB->start_delegated_transaction(); - - $params = array('quizid' => $quiz->id); - $where = 'quiz = :quizid AND preview = 0' . $this->get_attempts_extra_where(); - - $quizattemptsrs = $DB->get_recordset_select('quiz_attempts', $where, $params, 'uniqueid'); - $questionsessionsrs = $DB->get_recordset_sql(" - SELECT s.* - FROM {question_sessions} s - JOIN {quiz_attempts} a ON (attemptid = uniqueid) - WHERE $where - ORDER BY attemptid, questionid - ", $params); - - $questionsstatesrs = $DB->get_recordset_sql(" - SELECT s.* - FROM {question_states} s - JOIN {quiz_attempts} ON (s.attempt = uniqueid) - WHERE $where - ORDER BY s.attempt, question, seq_number, s.id - ", $params); - - $datatodo = $quizattemptsrs && $questionsessionsrs && $questionsstatesrs; - while ($datatodo && $quizattemptsrs->valid()) { - $attempt = $quizattemptsrs->current(); - $quizattemptsrs->next(); - $this->convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs); - } - - $quizattemptsrs->close(); - $questionsessionsrs->close(); - $questionsstatesrs->close(); - - $transaction->allow_commit(); - } - - protected function convert_quiz_attempt($quiz, $attempt, moodle_recordset $questionsessionsrs, - moodle_recordset $questionsstatesrs) { - $qas = array(); - $this->logger->set_current_attempt_id($attempt->id); - while ($qsession = $this->get_next_question_session($attempt, $questionsessionsrs)) { - $question = $this->load_question($qsession->questionid, $quiz->id); - $qstates = $this->get_question_states($attempt, $question, $questionsstatesrs); - try { - $qas[$qsession->questionid] = $this->convert_question_attempt( - $quiz, $attempt, $question, $qsession, $qstates); - } catch (Exception $e) { - notify($e->getMessage()); - } - } - $this->logger->set_current_attempt_id(null); - - $questionorder = array(); - foreach (explode(',', $quiz->questions) as $questionid) { - if ($questionid == 0) { - continue; - } - if (!array_key_exists($questionid, $qas)) { - $this->logger->log_assumption("Supplying minimal open state for - question {$questionid} in attempt {$attempt->id} at quiz - {$attempt->quiz}, since the session was missing.", $attempt->id); - try { - $question = $this->load_question($questionid, $quiz->id); - $qas[$questionid] = $this->supply_missing_question_attempt( - $quiz, $attempt, $question); - } catch (Exception $e) { - notify($e->getMessage()); - } - } - } - - return $this->save_usage($quiz->preferredbehaviour, $attempt, $qas, $quiz->questions); - } public function save_usage($preferredbehaviour, $attempt, $qas, $quizlayout) { $missing = array(); @@ -390,7 +214,6 @@ class question_engine_attempt_upgrader { } public function convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates) { - $this->prevent_timeout(); if ($question->qtype == 'random') { list($question, $qstates) = $this->decode_random_attempt($qstates, $question->maxmark); @@ -438,7 +261,6 @@ class question_engine_attempt_upgrader { } public function prepare_to_restore() { - $this->doingbackup = true; // Prevent printing of dots to stop timeout on upgrade. $this->logger = new dummy_question_engine_assumption_logger(); $this->questionloader = new question_engine_upgrade_question_loader($this->logger); } diff --git a/version.php b/version.php index fdd4e154df4..accb0bc2bed 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2014021300.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2014021300.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.