upgrade.php
5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* $Id$
*
* The contents of this file are subject to the KnowledgeTree Public
* License Version 1.1 ("License"); You may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.knowledgetree.com/KPL
*
* Software distributed under the License is distributed on an "AS IS"
* basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is: KnowledgeTree Open Source
*
* The Initial Developer of the Original Code is The Jam Warehouse Software
* (Pty) Ltd, trading as KnowledgeTree.
* Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
* (C) 2007 The Jam Warehouse Software (Pty) Ltd;
* All Rights Reserved.
*
*/
$GLOBALS["checkup"] = true;
require_once('../config/dmsDefaults.php');
require_once(KT_LIB_DIR . '/upgrades/upgrade.inc.php');
function generateUpgradeTable () {
global $default;
$query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);
$lastVersion = DBUtil::getOneResultKey($query, 'value');
$currentVersion = $default->systemVersion;
$upgrades = describeUpgrade($lastVersion, $currentVersion);
$ret = "<table>\n";
$ret .= "<tr><th>Code</th><th>Description</th><th>Applied</th></tr>\n";
foreach ($upgrades as $upgrade) {
$ret .= sprintf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",
htmlspecialchars($upgrade->getDescriptor()),
htmlspecialchars($upgrade->getDescription()),
$upgrade->isAlreadyApplied() ? "Yes" : "No"
);
}
$ret .= '</table>';
return $ret;
}
function showResult($res) {
if (PEAR::isError($res)) {
if (is_a($res, 'Upgrade_Already_Applied')) {
return '<span style="color: orange">Already applied</span>';
}
return sprintf('<span style="color: red">%s</span>', htmlspecialchars($res->toString()));
}
if ($res === true) {
return '<span style="color: green">Success</span>';
}
if ($res === false) {
return '<span style="color: red">Failure</span>';
}
return $res;
}
$GLOBALS['row'] = 1;
function performAllUpgrades () {
global $default;
$query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);
$lastVersion = DBUtil::getOneResultKey($query, 'value');
$currentVersion = $default->systemVersion;
$upgrades = describeUpgrade($lastVersion, $currentVersion);
foreach ($upgrades as $upgrade) {
if (($GLOBALS['row'] % 2) == 1) {
$class = "odd";
} else {
$class = "even";
}
printf('<div class="row %s"><div class="foo">%s</div>' . "\n", $class, htmlspecialchars($upgrade->getDescription()));
$GLOBALS['row']++;
ob_flush();
flush();
$res = $upgrade->performUpgrade();
printf('<div class="bar">%s</div>', showResult($res));
print '<br style="clear: both">' . "\n";
ob_flush();
flush();
print "</div>\n";
if (PEAR::isError($res)) {
if (!is_a($res, 'Upgrade_Already_Applied')) {
break;
} else {
$res = true;
}
}
if ($res === false) {
$res = PEAR::raiseError("Upgrade returned false");
break;
}
}
return $res;
}
function failWritablePath($name, $path) {
if (!is_writable($path)) {
sprintf("The path for setting %s, which is set to %s, can not be written to. Correct this situation before continuing.", $name, $path);
exit(1);
}
}
failWritablePath('Log directory', $default->logDirectory);
failWritablePath('Document directory', $default->documentRoot);
if (PEAR::isError($loggingSupport)) {
print '<p><font color="red">Logging support is not currently working. Check post-installation checkup.</font></p>';
exit(1);
}
if (PEAR::isError($dbSupport)) {
print '<p><font color="red">Database support is not currently working. Check post-installation checkup.</font></p>';
exit(1);
}
if ($_REQUEST["go"] === "Upgrade") {
$performingUpgrade = true;
} else {
$upgradeTable = generateUpgradeTable();
}
?>
<html>
<head>
<title>KnowledgeTree Upgrade</title>
<style>
th { text-align: left; }
td { vertical-align: top; }
.foo { float: left; }
.bar { padding-left: 2em; float: right; }
.odd { background-color: #eeeeee; }
.even { background-color: #dddddd; }
.row { padding: 0.5em 1em; }
</style>
</head>
<body>
<h1>KnowledgeTree Upgrades</h1>
<?php
if (!$performingUpgrade) {
print "
<p>The table below describes the upgrades that need to occur to
upgrade your KnowledgeTree installation to <strong>$default->systemVersion</strong>.
Click on the button below the table to perform the upgrades.</p>
";
$upgradeTable = generateUpgradeTable();
print $upgradeTable;
print '<form><input type="submit" name="go" value="Upgrade" /></form>';
print '</body></html>';
} else {
print "
<p>The table below describes the upgrades that have occurred to
upgrade your KnowledgeTree installation to <strong>$default->systemVersion</strong>.
";
$res = performAllUpgrades();
if (PEAR::isError($res)) {
print '<font color="red">Upgrade failed.</font>' . "\n";
} else {
$sUrl = generateLink("");
print sprintf('<font color="green">Upgrade succeeded. Now
try <a href="%s">log in and use the system</a>.</font>',
$sUrl) . "\n";
}
print '</body></html>';
}
?>