diff --git a/admin/tool/qeupgradehelper/README.txt b/admin/tool/qeupgradehelper/README.txt index ce0825bf3af..b9ce983d4bd 100644 --- a/admin/tool/qeupgradehelper/README.txt +++ b/admin/tool/qeupgradehelper/README.txt @@ -5,7 +5,7 @@ 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 provies a report of how much data there is to upgrade. +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. @@ -35,3 +35,9 @@ 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/cli/convert.php b/admin/tool/qeupgradehelper/cli/convert.php new file mode 100644 index 00000000000..00996378568 --- /dev/null +++ b/admin/tool/qeupgradehelper/cli/convert.php @@ -0,0 +1,129 @@ +. + +/** + * 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(__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;