upgrade.json.php 2.64 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
define('INTERNAL', 1);
28
define('ADMIN', 1);
29
define('INSTALLER', 1);
30
31
define('JSON', 1);

Penny Leach's avatar
Penny Leach committed
32
require(dirname(dirname(__FILE__)) . '/init.php');
33
require(get_config('libroot') . 'upgrade.php');
Penny Leach's avatar
Penny Leach committed
34

35
36
$name    = param_variable('name');
$install = ($name == 'firstcoredata' || $name == 'lastcoredata');
37
if (!$install) {
38
39
40
41
42
    $upgrade = check_upgrades($name);
    
    if (empty($upgrade->disablelogin)) {
        auth_setup();
    }
43
}
44

45
46
47
$data = array(
    'key'        => $name
);             
48
49
if ($install) {
    if (!get_config('installed')) {
50
        try {
51
52
            $fun = 'core_install_' . $name . '_defaults';
            $fun();
53
54
        }
        catch (SQLException $e) {
55
            json_reply('local', array('key' => $name, 'errormessage' => $e->getMessage()));
56
        }
57
    }
58
59
    $data['coredata'] = true;
    json_reply(false, $data);
60
}
Penny Leach's avatar
Penny Leach committed
61

62
if (!empty($upgrade)) {
63
    $data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ;
64
65
66
67
68
69
70
71
    if ($name == 'core') {
        $funname = 'upgrade_core';
    } 
    else {
        $funname = 'upgrade_plugin';
    }
    try {
        $funname($upgrade);
Penny Leach's avatar
Penny Leach committed
72
73
74
        if (isset($upgrade->install)) {
            $data['install'] = $upgrade->install;
        }
75
        $data['error'] = false;
Penny Leach's avatar
Penny Leach committed
76
77
        json_reply(false, $data);
        exit;
78
79
    } 
    catch (Exception $e) {
80
81
        list($texttrace, $htmltrace) = log_build_backtrace($e->getTrace());
        $data['errormessage'] = $e->getMessage() . '<br>' . $htmltrace;
82
83
        $data['error'] = true;
        json_reply('local', $data);
Penny Leach's avatar
Penny Leach committed
84
        exit;
85
86
87
    }
}
else {
88
    json_reply(false, array('error' => false,
89
                            'message' => get_string('nothingtoupgrade','admin')));
Penny Leach's avatar
Penny Leach committed
90
    exit;
91
}
92
?>