3 // This file keeps track of upgrades to
6 // Sometimes, changes between versions involve
7 // alterations to database structures and other
8 // major things that may break installations.
10 // The upgrade function in this file will attempt
11 // to perform all the necessary actions to upgrade
12 // your older installtion to the current version.
14 // If there's something it cannot do itself, it
15 // will tell you what you need to do.
17 // The commands in here will all be database-neutral,
18 // using the functions defined in lib/ddllib.php
20 function xmldb_block_search_upgrade($oldversion=0) {
22 global $CFG, $THEME, $db;
26 /// And upgrade begins here. For each one, you'll need one
27 /// block of code similar to the next one. Please, delete
28 /// this comment lines once this file start handling proper
31 /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
32 /// $result = result of "/lib/ddllib.php" function calls
34 if ($result && $oldversion < 2007071302) {
36 /// Define table search_documents to be created
37 $table = new XMLDBTable('search_documents');
39 /// Drop it if it existed before
41 drop_table($table, true, false);
43 /// Adding fields to table search_documents
44 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
45 $table->addFieldInfo('docid', XMLDB_TYPE_CHAR
, '32', null, XMLDB_NOTNULL
, null, null, null, null);
46 $table->addFieldInfo('doctype', XMLDB_TYPE_CHAR
, '32', null, XMLDB_NOTNULL
, null, null, null, 'none');
47 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '32', null, XMLDB_NOTNULL
, null, null, null, 'standard');
48 $table->addFieldInfo('title', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null);
49 $table->addFieldInfo('url', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null);
50 $table->addFieldInfo('docdate', XMLDB_TYPE_DATETIME
, null, null, XMLDB_NOTNULL
, null, null, null);
51 $table->addFieldInfo('updated', XMLDB_TYPE_DATETIME
, null, null, XMLDB_NOTNULL
, null, null, null);
52 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
53 $table->addFieldInfo('groupid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
55 /// Adding keys to table search_documents
56 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
58 /// Adding indexes to table search_documents
59 $table->addIndexInfo('mdl_search_docid', XMLDB_INDEX_NOTUNIQUE
, array('docid'));
60 $table->addIndexInfo('mdl_search_doctype', XMLDB_INDEX_NOTUNIQUE
, array('doctype'));
61 $table->addIndexInfo('mdl_search_itemtype', XMLDB_INDEX_NOTUNIQUE
, array('itemtype'));
63 /// Launch create table for search_documents
64 $result = $result && create_table($table);
67 /// Rename table search_documents to block_search_documents and
68 /// fix some defaults (MDL-10572)
69 if ($result && $oldversion < 2007081100) {
71 /// Define table search_documents to be renamed to block_search_documents
72 $table = new XMLDBTable('search_documents');
74 /// Launch rename table for block_search_documents
75 $result = $result && rename_table($table, 'block_search_documents');
77 /// Changing the default of field doctype on table block_search_documents to none
78 $table = new XMLDBTable('block_search_documents');
79 $field = new XMLDBField('doctype');
80 $field->setAttributes(XMLDB_TYPE_CHAR
, '32', null, XMLDB_NOTNULL
, null, null, null, 'none', 'docid');
82 /// Launch change of default for field doctype
83 $result = $result && change_field_default($table, $field);
85 /// Changing the default of field itemtype on table block_search_documents to standard
86 $table = new XMLDBTable('block_search_documents');
87 $field = new XMLDBField('itemtype');
88 $field->setAttributes(XMLDB_TYPE_CHAR
, '32', null, XMLDB_NOTNULL
, null, null, null, 'standard', 'doctype');
90 /// Launch change of default for field itemtype
91 $result = $result && change_field_default($table, $field);
93 /// Changing the default of field title on table block_search_documents to drop it
94 $table = new XMLDBTable('block_search_documents');
95 $field = new XMLDBField('title');
96 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'itemtype');
98 /// Launch change of default for field title
99 $result = $result && change_field_default($table, $field);
101 /// Changing the default of field url on table block_search_documents to drop it
102 $table = new XMLDBTable('block_search_documents');
103 $field = new XMLDBField('url');
104 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'title');
106 /// Launch change of default for field url
107 $result = $result && change_field_default($table, $field);
110 if ($result && $oldversion < 2007112700) {
113 /// Truncate the block_search_documents table
114 execute_sql("TRUNCATE TABLE {$CFG->prefix}block_search_documents", true);
116 /// Changing type of field docdate on table block_search_documents to int
117 $table = new XMLDBTable('block_search_documents');
118 $field = new XMLDBField('docdate');
119 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'url');
121 /// Launch change of type for field docdate
122 $result = $result && change_field_type($table, $field);
124 /// Changing type of field updated on table block_search_documents to int
125 $table = new XMLDBTable('block_search_documents');
126 $field = new XMLDBField('updated');
127 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'docdate');
129 /// Launch change of type for field updated
130 $result = $result && change_field_type($table, $field);
134 /// MDL-12352, postgres can not cope with change_field_type(), so dropping the fields and adding again
136 /// Define field docdate to be dropped from block_search_documents
137 $table = new XMLDBTable('block_search_documents');
138 $field = new XMLDBField('docdate');
140 /// Launch drop field docdate
141 $result = $result && drop_field($table, $field);
143 /// Define field updated to be dropped from block_search_documents
144 $field = new XMLDBField('updated');
146 /// Launch drop field updated
147 $result = $result && drop_field($table, $field);
149 /// Define field docdate to be added to block_search_documents
150 $field = new XMLDBField('docdate');
151 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'url');
153 /// Launch add field docdate
154 $result = $result && add_field($table, $field);
156 /// Define field updated to be added to block_search_documents
157 $field = new XMLDBField('updated');
158 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'docdate');
160 /// Launch add field updated
161 $result = $result && add_field($table, $field);