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

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

require(dirname(dirname(__FILE__)).'/init.php');
33
require(get_config('libroot') . 'upgrade.php');
34

35
$smarty = smarty();
36

37
$upgrades = check_upgrades();
38
39
40
41
42
43
44
45
46
if (!empty($upgrades['core']->install)) {
    define('TITLE', get_string('installation', 'admin'));
    $smarty->assign('upgradeheading', get_string('performinginstallation', 'admin'));
}
else {
    define('TITLE', get_string('upgrades', 'admin'));
    $smarty->assign('upgradeheading', get_string('performingupgrades', 'admin'));
}

47
48
49
if (empty($upgrades['disablelogin'])) {
    auth_setup();
}
50
unset($upgrades['disablelogin']);
51

52
53
54
if (!$upgrades) {
    die_info(get_string('noupgrades', 'admin'));
}
55

56
57
58
$loadingicon = $THEME->get_url('images/loading.gif');
$successicon = $THEME->get_url('images/success.gif');
$failureicon = $THEME->get_url('images/failure.gif');
59

60
61
// Remove all files in the smarty and dwoo caches
// TODO post 1.2 remove the smarty part
62
63
64
65
66
67
68
69
70
71
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);
}
72
73
74
75
76
77
78
79
80
81
$basedir = get_config('dataroot') . 'dwoo/compile/';
$dh = new DirectoryIterator($basedir);
foreach ($dh as $themedir) {
    if ($themedir->isDot()) continue;
    $themedirname = $basedir . $themedir->getFilename();
    rmdirr($themedirname);
    clearstatcache();
    check_dir_exists($themedirname);
}

82

83
84
85
86
87
$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'));
88
$localsuccess  = json_encode(get_string('localdatasuccess', 'admin'));
89

90
91
92
// Check if Mahara is being installed. An extra hook is required to insert core
// data if so.
if (!empty($upgrades['core']->install)) {
93
    $upgrades['firstcoredata'] = true;
94
    $upgrades['localpreinst'] = true;
95
    $upgrades['lastcoredata'] = true;
96
    $upgrades['localpostinst'] = true;
97
    $smarty->assign('install', true);
98
}                   
99

100
$js = <<< EOJS
Penny Leach's avatar
Penny Leach committed
101
102
103
            function processNext() {
                var element = todo.shift();

104
105
106
                if (!element) {
                    $('finished').style.visibility = 'visible';
                    return; // done
Penny Leach's avatar
Penny Leach committed
107
108
                }

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

111
                sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) {
112
                    if ( !data.error ) {
113
                        var message;
114
115
116
                        if (data.coredata) {
                            message = {$coresuccess};
                        } 
117
118
119
                        else if (data.localdata) {
                            message = {$localsuccess};
                        }
120
                        else {
121
122
123
124
125
126
127
                            if (data.install) {
                                message = {$installsuccessstring};
                            }
                            else {
                                message = {$successstring};
                            }
                            message += data.newversion;
128
                        }
129
                        $(data.key).innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
130
                        processNext();
Penny Leach's avatar
Penny Leach committed
131
132
                    }
                    else {
133
                        var message = '';
134
135
                        if (data.errormessage) {
                            message = data.errormessage;
136
137
                        } 
                        else {
138
                            message = {$failurestring};
139
                        }
140
                        $(data.key).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
Penny Leach's avatar
Penny Leach committed
141
                    }
142
143
                }, 
                function () {
144
                    $(element).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + {$failurestring};
145
146
                },
                true);
Penny Leach's avatar
Penny Leach committed
147
148
149
150
151
            }

            addLoadEvent( processNext );
EOJS;

152
153
uksort($upgrades, 'sort_upgrades');
$js .= "\n" . 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
154
$smarty->assign('INLINEJAVASCRIPT', $js);
Penny Leach's avatar
Penny Leach committed
155

156
$smarty->assign_by_ref('upgrades', $upgrades);
157
158
159
if (isset($upgrades['core'])) {
    $smarty->assign('releaseargs', array($upgrades['core']->torelease, $upgrades['core']->to));
}
160
161
$smarty->display('admin/upgrade.tpl');

162
163


Nigel McNie's avatar
Nigel McNie committed
164
?>