Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / question / upgrade.php
blobe9d1cd2b2869077d3aa96f731ba88a1f23c50908
1 <?php
2 /**
3 * This file contains dtabase upgrade code that is called from lib/db/upgrade.php,
4 * and also check methods that can be used for pre-install checks via
5 * admin/environment.php and lib/environmentlib.php.
7 * @copyright &copy; 2007 The Open University
8 * @author T.J.Hunt@open.ac.uk
9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 * @package package_name
11 *//** */
13 /**
14 * This test is becuase the RQP question type was included in core
15 * up to and including Moodle 1.8, and was removed before Moodle 1.9.
17 * Therefore, we want to check whether any rqp questions exist in the database
18 * before doing the upgrade. However, the check is not relevant if that
19 * question type was never installed, or if the person has chosen to
20 * manually reinstall the rqp question type from contrib.
22 * @param $version the version to test.
23 * @return null if the test is irrelevant, or true or false depending on whether the test passes.
25 function question_check_no_rqp_questions($result) {
26 global $CFG;
28 if (empty($CFG->qtype_rqp_version) || is_dir($CFG->dirroot . '/question/type/rqp')) {
29 return null;
30 } else {
31 $result->setStatus(count_records('question', 'qtype', 'rqp') == 0);
33 return $result;
36 function question_remove_rqp_qtype() {
37 global $CFG;
39 $result = true;
41 // Only remove the question type if the code is gone.
42 if (!is_dir($CFG->dirroot . '/question/type/rqp')) {
43 $table = new XMLDBTable('question_rqp_states');
44 $result = $result && drop_table($table);
46 $table = new XMLDBTable('question_rqp');
47 $result = $result && drop_table($table);
49 $table = new XMLDBTable('question_rqp_types');
50 $result = $result && drop_table($table);
52 $table = new XMLDBTable('question_rqp_servers');
53 $result = $result && drop_table($table);
55 $result = $result && unset_config('qtype_rqp_version');
58 return $result;
61 function question_remove_rqp_qtype_config_string() {
62 global $CFG;
64 $result = true;
66 // An earlier, buggy version of the previous function missed out the unset_config call.
67 if (!empty($CFG->qtype_rqp_version) && !is_dir($CFG->dirroot . '/question/type/rqp')) {
68 $result = $result && unset_config('qtype_rqp_version');
71 return $result;