merging MOODLE_19_QUESTIONS with HEAD
[moodle.git] / question / upgrade.php
CommitLineData
bac40536 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.
6 *
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 *//** */
12
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.
16 *
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.
21 *
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.
24 */
25function question_check_no_rqp_questions($result) {
26 global $CFG;
27
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);
32 }
33 return $result;
34}
08103c93
ML
35
36function question_remove_rqp_qtype() {
efe256e4 37 global $CFG;
38
08103c93
ML
39 $result = true;
40
efe256e4 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);
45
46 $table = new XMLDBTable('question_rqp');
47 $result = $result && drop_table($table);
48
49 $table = new XMLDBTable('question_rqp_types');
50 $result = $result && drop_table($table);
51
52 $table = new XMLDBTable('question_rqp_servers');
53 $result = $result && drop_table($table);
54
55 $result = $result && unset_config('qtype_rqp_version');
56 }
57
58 return $result;
59}
60
61function question_remove_rqp_qtype_config_string() {
62 global $CFG;
63
64 $result = true;
65
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');
69 }
08103c93
ML
70
71 return $result;
72}
bac40536 73?>