note that www-data is the user of the webprocess on your system - it may be something else, like httpd or apache, the path to php may also vary.

From there you can try different flags, -t=x to process for x seconds (note it allows the current quiz to finish, so it will likely run longer than x seconds), -c=n to process n quizes, or --quiz=quizid to process quizid.

-t and -c can be used together, the first to be reached causes a stop.

Moodle 1.9 or 2.0 site with quiz attempts.
Place 2.1, 2.2 or master code in place - but do not run upgrade yet!
Create admin/tool/qeupgradehelper/partialupgrade.php (2.1 path is local/qeupgradehelper/partialupgrade.php), with the code:
<?php
function tool_qeupgradehelper_get_quizzes_to_upgrade() {
return array();
}
This will cause the question attempt upgrade to not execute.
Run the Moodle system upgrade.
now run (via command line):
sudo -u www-data /usr/bin/php admin/tool/qeupgradehelper/cli/convert.php -h
or (for 2.1)
sudo -u www-data /usr/bin/php local/qeupgradehelper/cli/convert.php -h
note that www-data is the user of the webprocess on your system - it may be something else, like httpd or apache, the path to php may also vary.
From there you can try different flags, -t=x to process for x seconds (note it allows the current quiz to finish, so it will likely run longer than x seconds), -c=n to process n quizes, or --quiz=quizid to process quizid.
-t and -c can be used together, the first to be reached causes a stop.
No flags will cause the system to complete all remaining quizes.

Eric Merrill
added a comment - 14/Apr/12 11:26 PM Added the patch for master and 2.3
Don't know (if it were to be included), if the tool should go in admin/tool/qeupgradehelper/* or admin/cli/* - right now I have it in with qeupgradehelper

1. I think it should be in admin/tool/qeupgradehelper/. I don't know if there is a convention like putting it in admin/tool/qeupgradehelper/cli/? I don't think there is, but perhaps there should be. If you can be bothered, discuss it with Petr Skoda but for now it is good where it is.

2. You seem to have duplicated the line $quiz = tool_qeupgradehelper_get_quiz_for_upgrade(); (lines 91 and 93).

3. What are the rules about making CLI scripts translatable? Looking in admin/cron.php, it is not clear. This new script is useful as-is. No need to create lots more lang strings.

4. Getting to the really picky bits: in the PHP comment at the top of the file, it should be @package tool_qeupgradehelper (not separate @subpackage). (At one time I thought it was the other way, which is why all the other files are wrong.) Also, you should change @copyright to by copyright you!

Tim Hunt
added a comment - 15/Apr/12 1:17 AM That looks pretty good.
1. I think it should be in admin/tool/qeupgradehelper/. I don't know if there is a convention like putting it in admin/tool/qeupgradehelper/cli/? I don't think there is, but perhaps there should be. If you can be bothered, discuss it with Petr Skoda but for now it is good where it is.
2. You seem to have duplicated the line $quiz = tool_qeupgradehelper_get_quiz_for_upgrade(); (lines 91 and 93).
3. What are the rules about making CLI scripts translatable? Looking in admin/cron.php, it is not clear. This new script is useful as-is. No need to create lots more lang strings.
4. Getting to the really picky bits: in the PHP comment at the top of the file, it should be @package tool_qeupgradehelper (not separate @subpackage). (At one time I thought it was the other way, which is why all the other files are wrong.) Also, you should change @copyright to by copyright you!
Thanks, Tim.

Eric Merrill
added a comment - 15/Apr/12 1:40 AM Like a chump I committed the wrong (old version). If you could take another peak at it - the now committed version is much better.
Sorry about that (and I fixed the package label)

6. If you use the latest version of https://github.com/moodlehq/moodle-local_codechecker, it now wants comments to // Start with a capital and end with a full stop. I am not expecting you to fix that here. I just thought I should let you know for future reference.

If you write some testing instructions, and fix the copyright year, I can submit this for integration.

Tim Hunt
added a comment - 15/Apr/12 1:49 AM Yes that is better.
5. @copyright does need the year, I think.
6. If you use the latest version of https://github.com/moodlehq/moodle-local_codechecker , it now wants comments to // Start with a capital and end with a full stop. I am not expecting you to fix that here. I just thought I should let you know for future reference.
If you write some testing instructions, and fix the copyright year, I can submit this for integration.

Tim Hunt
added a comment - 15/Apr/12 1:53 AM Sorry. One more thing.
Please can you add mention of this command-line script to the readme, and on http://docs.moodle.org/21/en/Upgrading_to_Moodle_2.1 . We need to let people know this option exists!

Eric Merrill
added a comment - 15/Apr/12 1:56 AM I'll get right on it.
Speaking of the Upgrading_to_Moodle_2.1, do you also want me to backport it to 2.1? I'm not sure what the protocol is for backporting feature improvements. I'm happy to do it, just whatever you want.

Tim Hunt
added a comment - 15/Apr/12 2:07 AM I am not bothered one way or the other. It is good to backport, because this is useful functionality, and adding it won't break anything.
On the other hand, people really ought to be upgrading to 2.2.x, and it is a non-trivial back-port, so you need not bother. Basically, it is up to you.

Eric Merrill
added a comment - 15/Apr/12 2:22 AM I committed some the copyright fix and an addition to the README (not sure if it's the best addition in the world, so please give it a look and let me know if/how I should change it).
I'll look at 2.1 tonight, if it's not too much of a pain I'll give it a-go. I'll comment here either way.
Also, should I redo the branches into a single commit, or just leave them as is? All my other patches were done in one go

Eric Merrill
added a comment - 15/Apr/12 10:48 AM Ok, backported to 2.1, and squashed them all down into single commits, so if you think it looks ready, please send it on for integration.
Thanks for all the help Tim.

To INTEGRATORS, although this is technically a new feature, it is just a new script that cannot possibly break any existing functionality, and it is useful, therefore, please can we back-port it to all the stable branches.

Tim Hunt
added a comment - 15/Apr/12 2:14 PM Great, thanks Eric!
To INTEGRATORS, although this is technically a new feature, it is just a new script that cannot possibly break any existing functionality, and it is useful, therefore, please can we back-port it to all the stable branches.

I have two comments which I wonder if you'd be able to fix before integrating:

I think that this script should go into a cli subdirectory like Tim suggested, its certainly a defacto standard (and I am going to propose we put this into the coding guidelines). See examples:admin/cli/ auth/ldap/cli/ auth/db/cli/ enrol/meta/cli enrol/cohort/cli admin/tool/phpunit/cli/ etc

The coding style doc says: ' Our CLI script must not use relative config.php paths.'. So I think that your relative include of config.php should be changed to use dirname instead. (Note that when investigating this I noticed the phpunit tool does use relative includes.. going to investigate that).

Dan Poltawski
added a comment - 16/Apr/12 11:14 AM - edited Hi Eric/Tim,
This looks and I agree its worth going into the stable branches.
I have two comments which I wonder if you'd be able to fix before integrating:
I think that this script should go into a cli subdirectory like Tim suggested, its certainly a defacto standard (and I am going to propose we put this into the coding guidelines). See examples:
admin/cli/ auth/ldap/cli/ auth/db/cli/ enrol/meta/cli enrol/cohort/cli admin/tool/phpunit/cli/ etc
The coding style doc says: ' Our CLI script must not use relative config.php paths.'. So I think that your relative include of config.php should be changed to use dirname instead. (Note that when investigating this I noticed the phpunit tool does use relative includes.. going to investigate that).