upgrade.php 5.35 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
40
if (empty($upgrades['disablelogin'])) {
    auth_setup();
}

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

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

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

56
57
58
59
60
61
62
63
64
// 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
                    var d = loadJSONDoc('upgrade.json.php', { 'install' : 1 });
                    
                    $('coredata').innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />';
                    
65
                    d.addCallbacks(function (data) {
66
                        if ( !data.error ) {
Penny Leach's avatar
Penny Leach committed
67
                            var message = '{$coresuccess}';
68
69
70
                            if (data.message) {
                                message += ' (' + data.message + ')';
                            }
71
                            $('coredata').innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
72
                            $('finished').style.visibility = 'visible';
73
74
75
                        }
                        else {
                            var message = '';
76
77
                            if (data.message) {
                                message = data.message;
78
79
80
81
82
83
                            } 
                            else {
                                message = '{$failurestring}';
                            }
                            $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
                        }
84
                    }, function () {
85
86
                        $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> {$failurestring}';
                    });
87

88
89
90
91
92
93
EOJS;
}
else {
    $installjs = '';
}
                    
Penny Leach's avatar
Penny Leach committed
94
95
96
97
98
99
$js .= <<< EOJS
            function processNext() {
                var element = todo.shift();

                if ( ! element ) {
                    // we're done
100
                    $installjs
Penny Leach's avatar
Penny Leach committed
101
102
103
104
105
                    return;
                }

                var d = loadJSONDoc('upgrade.json.php', { 'name': element });

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

108
                d.addCallbacks(function (data) {
109
                    if ( !data.error ) {
110
                        var message;
Penny Leach's avatar
Penny Leach committed
111
                        if (data.message.install) {
112
113
114
115
116
                            message = '{$installsuccessstring}';
                        }
                        else {
                            message = '{$successstring}';
                        }
Penny Leach's avatar
Penny Leach committed
117
118
                        message += data.message.newversion;
                        $(data.message.key).innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
Penny Leach's avatar
Penny Leach committed
119
120
                    }
                    else {
121
                        var message = '';
Penny Leach's avatar
Penny Leach committed
122
123
                        if (data.message.errormessage) {
                            message = data.message.errormessage;
124
125
126
127
                        } 
                        else {
                            message = '{$failurestring}';
                        }
Penny Leach's avatar
Penny Leach committed
128
                        $(data.message.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
Penny Leach's avatar
Penny Leach committed
129
130
                    }
                    processNext();
131
                }, function () {
132
                    $(element).innerHTML = '<img src="{$failureicon}" alt=":(" /> {$failurestring}';
Nigel McNie's avatar
Nigel McNie committed
133
                });
Penny Leach's avatar
Penny Leach committed
134
135
136
137
138
            }

            addLoadEvent( processNext );
EOJS;

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

141
$smarty->assign_by_ref('upgrades', $upgrades);
142
143
144
if (isset($upgrades['core'])) {
    $smarty->assign('releaseargs', array($upgrades['core']->torelease, $upgrades['core']->to));
}
145
146
$smarty->display('admin/upgrade.tpl');

Nigel McNie's avatar
Nigel McNie committed
147
?>