upgrade.php 9.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
/**
 * This program is part of Mahara
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
Penny Leach's avatar
Penny Leach committed
20
21
 * @subpackage core
 * @author     Penny Leach <penny@catalyst.net.nz>
22
23
24
25
26
27
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

defined('INTERNAL') || die();

29
30
require_once('template.php');

31
32
33
function xmldb_core_upgrade($oldversion=0) {

    $status = true;
34
    $prefix = get_config('dbprefix');
35

Penny Leach's avatar
Penny Leach committed
36
37
38
39
40
41
42
43
44
45
    if ($oldversion < 2006121400) {

        set_field('community', 'jointype', 'open', 'jointype', 'anyone');
        $table = new XMLDBTable('community');
        $field = new XMLDBField('jointype');
        $field->setAttributes(XMLDB_TYPE_CHAR, 20, false, true, false, true, 
                              array('controlled', 'invite', 'request', 'open'), 'open');
        change_field_default($table, $field);
        change_field_enum($table, $field);
    }
46

47
48
49
50
51
52
53
54
55
56
    if ($oldversion < 2006121401) {
        $table = new XMLDBTable('usr');
        $field = new XMLDBField('expirymailsent');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0);
        add_field($table, $field);
        $field = new XMLDBField('inactivemailsent');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0);
        add_field($table, $field);
    }

Nigel McNie's avatar
Nigel McNie committed
57
58
59
60
61
62
63
64
65
    // Add cron jobs for authentication cleanup: partial registrations and account expiries
    if ($oldversion < 2006121500) {
        $registrations = new StdClass;
        $registrations->callfunction = 'auth_clean_partial_registrations';
        $registrations->minute = '0';
        $registrations->hour = '5';
        insert_record('cron', $registrations);

        $expiries = new StdClass;
66
67
68
        $expiries->callfunction = 'auth_handle_account_expiries';
        $expiries->minute = '10';
        $expiries->hour = '5';
Nigel McNie's avatar
Nigel McNie committed
69
70
71
        insert_record('cron', $expiries);
    }

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    // Merge the usr_suspension table with the usr table, and add a 'active' column and
    // various events and fields to do with this column
    if ($oldversion < 2006121800) {
        $table = new XMLDBTable('usr_suspension');
        drop_table($table);

        $table = new XMLDBTable('usr');

        $field = new XMLDBField('suspendedctime');
        $field->setAttributes(XMLDB_TYPE_DATETIME);
        add_field($table, $field);

        $field = new XMLDBField('suspendedreason');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);

        $field = new XMLDBField('suspendedcusr');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 10, false, false, false);
        add_field($table, $field);

        $field = new XMLDBField('active');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 1);
        add_field($table, $field);
        set_field('usr', 'active', 1);

        $key = new XMLDBKey('sus_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('suspendedcusr'), 'usr', array('id'));
        add_key($table, $key);

        $event = new StdClass;
        $event->name = 'unsuspenduser';
        insert_record('event_type', $event);
        $event->name = 'undeleteuser';
        insert_record('event_type', $event);
        $event->name = 'expireuser';
        insert_record('event_type', $event);
        $event->name = 'unexpireuser';
        insert_record('event_type', $event);
        $event->name = 'deactivateuser';
        insert_record('event_type', $event);
        $event->name = 'activateuser';
        insert_record('event_type', $event);

        $activecheck = new StdClass;
        $activecheck->plugin = 'internal';
        $activecheck->event = 'suspenduser';
        $activecheck->callfunction = 'update_active_flag';
        insert_record('auth_event_subscription', $activecheck);
        $activecheck->event = 'unsuspenduser';
        insert_record('auth_event_subscription', $activecheck);
        $activecheck->event = 'deleteuser';
        insert_record('auth_event_subscription', $activecheck);
        $activecheck->event = 'undeleteuser';
        insert_record('auth_event_subscription', $activecheck);
        $activecheck->event = 'expireuser';
        insert_record('auth_event_subscription', $activecheck);
        $activecheck->event = 'unexpireuser';
        insert_record('auth_event_subscription', $activecheck);
        $activecheck->event = 'deactivateuser';
        insert_record('auth_event_subscription', $activecheck);
        $activecheck->event = 'activateuser';
        insert_record('auth_event_subscription', $activecheck);

    }

Richard Mansfield's avatar
Richard Mansfield committed
137
138
139
140
141
142
143
144
145
146
147
148
    if ($oldversion < 2006122200) {
        // Creating usr_infectedupload table
        $table = new XMLDBTable('usr_infectedupload');

        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
                             XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('usr', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('time', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);

        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));

149
        create_table($table);
Richard Mansfield's avatar
Richard Mansfield committed
150
151
    }

152
153
154
155
156
    if ($oldversion < 2007011200) {
        // Add path to file to the config table
        set_config('pathtofile', '/usr/bin/file');
    }

157
158
159
160
161
162
163
164
    if ($oldversion < 2007011500) {
        // Add the 'profileicon' field to the usr table
        $table = new XMLDBTable('usr');
        $field = new XMLDBField('profileicon');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 10, false, false, false);
        add_field($table, $field);
    }

165
166
167
168
169
170
171
172
173
174
    if ($oldversion < 2007011600) {
        // Add the 'quota' and 'quotaused' fields to the usr table
        $table = new XMLDBTable('usr');
        $field = new XMLDBField('quota');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 10, false, false, false);
        add_field($table, $field);
        $field = new XMLDBField('quotaused');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 10, false, true, null, null, null, 0);
        add_field($table, $field);

175
        execute_sql('UPDATE ' . $prefix . 'usr SET quota=10485760');
176
177
    }

178
179
180
181
182
183
184
185
186
    if ($oldversion < 2007012300) {
        // fix up a broken cron entry...
        set_field('cron', 'minute', '0', 'callfunction', 'rebuild_artefact_parent_cache_complete');
        $c = new StdClass;
        $c->callfunction = 'activity_process_queue';
        $c->minute = '*/5';
        insert_record('cron', $c);
    }

187
188
189
190
191
192
193
194
    if ($oldversion < 2007012301) {
        $at = new StdClass;
        $at->name = 'viewaccess';
        $at->admin = 0;
        $at->delay = 1;
        insert_record('activity_type', $at);
    }

195
196
    if ($oldversion < 2007012500) {
        $table = new XMLDBTable('usr_watchlist_artefact');
197
        $field = new XMLDBField('deleted');
198
199
200
201
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, false, false, 0);
        add_field($table, $field);
    }

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    if ($oldversion < 2007020300) {
        // artefact_tag table
        $table = new XMLDBTable('artefact_tag');
        $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
        $table->addFieldInfo('tag', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('artefact', 'tag'));
        create_table($table);

        // view_tag table
        $table = new XMLDBTable('view_tag');
        $table->addFieldInfo('view', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addKeyInfo('viewfk', XMLDB_KEY_FOREIGN, array('view'), 'view', array('id'));
        $table->addFieldInfo('tag', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('view', 'tag'));
        create_table($table);
    }
219
220
221
222
    if ($oldversion < 2007020500) {
        insert_record('event_type', (object)array('name' => 'saveartefact'));
        insert_record('event_type', (object)array('name' => 'deleteartefact'));
    }
223

224
225
226
227
228
    if ($oldversion < 2007021600) {
        $template = template_parse('gallery');
        upgrade_template('gallery', $template);
    }

Martyn Smith's avatar
Martyn Smith committed
229
230
231
232
233
    if ($oldversion < 2007021900) {
        insert_record('event_type', (object)array('name' => 'saveview'));
        insert_record('event_type', (object)array('name' => 'deleteview'));
    }

234
235
236
237
238
    if ($oldversion < 2007021902) {
        $template = template_parse('filelist');
        upgrade_template('filelist', $template);
    }

239
240
241
242
243
244
    if ($oldversion < 2007021903) {
        execute_sql("UPDATE {$prefix}artefact
            SET container = 1
            WHERE artefacttype = 'blog'");
    }

245
246
247
248
    return $status;

}
?>