upgrade.json.php 2.94 KB
Newer Older
1
2
<?php
/**
3
 * This program is part of Mahara
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 *  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 admin
 * @author     Penny Leach <penny@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

27
28
define('INTERNAL', 1);
define('INSTALLER', 1);
Penny Leach's avatar
Penny Leach committed
29
require(dirname(dirname(__FILE__)) . '/init.php');
30
require(get_config('libroot') . 'upgrade.php');
Penny Leach's avatar
Penny Leach committed
31

32
$name    = clean_requestdata('name', PARAM_ALPHAEXT, REQUEST_EITHER);
33
34
35
36
$install = clean_requestdata('install', PARAM_BOOL, REQUEST_EITHER);

if ($install) {
    if (!get_config('installed')) {
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        try {
            // Install the default institution
            $institution = new StdClass;
            $institution->name = 'mahara';
            $institution->displayname = 'No Institution';
            $institution->authplugin  = 'internal';
            insert_record('institution', $institution);

            // Insert the root user
            $user = new StdClass;
            $user->username = 'root';
            $user->password = 'mahara';
            $user->institution = 'mahara';
            $user->passwordchange = 1;
            $user->firstname = 'Admin';
            $user->lastname = 'User';
            $user->email = 'admin@example.org';
            insert_record('usr', $user);

            set_config('installed', true);
        }
        catch (SQLException $e) {
            echo json_encode(array(
                'success' => 0,
                'errormessage' => $e->getMessage()
            ));
            exit;
        }
65
    }
66
67

    echo json_encode(array('success' => 1));
68
    exit;
69
}
Penny Leach's avatar
Penny Leach committed
70

71
$upgrade = check_upgrades($name);
Penny Leach's avatar
Penny Leach committed
72
$data = array(
73
74
75
76
    'key'        => $name
);             

if (!empty($upgrade)) {
77
    $data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
    if ($name == 'core') {
        $funname = 'upgrade_core';
    } 
    else {
        $funname = 'upgrade_plugin';
    }
    try {
        $funname($upgrade);
        $data['success'] = 1;
    } 
    catch (Exception $e) {
        $data['errormessage'] = $e->getMessage();
        $data['success']      = 0;
    }
}
else {
    $data['success'] = 1;
    $data['errormessage'] = get_string('nothingtoupgrade','admin');
}
Penny Leach's avatar
Penny Leach committed
97
echo json_encode($data);    
98
?>