From 2afef090d20df9385fe04b6750cfd448df91acb4 Mon Sep 17 00:00:00 2001 From: nbm Date: Wed, 15 Jun 2005 21:28:17 +0000 Subject: [PATCH] Check whether the upgrade table exists before checking if an upgrade has been installed. --- lib/upgrades/UpgradeItems.inc.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/upgrades/UpgradeItems.inc.php b/lib/upgrades/UpgradeItems.inc.php index 2f81643..f74b77d 100644 --- a/lib/upgrades/UpgradeItems.inc.php +++ b/lib/upgrades/UpgradeItems.inc.php @@ -72,7 +72,19 @@ class UpgradeItem { return $this->type; } + function _upgradeTableInstalled() { + $query = "SELECT COUNT(id) FROM upgrades"; + $res = DBUtil::getOneResult($query); + if (PEAR::isError($res)) { + return false; + } + return true; + } + function isAlreadyApplied() { + if (!$this->_upgradeTableInstalled()) { + return false; + } $query = "SELECT id FROM upgrades WHERE descriptor = ? AND result = ?"; $params = array($this->getDescriptor(), true); $res = DBUtil::getOneResultKey(array($query, $params), 'id'); @@ -87,12 +99,15 @@ class UpgradeItem { function performUpgrade($force = false) { $res = $this->isAlreadyApplied(); - if ($res === true || PEAR::isError($res)) { + if ($res === true) { if ($force !== true) { // PHP5: Exception return new Upgrade_Already_Applied($this); } } + if (PEAR::isError($res)) { + return $res; + } $res = $this->_performUpgrade(); if (PEAR::isError($res)) { $this->_recordUpgrade(false); @@ -259,8 +274,7 @@ class SQLUpgradeItem extends UpgradeItem { global $default; $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/'; $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name); - var_dump($queries); - //return DBUtil::runQueries($queries); + return DBUtil::runQueries($queries, $default->_admindb); } } -- libgit2 0.21.4