upgrade.php 2.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?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
 * @subpackage core or plugintype/pluginname
 * @author     Your Name <you@example.org>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

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

function xmldb_core_upgrade($oldversion=0) {

    $status = true;

Nigel McNie's avatar
Nigel McNie committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    if ($status && $oldversion < 2006101700) {
        // Creating the usr table with basic fields required for authentication
        $table = new XMLDBTable('usr');

        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
            XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', XMLDB_NOTNULL,
            null, null, null, null);
        $table->addFieldInfo('password', XMLDB_TYPE_CHAR, '40', XMLDB_NOTNULL,
            null, null, null, null);
        $table->addFieldInfo('salt', XMLDB_TYPE_CHAR, '8', XMLDB_NOTNULL,
            null, null, null, null);

        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addIndexInfo('usernameuk', XMLDB_KEY_UNIQUE, array('LOWER(username)'));

        $status = $status && create_table($table);
    }

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    if ($status && $oldversion < 2006101900) {
        // Insert core configuration option
        $status = $status && set_config('session_timeout', 1800);

        // Add password_change field
        $table = new XMLDBTable('usr');
        $field = new XMLDBField('password_change');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
            XMLDB_NOTNULL, null, null, null, 0, null);

        $status = $status && add_field($table, $field);

        // Insert the root user
        try {
            log_dbg('trying to insert root user');
            $root = new StdClass;
            $root->username = 'root';
            $root->password = 'mahara';
            $root->password_change = 1;
            insert_record('usr', $root);
        }
        catch (DatalibException $e) {
            return false;
        }
    }
Nigel McNie's avatar
Nigel McNie committed
77

78
79
80
81
    return $status;

}
?>