Commit 6123e00a0f5d64e6d4519e522e44a4fcb64f1979

Authored by nbm
1 parent 2afef090

Handle the final upgrade API.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3379 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 38 additions and 13 deletions
setup/upgrade.php
... ... @@ -26,8 +26,17 @@ function generateUpgradeTable () {
26 26  
27 27 function showResult($res) {
28 28 if (PEAR::isError($res)) {
  29 + if (is_a($res, 'Upgrade_Already_Applied')) {
  30 + return "Already applied";
  31 + }
29 32 return $res->toString();
30 33 }
  34 + if ($res === true) {
  35 + return "Success";
  36 + }
  37 + if ($res === false) {
  38 + return "Failure";
  39 + }
31 40 return $res;
32 41 }
33 42  
... ... @@ -37,21 +46,26 @@ function performAllUpgrades () {
37 46 $lastVersion = DBUtil::getOneResultKey($query, 'value');
38 47 $currentVersion = $default->systemVersion;
39 48  
40   - $upgrades = performUpgrade($lastVersion, $currentVersion);
  49 + $upgrades = describeUpgrade($lastVersion, $currentVersion);
41 50  
42   - $ret = "<table>\n";
43   - $ret .= "<tr><th>Code</th><th>Description<th></tr>\n";
  51 + $ret = "<table width=\"100%\">\n";
  52 + $ret .= "<tr><th>Description</th><th>Result</th></tr>\n";
44 53 foreach ($upgrades as $upgrade) {
45   - $ret .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
46   - htmlspecialchars($upgrade->getDescriptor()),
  54 + $res = $upgrade->performUpgrade();
  55 + $ret .= sprintf('<tr><td>%s</td><td>%s</td></tr>',
47 56 htmlspecialchars($upgrade->getDescription()),
48   - htmlspecialchars(showResult($upgrade->getResult())));
  57 + htmlspecialchars(showResult($res)));
49 58 }
50 59 $ret .= '</table>';
51 60 return $ret;
52 61 }
53 62  
54   -$upgradeTable = generateUpgradeTable();
  63 +if ($_REQUEST["go"] === "Upgrade") {
  64 + $performingUpgrade = true;
  65 + $upgradeTable = performAllUpgrades();
  66 +} else {
  67 + $upgradeTable = generateUpgradeTable();
  68 +}
55 69 ?>
56 70 <html>
57 71 <head>
... ... @@ -68,15 +82,26 @@ td { vertical-align: top; }
68 82 <?php
69 83  
70 84 if ($upgradeTable) {
71   - print "
72   - <p>The table below describes the upgrades that need to occur to
73   - upgrade your KnowledgeTree installation to <strong>$default->systemVersion</strong>.
74   - Click on the button below the table to perform the upgrades.</p>
75   - ";
  85 + if (!$performingUpgrade) {
  86 + print "
  87 + <p>The table below describes the upgrades that need to occur to
  88 + upgrade your KnowledgeTree installation to <strong>$default->systemVersion</strong>.
  89 + Click on the button below the table to perform the upgrades.</p>
  90 + ";
  91 + } else {
  92 + print "
  93 + <p>The table below describes the upgrades that have occurred to
  94 + upgrade your KnowledgeTree installation to <strong>$default->systemVersion</strong>.
  95 + ";
  96 + }
76 97  
77 98 print $upgradeTable;
78 99  
79   - print '<form><input type="submit" name="go" value="Upgrade" /></form>';
  100 + if (!$performingUpgrade) {
  101 + print '<form><input type="submit" name="go" value="Upgrade" /></form>';
  102 + } else {
  103 + print '<form><input type="submit" name="go" value="ShowUpgrades" /></form>';
  104 + }
80 105 } else {
81 106  
82 107 }
... ...