upgrade.php 4.98 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
49
$successstring = get_string('upgradesuccess', 'admin');
$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.success ) {
Penny Leach's avatar
Penny Leach committed
63
                            var message = '{$coresuccess}';
64
                            $('coredata').innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
65
                            $('finished').style.visibility = 'visible';
66
67
68
69
70
71
72
73
74
75
76
                        }
                        else {
                            var message = '';
                            if (data.errormessage) {
                                message = data.errormessage;
                            } 
                            else {
                                message = '{$failurestring}';
                            }
                            $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
                        }
77
                    }, function () {
78
79
                        $('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> {$failurestring}';
                    });
80

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

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

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

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

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

            addLoadEvent( processNext );
EOJS;

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

134
$smarty->assign_by_ref('upgrades', $upgrades);
135
136
$smarty->display('admin/upgrade.tpl');

Nigel McNie's avatar
Nigel McNie committed
137
?>