upgrade.php 5.05 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * 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 3 of the License, or
 * (at your option) any later version.
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * 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.
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
 *
 * @package    mahara
 * @subpackage admin
21
 * @author     Catalyst IT Ltd
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
24
25
26
 *
 */

27
define('INTERNAL', 1);
28
define('ADMIN', 1);
29
define('INSTALLER', 1);
30
31

require(dirname(dirname(__FILE__)).'/init.php');
32
define('TITLE', get_string('upgrades', 'admin'));
33
require(get_config('libroot') . 'upgrade.php');
34

35
$smarty = smarty();
36

37
$upgrades = check_upgrades();
38
39
40
if (empty($upgrades['disablelogin'])) {
    auth_setup();
}
41
unset($upgrades['disablelogin']);
42

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

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
52
53
54
55
56
57
58
59
60
61
62
// Remove all files in the smarty cache
require_once('file.php');
$basedir = get_config('dataroot') . 'smarty/compile/';
$dh = new DirectoryIterator($basedir);
foreach ($dh as $themedir) {
    if ($themedir->isDot()) continue;
    $themedirname = $basedir . $themedir->getFilename();
    rmdirr($themedirname);
    clearstatcache();
    check_dir_exists($themedirname);
}

63
64
65
66
67
$loadingstring = json_encode(get_string('upgradeloading', 'admin'));
$installsuccessstring = json_encode(get_string('installsuccess', 'admin'));
$successstring = json_encode(get_string('upgradesuccesstoversion', 'admin'));
$failurestring = json_encode(get_string('upgradefailure', 'admin'));
$coresuccess   = json_encode(get_string('coredatasuccess', 'admin'));
68
$localsuccess  = json_encode(get_string('localdatasuccess', 'admin'));
69

70
71
72
// Check if Mahara is being installed. An extra hook is required to insert core
// data if so.
if (!empty($upgrades['core']->install)) {
73
    $upgrades['firstcoredata'] = true;
74
    $upgrades['localpreinst'] = true;
75
    $upgrades['lastcoredata'] = true;
76
    $upgrades['localpostinst'] = true;
77
    $smarty->assign('install', true);
78
}                   
79

80
$js = <<< EOJS
Penny Leach's avatar
Penny Leach committed
81
82
83
            function processNext() {
                var element = todo.shift();

84
85
86
                if (!element) {
                    $('finished').style.visibility = 'visible';
                    return; // done
Penny Leach's avatar
Penny Leach committed
87
88
                }

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

91
                sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) {
92
                    if ( !data.error ) {
93
                        var message;
94
95
96
                        if (data.coredata) {
                            message = {$coresuccess};
                        } 
97
98
99
                        else if (data.localdata) {
                            message = {$localsuccess};
                        }
100
                        else {
101
102
103
104
105
106
107
                            if (data.install) {
                                message = {$installsuccessstring};
                            }
                            else {
                                message = {$successstring};
                            }
                            message += data.newversion;
108
                        }
109
                        $(data.key).innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
110
                        processNext();
Penny Leach's avatar
Penny Leach committed
111
112
                    }
                    else {
113
                        var message = '';
114
115
                        if (data.errormessage) {
                            message = data.errormessage;
116
117
                        } 
                        else {
118
                            message = {$failurestring};
119
                        }
120
                        $(data.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
Penny Leach's avatar
Penny Leach committed
121
                    }
122
123
                }, 
                function () {
124
                    $(element).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + {$failurestring};
125
126
                },
                true);
Penny Leach's avatar
Penny Leach committed
127
128
129
130
131
            }

            addLoadEvent( processNext );
EOJS;

132
133
uksort($upgrades, 'sort_upgrades');
$js .= "\n" . 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
134
$smarty->assign('INLINEJAVASCRIPT', $js);
Penny Leach's avatar
Penny Leach committed
135

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

142
143


Nigel McNie's avatar
Nigel McNie committed
144
?>