upgrade.php 4.34 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

require(dirname(dirname(__FILE__)).'/init.php');
32
require(get_config('libroot') . 'upgrade.php');
33

34
$smarty = smarty();
35

36
$upgrades = check_upgrades();
37
38
39
if (empty($upgrades['disablelogin'])) {
    auth_setup();
}
40
unset($upgrades['disablelogin']);
41

42
43
44
if (!$upgrades) {
    die_info(get_string('noupgrades', 'admin'));
}
45

46
47
48
$loadingicon = theme_get_url('images/loading.gif');
$successicon = theme_get_url('images/success.gif');
$failureicon = theme_get_url('images/failure.gif');
49

50
51
52
53
54
$loadingstring = json_encode(get_string('upgradeloading', 'admin'));
$installsuccessstring = json_encode(get_string('installsuccess', 'admin'));
$successstring = json_encode(get_string('upgradesuccesstoversion', 'admin'));
$failurestring = json_encode(get_string('upgradefailure', 'admin'));
$coresuccess   = json_encode(get_string('coredatasuccess', 'admin'));
55

56
57
58
// Check if Mahara is being installed. An extra hook is required to insert core
// data if so.
if (!empty($upgrades['core']->install)) {
59
60
    $upgrades['firstcoredata'] = true;
    $upgrades['lastcoredata'] = true;
61
    $smarty->assign('install', true);
62
}                   
63

64
$js = <<< EOJS
Penny Leach's avatar
Penny Leach committed
65
66
67
            function processNext() {
                var element = todo.shift();

68
69
70
                if (!element) {
                    $('finished').style.visibility = 'visible';
                    return; // done
Penny Leach's avatar
Penny Leach committed
71
72
                }

73
                $(element).innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />';
Penny Leach's avatar
Penny Leach committed
74

75
                sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) {
76
                    if ( !data.error ) {
77
                        var message;
78
79
80
                        if (data.coredata) {
                            message = {$coresuccess};
                        } 
81
                        else {
82
83
84
85
86
87
88
                            if (data.install) {
                                message = {$installsuccessstring};
                            }
                            else {
                                message = {$successstring};
                            }
                            message += data.newversion;
89
                        }
90
                        $(data.key).innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
91
                        processNext();
Penny Leach's avatar
Penny Leach committed
92
93
                    }
                    else {
94
                        var message = '';
95
96
                        if (data.errormessage) {
                            message = data.errormessage;
97
98
                        } 
                        else {
99
                            message = {$failurestring};
100
                        }
101
                        $(data.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
Penny Leach's avatar
Penny Leach committed
102
                    }
103
104
                }, 
                function () {
105
                    $(element).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + {$failurestring};
106
107
                },
                true);
Penny Leach's avatar
Penny Leach committed
108
109
110
111
112
            }

            addLoadEvent( processNext );
EOJS;

113
114
uksort($upgrades, 'sort_upgrades');
$js .= "\n" . 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
115
$smarty->assign('INLINEJAVASCRIPT', $js);
Penny Leach's avatar
Penny Leach committed
116

117
$smarty->assign_by_ref('upgrades', $upgrades);
118
119
120
if (isset($upgrades['core'])) {
    $smarty->assign('releaseargs', array($upgrades['core']->torelease, $upgrades['core']->to));
}
121
122
$smarty->display('admin/upgrade.tpl');

123
124


Nigel McNie's avatar
Nigel McNie committed
125
?>