MDL-24625 Dropped $CFG->block_search_text and $CFG->block_search_button
[moodle.git] / blocks / search / db / upgrade.php
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
18 /**
19  * Keeps track of upgrades to the global search block
20  *
21  * @package    blocks
22  * @subpackage search
23  * @copyright  2010 Aparup Banerjee <aparup@moodle.com>
24  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
27 defined('MOODLE_INTERNAL') || die();
29 function xmldb_block_search_upgrade($oldversion) {
30     global $CFG, $DB;
32     require('upgradelib.php');
33     $result = TRUE;
34     $dbman = $DB->get_manager();
36     if ($oldversion < 2010101800) {
37         // See MDL-24374
38         // Changing type of field docdate on table block_search_documents to int
39         // Changing type of field updated on table block_search_documents to int
40         $table = new xmldb_table('block_search_documents');
42         $field_docdate_new = new xmldb_field('docdate_new', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'docdate');
43         $field_updated_new = new xmldb_field('updated_new', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'updated');
44         $field_docdate_old = new xmldb_field('docdate');
45         $field_updated_old = new xmldb_field('updated');
47         // Conditionally launch add temporary fields
48         if (!$dbman->field_exists($table, $field_docdate_new)) {
49             $dbman->add_field($table, $field_docdate_new);
50         }
51         if (!$dbman->field_exists($table, $field_updated_new)) {
52             $dbman->add_field($table, $field_updated_new);
53         }
55         $sql = "SELECT id, docdate, updated FROM {block_search_documents}";
56         $search_documents = $DB->get_records_sql($sql);
57         if ($search_documents) {
58             foreach ($search_documents as $sd) {
59                 $sd->docdate_new = convert_datetime_upgrade($sd->docdate);
60                 $sd->updated_new = convert_datetime_upgrade($sd->updated);
61                 $DB->update_record('block_search_documents', $sd);
62             }
63         }
64         // Conditionally launch drop the old fields
65         if ($dbman->field_exists($table, $field_docdate_old)) {
66             $dbman->drop_field($table, $field_docdate_old);
67         }
68         if ($dbman->field_exists($table, $field_updated_old)) {
69             $dbman->drop_field($table, $field_updated_old);
70         }
72         //rename the new fields to the original field names.
73         $dbman->rename_field($table, $field_docdate_new, 'docdate');
74         $dbman->rename_field($table, $field_updated_new, 'updated');
76         // search savepoint reached
77         upgrade_block_savepoint(true, 2010101800, 'search');
78     }
80     if ($oldversion < 2010110900) {
81         unset_config('block_search_text');
82         unset_config('block_search_button');
83         upgrade_block_savepoint(true, 2010110900, 'search');
84     }
86     return $result;
87 }