Commit 2afef090d20df9385fe04b6750cfd448df91acb4

Authored by nbm
1 parent e9b82f84

Check whether the upgrade table exists before checking if an upgrade has

been installed.

Run SQL queries using the admin db connection set up in upgrades.inc.php


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3378 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/upgrades/UpgradeItems.inc.php
@@ -72,7 +72,19 @@ class UpgradeItem { @@ -72,7 +72,19 @@ class UpgradeItem {
72 return $this->type; 72 return $this->type;
73 } 73 }
74 74
  75 + function _upgradeTableInstalled() {
  76 + $query = "SELECT COUNT(id) FROM upgrades";
  77 + $res = DBUtil::getOneResult($query);
  78 + if (PEAR::isError($res)) {
  79 + return false;
  80 + }
  81 + return true;
  82 + }
  83 +
75 function isAlreadyApplied() { 84 function isAlreadyApplied() {
  85 + if (!$this->_upgradeTableInstalled()) {
  86 + return false;
  87 + }
76 $query = "SELECT id FROM upgrades WHERE descriptor = ? AND result = ?"; 88 $query = "SELECT id FROM upgrades WHERE descriptor = ? AND result = ?";
77 $params = array($this->getDescriptor(), true); 89 $params = array($this->getDescriptor(), true);
78 $res = DBUtil::getOneResultKey(array($query, $params), 'id'); 90 $res = DBUtil::getOneResultKey(array($query, $params), 'id');
@@ -87,12 +99,15 @@ class UpgradeItem { @@ -87,12 +99,15 @@ class UpgradeItem {
87 99
88 function performUpgrade($force = false) { 100 function performUpgrade($force = false) {
89 $res = $this->isAlreadyApplied(); 101 $res = $this->isAlreadyApplied();
90 - if ($res === true || PEAR::isError($res)) { 102 + if ($res === true) {
91 if ($force !== true) { 103 if ($force !== true) {
92 // PHP5: Exception 104 // PHP5: Exception
93 return new Upgrade_Already_Applied($this); 105 return new Upgrade_Already_Applied($this);
94 } 106 }
95 } 107 }
  108 + if (PEAR::isError($res)) {
  109 + return $res;
  110 + }
96 $res = $this->_performUpgrade(); 111 $res = $this->_performUpgrade();
97 if (PEAR::isError($res)) { 112 if (PEAR::isError($res)) {
98 $this->_recordUpgrade(false); 113 $this->_recordUpgrade(false);
@@ -259,8 +274,7 @@ class SQLUpgradeItem extends UpgradeItem { @@ -259,8 +274,7 @@ class SQLUpgradeItem extends UpgradeItem {
259 global $default; 274 global $default;
260 $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/'; 275 $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/';
261 $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name); 276 $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name);
262 - var_dump($queries);  
263 - //return DBUtil::runQueries($queries); 277 + return DBUtil::runQueries($queries, $default->_admindb);
264 } 278 }
265 } 279 }
266 280