upgrade.php
3.06 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
<?php
$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 = "knowledgeTreeVersion"', $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 "Already applied";
}
return $res->toString();
}
if ($res === true) {
return "Success";
}
if ($res === false) {
return "Failure";
}
return $res;
}
function performAllUpgrades () {
global $default;
$query = sprintf('SELECT value FROM %s WHERE name = "knowledgeTreeVersion"', $default->system_settings_table);
$lastVersion = DBUtil::getOneResultKey($query, 'value');
$currentVersion = $default->systemVersion;
$upgrades = describeUpgrade($lastVersion, $currentVersion);
print "<table width=\"100%\">\n";
print "<tr><th>Description</th><th>Result</th></tr>\n";
foreach ($upgrades as $upgrade) {
$res = $upgrade->performUpgrade();
printf("<tr><td>%s</td><td>%s</td></tr>\n",
htmlspecialchars($upgrade->getDescription()),
htmlspecialchars(showResult($res)));
}
print '</table>';
return $ret;
}
if ($_REQUEST["go"] === "Upgrade") {
$performingUpgrade = true;
} else {
$upgradeTable = generateUpgradeTable();
}
?>
<html>
<head>
<title>KnowledgeTree Checkup</title>
<style>
th { text-align: left; }
td { vertical-align: top; }
</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>
";
} else {
print "
<p>The table below describes the upgrades that have occurred to
upgrade your KnowledgeTree installation to <strong>$default->systemVersion</strong>.
";
$upgradeTable = performAllUpgrades();
}
print $upgradeTable;
if (!$performingUpgrade) {
print '<form><input type="submit" name="go" value="Upgrade" /></form>';
} else {
print '<form><input type="submit" name="go" value="ShowUpgrades" /></form>';
}
?>
</body>
</html>