Skip to content

Commit

Permalink
MDL-29509 move qeupgradehelper to admin tools
Browse files Browse the repository at this point in the history
AMOS BEGIN
 MOV [action,local_qeupgradehelper],[action,tool_qeupgradehelper]
 MOV [alreadydone,local_qeupgradehelper],[alreadydone,tool_qeupgradehelper]
 MOV [areyousure,local_qeupgradehelper],[areyousure,tool_qeupgradehelper]
 MOV [areyousuremessage,local_qeupgradehelper],[areyousuremessage,tool_qeupgradehelper]
 MOV [areyousureresetmessage,local_qeupgradehelper],[areyousureresetmessage,tool_qeupgradehelper]
 MOV [attemptstoconvert,local_qeupgradehelper],[attemptstoconvert,tool_qeupgradehelper]
 MOV [backtoindex,local_qeupgradehelper],[backtoindex,tool_qeupgradehelper]
 MOV [conversioncomplete,local_qeupgradehelper],[conversioncomplete,tool_qeupgradehelper]
 MOV [convertattempts,local_qeupgradehelper],[convertattempts,tool_qeupgradehelper]
 MOV [convertquiz,local_qeupgradehelper],[convertquiz,tool_qeupgradehelper]
 MOV [convertedattempts,local_qeupgradehelper],[convertedattempts,tool_qeupgradehelper]
 MOV [cronenabled,local_qeupgradehelper],[cronenabled,tool_qeupgradehelper]
 MOV [croninstructions,local_qeupgradehelper],[croninstructions,tool_qeupgradehelper]
 MOV [cronprocesingtime,local_qeupgradehelper],[cronprocesingtime,tool_qeupgradehelper]
 MOV [cronsetup,local_qeupgradehelper],[cronsetup,tool_qeupgradehelper]
 MOV [cronsetup_desc,local_qeupgradehelper],[cronsetup_desc,tool_qeupgradehelper]
 MOV [cronstarthour,local_qeupgradehelper],[cronstarthour,tool_qeupgradehelper]
 MOV [cronstophour,local_qeupgradehelper],[cronstophour,tool_qeupgradehelper]
 MOV [extracttestcase,local_qeupgradehelper],[extracttestcase,tool_qeupgradehelper]
 MOV [extracttestcase_desc,local_qeupgradehelper],[extracttestcase_desc,tool_qeupgradehelper]
 MOV [gotoindex,local_qeupgradehelper],[gotoindex,tool_qeupgradehelper]
 MOV [gotoquizreport,local_qeupgradehelper],[gotoquizreport,tool_qeupgradehelper]
 MOV [gotoresetlink,local_qeupgradehelper],[gotoresetlink,tool_qeupgradehelper]
 MOV [includedintheupgrade,local_qeupgradehelper],[includedintheupgrade,tool_qeupgradehelper]
 MOV [invalidquizid,local_qeupgradehelper],[invalidquizid,tool_qeupgradehelper]
 MOV [listpreupgrade,local_qeupgradehelper],[listpreupgrade,tool_qeupgradehelper]
 MOV [listpreupgrade_desc,local_qeupgradehelper],[listpreupgrade_desc,tool_qeupgradehelper]
 MOV [listpreupgradeintro,local_qeupgradehelper],[listpreupgradeintro,tool_qeupgradehelper]
 MOV [listtodo,local_qeupgradehelper],[listtodo,tool_qeupgradehelper]
 MOV [listtodo_desc,local_qeupgradehelper],[listtodo_desc,tool_qeupgradehelper]
 MOV [listtodointro,local_qeupgradehelper],[listtodointro,tool_qeupgradehelper]
 MOV [listupgraded,local_qeupgradehelper],[listupgraded,tool_qeupgradehelper]
 MOV [listupgraded_desc,local_qeupgradehelper],[listupgraded_desc,tool_qeupgradehelper]
 MOV [listupgradedintro,local_qeupgradehelper],[listupgradedintro,tool_qeupgradehelper]
 MOV [noquizattempts,local_qeupgradehelper],[noquizattempts,tool_qeupgradehelper]
 MOV [nothingupgradedyet,local_qeupgradehelper],[nothingupgradedyet,tool_qeupgradehelper]
 MOV [notupgradedsiterequired,local_qeupgradehelper],[notupgradedsiterequired,tool_qeupgradehelper]
 MOV [numberofattempts,local_qeupgradehelper],[numberofattempts,tool_qeupgradehelper]
 MOV [oldsitedetected,local_qeupgradehelper],[oldsitedetected,tool_qeupgradehelper]
 MOV [outof,local_qeupgradehelper],[outof,tool_qeupgradehelper]
 MOV [pluginname,local_qeupgradehelper],[pluginname,tool_qeupgradehelper]
 MOV [pretendupgrade,local_qeupgradehelper],[pretendupgrade,tool_qeupgradehelper]
 MOV [pretendupgrade_desc,local_qeupgradehelper],[pretendupgrade_desc,tool_qeupgradehelper]
 MOV [questionsessions,local_qeupgradehelper],[questionsessions,tool_qeupgradehelper]
 MOV [quizid,local_qeupgradehelper],[quizid,tool_qeupgradehelper]
 MOV [quizupgrade,local_qeupgradehelper],[quizupgrade,tool_qeupgradehelper]
 MOV [quizzesthatcanbereset,local_qeupgradehelper],[quizzesthatcanbereset,tool_qeupgradehelper]
 MOV [quizzestobeupgraded,local_qeupgradehelper],[quizzestobeupgraded,tool_qeupgradehelper]
 MOV [quizzeswithunconverted,local_qeupgradehelper],[quizzeswithunconverted,tool_qeupgradehelper]
 MOV [resetquiz,local_qeupgradehelper],[resetquiz,tool_qeupgradehelper]
 MOV [resetcomplete,local_qeupgradehelper],[resetcomplete,tool_qeupgradehelper]
 MOV [resettingquizattempts,local_qeupgradehelper],[resettingquizattempts,tool_qeupgradehelper]
 MOV [resettingquizattemptsprogress,local_qeupgradehelper],[resettingquizattemptsprogress,tool_qeupgradehelper]
 MOV [upgradingquizattempts,local_qeupgradehelper],[upgradingquizattempts,tool_qeupgradehelper]
 MOV [upgradedsitedetected,local_qeupgradehelper],[upgradedsitedetected,tool_qeupgradehelper]
 MOV [upgradedsiterequired,local_qeupgradehelper],[upgradedsiterequired,tool_qeupgradehelper]
 MOV [veryoldattemtps,local_qeupgradehelper],[veryoldattemtps,tool_qeupgradehelper]
AMOS END
  • Loading branch information
skodak committed Sep 26, 2011
1 parent b703861 commit cff8fc8
Show file tree
Hide file tree
Showing 23 changed files with 261 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ With a lot of question attempts, doing the whole conversion on upgrade is very
slow. The plugin can help with that in various ways.


To install using git, type this command in the root of your Moodle install
git clone git://github.com/timhunt/moodle-local_qeupgradehelper.git local/qeupgradehelper
Then add /local/qeupgradehelper to your git ignore.

Alternatively, download the zip from
https://github.com/timhunt/moodle-local_qeupgradehelper/zipball/master
unzip it into the local folder, and then rename the new folder to qeupgradehelper.


When installed in a Moodle 2.0 site:

1. It provies 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
* Question engine upgrade helper library code that relies on other parts of the
* new question engine code.
*
* @package local
* @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 local_qeupgradehelper_attempt_upgrader extends question_engine_attempt_upgrader {
class tool_qeupgradehelper_attempt_upgrader extends question_engine_attempt_upgrader {
public $quizid;
public $attemptsdone = 0;
public $attemptstodo;
Expand Down Expand Up @@ -62,7 +63,7 @@ protected function reset_progress($done, $outof) {
$a->done = $done;
$a->outof = $outof;
$this->progressbar->update($done, $outof,
get_string('resettingquizattemptsprogress', 'local_qeupgradehelper', $a));
get_string('resettingquizattemptsprogress', 'tool_qeupgradehelper', $a));
}

protected function get_resettable_attempts($quiz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
/**
* Script to upgrade the attempts at a particular quiz, after confirmation.
*
* @package local
* @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__) . '/../../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once(dirname(__FILE__) . '/afterupgradelib.php');
require_once($CFG->libdir . '/adminlib.php');
Expand All @@ -34,20 +34,20 @@

require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
local_qeupgradehelper_require_upgraded();
tool_qeupgradehelper_require_upgraded();

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'));
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('local_qeupgradehelper');
$renderer = $PAGE->get_renderer('tool_qeupgradehelper');

$quizsummary = local_qeupgradehelper_get_quiz($quizid);
$quizsummary = tool_qeupgradehelper_get_quiz($quizid);
if (!$quizsummary) {
print_error('invalidquizid', 'local_qeupgradehelper',
local_qeupgradehelper_url('listtodo'));
print_error('invalidquizid', 'tool_qeupgradehelper',
tool_qeupgradehelper_url('listtodo'));
}

$quizsummary->name = format_string($quizsummary->name);
Expand All @@ -56,18 +56,18 @@
// Actually do the conversion.
echo $renderer->header();
echo $renderer->heading(get_string(
'upgradingquizattempts', 'local_qeupgradehelper', $quizsummary));
'upgradingquizattempts', 'tool_qeupgradehelper', $quizsummary));

$upgrader = new local_qeupgradehelper_attempt_upgrader(
$upgrader = new tool_qeupgradehelper_attempt_upgrader(
$quizsummary->id, $quizsummary->numtoconvert);
$upgrader->convert_all_quiz_attempts();

echo $renderer->heading(get_string('conversioncomplete', 'local_qeupgradehelper'));
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', 'local_qeupgradehelper'));
echo $renderer->end_of_page_link(local_qeupgradehelper_url('listtodo'),
get_string('listtodo', 'local_qeupgradehelper'));
get_string('gotoquizreport', 'tool_qeupgradehelper'));
echo $renderer->end_of_page_link(tool_qeupgradehelper_url('listtodo'),
get_string('listtodo', 'tool_qeupgradehelper'));

echo $renderer->footer();
exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
/**
* Script to set up cron to complete the upgrade automatically.
*
* @package local
* @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__) . '/../../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once(dirname(__FILE__) . '/cronsetup_form.php');
require_once($CFG->libdir . '/adminlib.php');
Expand All @@ -33,37 +33,37 @@
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'));
tool_qeupgradehelper_url('cronsetup'));
$PAGE->navbar->add(get_string('cronsetup', 'tool_qeupgradehelper'));

$renderer = $PAGE->get_renderer('local_qeupgradehelper');
$renderer = $PAGE->get_renderer('tool_qeupgradehelper');

$form = new local_qeupgradehelper_cron_setup_form(
new moodle_url('/local/qeupgradehelper/cronsetup.php'));
$form->set_data(get_config('local_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(local_qeupgradehelper_url('index'));
redirect(tool_qeupgradehelper_url('index'));

} else if ($fromform = $form->get_data()) {
if ($fromform->cronenabled) {
set_config('cronenabled', $fromform->cronenabled, 'local_qeupgradehelper');
set_config('starthour', $fromform->starthour, 'local_qeupgradehelper');
set_config('stophour', $fromform->stophour, 'local_qeupgradehelper');
set_config('procesingtime', $fromform->procesingtime, 'local_qeupgradehelper');
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', 'local_qeupgradehelper');
unset_config('starthour', 'local_qeupgradehelper');
unset_config('stophour', 'local_qeupgradehelper');
unset_config('procesingtime', 'local_qeupgradehelper');
unset_config('cronenabled', 'tool_qeupgradehelper');
unset_config('starthour', 'tool_qeupgradehelper');
unset_config('stophour', 'tool_qeupgradehelper');
unset_config('procesingtime', 'tool_qeupgradehelper');
}
redirect(local_qeupgradehelper_url('index'));
redirect(tool_qeupgradehelper_url('index'));

}

echo $renderer->header();
echo $renderer->heading(get_string('cronsetup', 'local_qeupgradehelper'));
echo $renderer->box(get_string('croninstructions', 'local_qeupgradehelper'));
echo $renderer->heading(get_string('cronsetup', 'tool_qeupgradehelper'));
echo $renderer->box(get_string('croninstructions', 'tool_qeupgradehelper'));
$form->display();
echo $renderer->footer();
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Settings form for cronsetup.php.
*
* @package local
* @package tool
* @subpackage qeupgradehelper
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -34,23 +34,23 @@
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_qeupgradehelper_cron_setup_form extends moodleform {
class tool_qeupgradehelper_cron_setup_form extends moodleform {
public function definition() {
$mform = $this->_form;

$mform->addElement('selectyesno', 'cronenabled',
get_string('cronenabled', 'local_qeupgradehelper'));
get_string('cronenabled', 'tool_qeupgradehelper'));

$mform->addElement('select', 'starthour',
get_string('cronstarthour', 'local_qeupgradehelper'), range(0, 23));
get_string('cronstarthour', 'tool_qeupgradehelper'), range(0, 23));

$mform->addElement('select', 'stophour',
get_string('cronstophour', 'local_qeupgradehelper'),
get_string('cronstophour', 'tool_qeupgradehelper'),
array_combine(range(1, 24), range(1, 24)));
$mform->setDefault('stophour', 24);

$mform->addElement('duration', 'procesingtime',
get_string('cronprocesingtime', 'local_qeupgradehelper'));
get_string('cronprocesingtime', 'tool_qeupgradehelper'));
$mform->setDefault('procesingtime', 60);

$mform->disabledIf('starthour', 'cronenabled', 'eq', 0);
Expand Down
38 changes: 38 additions & 0 deletions admin/tool/qeupgradehelper/db/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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/>.

/**
* 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;

// this is a hack - this plugin used to live in local/qeupgradehelper,
// we want to remove the orphaned version info and capability
// unless there is a local plugin type with the same name

if (!file_exists("$CFG->dirroot/local/qeupgradehelper")) {
unset_all_config_for_plugin('local_qeupgradehelper');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
* 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 local
* @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__) . '/../../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once(dirname(__FILE__) . '/extracttestcase_form.php');
require_once($CFG->libdir . '/questionlib.php');
Expand All @@ -40,31 +40,31 @@
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));

admin_externalpage_setup('qeupgradehelper', '', array(),
local_qeupgradehelper_url('extracttestcase'));
$PAGE->navbar->add(get_string('extracttestcase', 'local_qeupgradehelper'));
tool_qeupgradehelper_url('extracttestcase'));
$PAGE->navbar->add(get_string('extracttestcase', 'tool_qeupgradehelper'));

$renderer = $PAGE->get_renderer('local_qeupgradehelper');
$renderer = $PAGE->get_renderer('tool_qeupgradehelper');

$mform = new local_qeupgradehelper_extract_options_form(
new moodle_url('/local/qeupgradehelper/extracttestcase.php'), null, 'get');
$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 = local_qeupgradehelper_get_session_id($fromform->attemptid, $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 = local_qeupgradehelper_find_test_case($fromform->behaviour, $fromform->statehistory,
$qsid = tool_qeupgradehelper_find_test_case($fromform->behaviour, $fromform->statehistory,
$fromform->qtype, $fromform->extratests);
$name = 'history' . $fromform->statehistory;
}

if ($qsid) {
local_qeupgradehelper_generate_unit_test($qsid, $name);
tool_qeupgradehelper_generate_unit_test($qsid, $name);
} else {
notify('No suitable attempts found.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Settings form for extracttestcase.php.
*
* @package local
* @package tool
* @subpackage qeupgradehelper
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -34,7 +34,7 @@
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_qeupgradehelper_extract_options_form extends moodleform {
class tool_qeupgradehelper_extract_options_form extends moodleform {
public function definition() {
$mform = $this->_form;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@
* This screen is the main entry-point to the plugin, it gives the admin a list
* of options available to them.
*
* @package local
* @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__) . '/../../../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');

$renderer = $PAGE->get_renderer('local_qeupgradehelper');
$renderer = $PAGE->get_renderer('tool_qeupgradehelper');

$actions = array();
if (local_qeupgradehelper_is_upgraded()) {
$detected = get_string('upgradedsitedetected', 'local_qeupgradehelper');
$actions[] = local_qeupgradehelper_action::make('listtodo');
$actions[] = local_qeupgradehelper_action::make('listupgraded');
$actions[] = local_qeupgradehelper_action::make('extracttestcase');
$actions[] = local_qeupgradehelper_action::make('cronsetup');
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', 'local_qeupgradehelper');
$actions[] = local_qeupgradehelper_action::make('listpreupgrade');
$actions[] = local_qeupgradehelper_action::make('extracttestcase');
$actions[] = local_qeupgradehelper_action::make('cronsetup');
$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);
Loading

0 comments on commit cff8fc8

Please sign in to comment.