upgrade.json.php 2.09 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
$install = clean_requestdata('install', PARAM_BOOL, REQUEST_EITHER);

if ($install) {
36
    // @todo should probably report errors. Also see upgrade.php to make the js detect any errors
37
38
39
    if (!get_config('installed')) {
        set_config('installed', true);
    }
40
    exit;
41
}
Penny Leach's avatar
Penny Leach committed
42

43
$upgrade = check_upgrades($name);
Penny Leach's avatar
Penny Leach committed
44
$data = array(
45
46
47
48
    'key'        => $name
);             

if (!empty($upgrade)) {
49
    $data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    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
69
echo json_encode($data);    
70
?>