MDL-44118 new environment check are all quiz attempts upgraded.

In Moodle 2.1, there was a major DB upgrade relating to questions, and
it was possible to delay some of that upgrade. Now, those DB tables are
changing again, and the time has come to insist that all the updata has
been upgraded (or deleted).
This commit is contained in:
Tim Hunt
2014-02-18 11:55:17 +00:00
parent 692d247a3a
commit e4c20157c0
5 changed files with 47 additions and 9 deletions
+7
View File
@@ -1128,5 +1128,12 @@
</FEEDBACK>
</PHP_SETTING>
</PHP_SETTINGS>
<CUSTOM_CHECKS>
<CUSTOM_CHECK file="question/engine/upgrade/upgradelib.php" function="quiz_attempts_upgraded" level="required">
<FEEDBACK>
<ON_ERROR message="quizattemptsupgradedmessage" />
</FEEDBACK>
</CUSTOM_CHECK>
</CUSTOM_CHECKS>
</MOODLE>
</COMPATIBILITY_MATRIX>
+1
View File
@@ -875,6 +875,7 @@ $string['questioncwqpfscheck'] = 'One or more \'random\' questions in a quiz are
$string['questioncwqpfsok'] = 'Good. There are no \'random\' questions in your quizzes that are set up to select questions from a mixture of shared and unshared question categories.';
$string['questiontype'] = 'Question type';
$string['questiontypes'] = 'Question types';
$string['quizattemptsupgradedmessage'] = 'In Moodle 2.1 there was a major upgrade to questions. It was possible to delay parts of the database upgrade to be run later. Before upgrading to Moodle 2.7, this upgrade must be completed.';
$string['recaptchaprivatekey'] = 'ReCAPTCHA private key';
$string['recaptchapublickey'] = 'ReCAPTCHA public key';
$string['register'] = 'Register your site';
+4 -3
View File
@@ -15,15 +15,16 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This is a one-line short description of the file
* This is a place to put custom environment checks, if there is not a better place.
*
* This library contains a collection of functions able to perform
* some custom checks executed by environmental tests (automatically
* executed on install & upgrade and under petition in the admin block).
*
* Any function in this library must return:
* Any function in this library gets a environment_results object passed in.
* It must return:
* - null: if the test isn't relevant and must not be showed (ignored)
* - environment_results object with the status set to:
* - the environment_results object that was passed in, with the status set to:
* - true: if passed
* - false: if failed
*
+6 -6
View File
@@ -1123,7 +1123,7 @@ class environment_results {
*/
var $part;
/**
* @var bool
* @var bool true means the test passed and all is OK. false means it failed.
*/
var $status;
/**
@@ -1180,11 +1180,11 @@ class environment_results {
/**
* Set the status
*
* @param boolean $status the status (true/false)
* @param bool $testpassed true means the test passed and all is OK. false means it failed.
*/
function setStatus($status) {
$this->status=$status;
if ($status) {
function setStatus($testpassed) {
$this->status = $testpassed;
if ($testpassed) {
$this->setErrorCode(NO_ERROR);
}
}
@@ -1274,7 +1274,7 @@ class environment_results {
/**
* Get the status
*
* @return boolean result
* @return bool true means the test passed and all is OK. false means it failed.
*/
function getStatus() {
return $this->status;
+29
View File
@@ -621,3 +621,32 @@ class question_deleted_question_attempt_updater extends question_qtype_attempt_u
$data['upgradedfromdeletedquestion'] = $state->answer;
}
}
/**
* This check verifies that all quiz attempts were upgraded since following
* the question engine upgrade in Moodle 2.1.
*
* @param environment_results object to update, if relevant.
* @return environment_results updated results object, or null if this test is not relevant.
*/
function quiz_attempts_upgraded(environment_results $result) {
global $DB;
$dbman = $DB->get_manager();
$table = new xmldb_table('quiz_attempts');
$field = new xmldb_field('needsupgradetonewqe');
if (!$dbman->table_exists($table) || !$dbman->field_exists($table, $field)) {
// DB already upgraded. This test is no longer relevant.
return null;
}
if (!$DB->record_exists('quiz_attempts', array('needsupgradetonewqe' => 1))) {
// No 1s present in that column means there are no problems.
return null;
}
// Only display anything if the admins need to be aware of the problem.
$result->setStatus(false);
return $result;
}