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

Penny Leach's avatar
Penny Leach committed
46
$js = 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
47
48
49
$loadingicon = theme_get_url('images/loading.gif');
$successicon = theme_get_url('images/success.gif');
$failureicon = theme_get_url('images/failure.gif');
50

51
$loadingstring = get_string('upgradeloading', 'admin');
52
$installsuccessstring = get_string('installsuccess', 'admin');
53
$successstring = get_string('upgradesuccesstoversion', 'admin');
54
$failurestring = get_string('upgradefailure', 'admin');
Penny Leach's avatar
Penny Leach committed
55
$coresuccess   = get_string('coredatasuccess', 'admin');
56

57
58
59
60
61
62
// Check if Mahara is being installed. An extra hook is required to insert core
// data if so.
if (!empty($upgrades['core']->install)) {
    $smarty->assign('install', true);
    $installjs =<<< EOJS
                    $('coredata').innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />';
63
64
65
66
67
68
69
70
71
72
73
74
75

                    sendjsonrequest(
                        'upgrade.json.php', 
                        { 'install' : 1 }, 
                        'GET',
                        function (data) {
                            if ( !data.error ) {
                                var message = '{$coresuccess}';
                                if (data.message) {
                                    message += ' (' + data.message + ')';
                                }
                                $('coredata').innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
                                $('finished').style.visibility = 'visible';
76
                            }
77
                            else {
78
79
80
81
82
83
84
85
                                var message = '';
                                if (data.message) {
                                    message = data.message;
                                } 
                                else {
                                    message = '{$failurestring}';
                                }
                                $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
86
                            }
87
88
89
90
91
                        },
                        function () {
                            $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> {$failurestring}';
                        },
                        true); // quiet.
92

93
94
95
96
97
98
EOJS;
}
else {
    $installjs = '';
}
                    
Penny Leach's avatar
Penny Leach committed
99
100
101
102
103
104
$js .= <<< EOJS
            function processNext() {
                var element = todo.shift();

                if ( ! element ) {
                    // we're done
105
                    $installjs
Penny Leach's avatar
Penny Leach committed
106
107
108
                    return;
                }

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

111
                sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) {
112
                    if ( !data.error ) {
113
                        var message;
114
                        if (data.install) {
115
116
117
118
119
                            message = '{$installsuccessstring}';
                        }
                        else {
                            message = '{$successstring}';
                        }
120
121
                        message += data.newversion;
                        $(data.key).innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
Penny Leach's avatar
Penny Leach committed
122
123
                    }
                    else {
124
                        var message = '';
125
126
                        if (data.errormessage) {
                            message = data.errormessage;
127
128
129
130
                        } 
                        else {
                            message = '{$failurestring}';
                        }
131
                        $(data.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
Penny Leach's avatar
Penny Leach committed
132
133
                    }
                    processNext();
134
135
                }, 
                function () {
136
                    $(element).innerHTML = '<img src="{$failureicon}" alt=":(" /> {$failurestring}';
137
138
                },
                true);
Penny Leach's avatar
Penny Leach committed
139
140
141
142
143
            }

            addLoadEvent( processNext );
EOJS;

144
$smarty->assign('INLINEJAVASCRIPT', $js);
Penny Leach's avatar
Penny Leach committed
145

146
$smarty->assign_by_ref('upgrades', $upgrades);
147
148
149
if (isset($upgrades['core'])) {
    $smarty->assign('releaseargs', array($upgrades['core']->torelease, $upgrades['core']->to));
}
150
151
$smarty->display('admin/upgrade.tpl');

Nigel McNie's avatar
Nigel McNie committed
152
?>