From e4c20157c0ae900bb37f3018d1f95d02bafdf0d0 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 13 Feb 2014 12:26:32 +0000 Subject: [PATCH] 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). --- admin/environment.xml | 7 +++++++ lang/en/admin.php | 1 + lib/customcheckslib.php | 7 ++++--- lib/environmentlib.php | 12 +++++------ question/engine/upgrade/upgradelib.php | 29 ++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/admin/environment.xml b/admin/environment.xml index 4edfcd1e423..b1cfc2617ed 100644 --- a/admin/environment.xml +++ b/admin/environment.xml @@ -1128,5 +1128,12 @@ + + + + + + + diff --git a/lang/en/admin.php b/lang/en/admin.php index 2ef3ae1dc16..4454aa4aed3 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -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'; diff --git a/lib/customcheckslib.php b/lib/customcheckslib.php index b14ac791b90..6ae1064409d 100644 --- a/lib/customcheckslib.php +++ b/lib/customcheckslib.php @@ -15,15 +15,16 @@ // along with Moodle. If not, see . /** - * 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 * diff --git a/lib/environmentlib.php b/lib/environmentlib.php index 30fa3531a27..f4e168103d7 100644 --- a/lib/environmentlib.php +++ b/lib/environmentlib.php @@ -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; diff --git a/question/engine/upgrade/upgradelib.php b/question/engine/upgrade/upgradelib.php index 4e21fe39772..249e1f1e9dd 100644 --- a/question/engine/upgrade/upgradelib.php +++ b/question/engine/upgrade/upgradelib.php @@ -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; +}