Commit 153a82cc9b73fbe6a8bc3632c1673eebd81b9280

Authored by nbm
1 parent 2be40b46

Show the available upgrades, and allow them to be performed.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3361 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 85 additions and 0 deletions
setup/upgrade.php 0 → 100644
  1 +<?php
  2 +
  3 +require_once('../config/dmsDefaults.php');
  4 +require_once(KT_LIB_DIR . '/upgrades/upgrade.inc.php');
  5 +
  6 +function generateUpgradeTable () {
  7 + global $default;
  8 + $query = sprintf('SELECT value FROM %s WHERE name = "knowledgeTreeVersion"', $default->system_settings_table);
  9 + $lastVersion = DBUtil::getOneResultKey($query, 'value');
  10 + $currentVersion = $default->systemVersion;
  11 +
  12 + $upgrades = describeUpgrade($lastVersion, $currentVersion);
  13 +
  14 + $ret = "<table>\n";
  15 + $ret .= "<tr><th>Code</th><th>Description</th><th>Applied</th></tr>\n";
  16 + foreach ($upgrades as $upgrade) {
  17 + $ret .= sprintf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",
  18 + htmlspecialchars($upgrade->getDescriptor()),
  19 + htmlspecialchars($upgrade->getDescription()),
  20 + $upgrade->isAlreadyApplied() ? "Yes" : "No"
  21 + );
  22 + }
  23 + $ret .= '</table>';
  24 + return $ret;
  25 +}
  26 +
  27 +function showResult($res) {
  28 + if (PEAR::isError($res)) {
  29 + return $res->toString();
  30 + }
  31 + return $res;
  32 +}
  33 +
  34 +function performAllUpgrades () {
  35 + global $default;
  36 + $query = sprintf('SELECT value FROM %s WHERE name = "knowledgeTreeVersion"', $default->system_settings_table);
  37 + $lastVersion = DBUtil::getOneResultKey($query, 'value');
  38 + $currentVersion = $default->systemVersion;
  39 +
  40 + $upgrades = performUpgrade($lastVersion, $currentVersion);
  41 +
  42 + $ret = "<table>\n";
  43 + $ret .= "<tr><th>Code</th><th>Description<th></tr>\n";
  44 + foreach ($upgrades as $upgrade) {
  45 + $ret .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
  46 + htmlspecialchars($upgrade->getDescriptor()),
  47 + htmlspecialchars($upgrade->getDescription()),
  48 + htmlspecialchars(showResult($upgrade->getResult())));
  49 + }
  50 + $ret .= '</table>';
  51 + return $ret;
  52 +}
  53 +
  54 +$upgradeTable = generateUpgradeTable();
  55 +?>
  56 +<html>
  57 + <head>
  58 + <title>KnowledgeTree Checkup</title>
  59 + <style>
  60 +th { text-align: left; }
  61 +td { vertical-align: top; }
  62 + </style>
  63 + </head>
  64 +
  65 + <body>
  66 + <h1>KnowledgeTree Upgrades</h1>
  67 +
  68 +<?php
  69 +
  70 +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 + ";
  76 +
  77 + print $upgradeTable;
  78 +
  79 + print '<form><input type="submit" name="go" value="Upgrade" /></form>';
  80 +} else {
  81 +
  82 +}
  83 +?>
  84 + </body>
  85 +</html>
... ...