upgrade.php 5.29 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 (!$upgrades) {
    die_info(get_string('noupgrades', 'admin'));
}
40

Penny Leach's avatar
Penny Leach committed
41
$js = 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
42
43
44
45
$loadingicon = theme_get_image_path('loading.gif');
$successicon = theme_get_image_path('success.gif');
$failureicon = theme_get_image_path('failure.gif');

46
$loadingstring = get_string('upgradeloading', 'admin');
47
$installsuccessstring = get_string('installsuccess', 'admin');
48
$successstring = get_string('upgradesuccesstoversion', 'admin');
49
$failurestring = get_string('upgradefailure', 'admin');
Penny Leach's avatar
Penny Leach committed
50
$coresuccess   = get_string('coredatasuccess', 'admin');
51

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

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

                if ( ! element ) {
                    // we're done
96
                    $installjs
Penny Leach's avatar
Penny Leach committed
97
98
99
100
101
                    return;
                }

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

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

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

            addLoadEvent( processNext );
EOJS;

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

137
$smarty->assign_by_ref('upgrades', $upgrades);
138
139
140
if (isset($upgrades['core'])) {
    $smarty->assign('releaseargs', array($upgrades['core']->torelease, $upgrades['core']->to));
}
141
142
$smarty->display('admin/upgrade.tpl');

Nigel McNie's avatar
Nigel McNie committed
143
?>