upgrade.php 4.67 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
47
48
$loadingstring = get_string('upgradeloading', 'admin');
$successstring = get_string('upgradesuccess', 'admin');
$failurestring = get_string('upgradefailure', 'admin');
49

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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}" />';
                    
                    d.addCallback(function (data) {
                        if ( data.success ) {
                            var message = 'Successfully installed core data';
                            $('coredata').innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
                        }
                        else {
                            var message = '';
                            if (data.errormessage) {
                                message = data.errormessage;
                            } 
                            else {
                                message = '{$failurestring}';
                            }
                            $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
                        }
                    });
                    d.addErrback(function () {
                        $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> {$failurestring}';
                    });
EOJS;
}
else {
    $installjs = '';
}
                    
Penny Leach's avatar
Penny Leach committed
84
85
86
87
88
89
$js .= <<< EOJS
            function processNext() {
                var element = todo.shift();

                if ( ! element ) {
                    // we're done
90
                    $installjs
91
                    $('finished').style.display = 'block';
Penny Leach's avatar
Penny Leach committed
92
93
94
95
96
                    return;
                }

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

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

                d.addCallback(function (data) {
                    if ( data.success ) {
101
                        var message = '{$successstring}' + data.newversion;
102
                        $(data.key).innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
Penny Leach's avatar
Penny Leach committed
103
104
                    }
                    else {
105
106
107
108
109
110
111
                        var message = '';
                        if (data.errormessage) {
                            message = data.errormessage;
                        } 
                        else {
                            message = '{$failurestring}';
                        }
112
                        $(data.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
Penny Leach's avatar
Penny Leach committed
113
114
115
                    }
                    processNext();
                });
116
117
                d.addErrback(function () {
                    $(element).innerHTML = '<img src="{$failureicon}" alt=":(" /> {$failurestring}';
Nigel McNie's avatar
Nigel McNie committed
118
                });
Penny Leach's avatar
Penny Leach committed
119
120
121
122
123
            }

            addLoadEvent( processNext );
EOJS;

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

126
$smarty->assign_by_ref('upgrades', $upgrades);
127
128
$smarty->display('admin/upgrade.tpl');

Nigel McNie's avatar
Nigel McNie committed
129
?>