diff --git a/setup/migrate/steps/migrateInstallation.php b/setup/migrate/steps/migrateInstallation.php index 0c98bcc..4a696e5 100644 --- a/setup/migrate/steps/migrateInstallation.php +++ b/setup/migrate/steps/migrateInstallation.php @@ -148,7 +148,7 @@ class migrateInstallation extends step return false; } else { $this->foundVersion = $this->readVersion(); - if($version) { + if($this->foundVersion) { $this->checkVersion(); } $this->storeSilent(); @@ -239,6 +239,8 @@ class migrateInstallation extends step ); $ktSettings = $this->util->iniUtilities->getSection('KnowledgeTree'); $froot = $ktSettings['fileSystemRoot']; +// print_r($ktSettings); +// die; if ($froot == 'default') { $froot = $this->location; } diff --git a/setup/postcheckup.php b/setup/postcheckup.php index 322a627..fb69501 100644 --- a/setup/postcheckup.php +++ b/setup/postcheckup.php @@ -38,7 +38,7 @@ $checkup = true; error_reporting(E_ALL); -require_once('../config/dmsDefaults.php'); +//require_once('../config/dmsDefaults.php'); function writablePath($name, $path) { $ret = sprintf('
'; +// print_r($result); +// echo ''; + if($checkResult) { + $assArr = $this->dbUtilities->fetchAssoc($result); +// echo '
'; +// print_r($assArr); +// echo ''; +// if(is_null($assArr)) { +// echo '=== null ===
'; +// print_r($assArr); +// echo ''; + return !is_null($result); } function _upgradeTableInstalled() { $query = "SELECT COUNT(id) FROM upgrades"; - $res = $this->runDBQuery($query); + $res = $this->runDBQuery($query, true, true); if($res) { return true; } @@ -146,8 +169,9 @@ class UpgradeItem extends InstallUtil { return false; } $query = "SELECT id FROM upgrades WHERE descriptor = '".$this->getDescriptor()."' AND result = 1"; - $res = $this->runDBQuery($query); - if($res) { + $res = $this->runDBQuery($query, true, false); + + if(!$res) { return true; } return false; @@ -161,27 +185,30 @@ class UpgradeItem extends InstallUtil { return new Upgrade_Already_Applied($this); } } -// if (PEAR::isError($res)) { -// return $res; +// if (!$res) { +// $this->error[] = 'An Error Has Occured'; // } - $oCache =& KTCache::getSingleton(); - $save = $oCache->bEnabled; - $oCache->bEnabled = false; +// $oCache =& KTCache::getSingleton(); +// $save = $oCache->bEnabled; +// $oCache->bEnabled = false; $res = $this->_performUpgrade(); - $oCache->bEnabled = $save; -// if (PEAR::isError($res)) { -// $this->_recordUpgrade(false); -// return $res; -// } +// $oCache->bEnabled = $save; + if (!$res) { + $this->_recordUpgrade(false); + $this->error[] = $this->dbUtilities->getErrors(); + return false; + } $res = $this->_recordUpgrade(true); -// if (PEAR::isError($res)) { -// return $res; -// } + if (!$res) { + $this->error[] = 'An Error Has Occured 1'; + return false; + } return true; } function _performUpgrade() { -// return PEAR::raiseError("Unimplemented"); + $this->error[] = 'Unimplemented'; + return false; } function _recordUpgrade($result) { @@ -193,17 +220,10 @@ class UpgradeItem extends InstallUtil { } else { $parentid = null; } - //TODO: Where is the code? - exit("add code"); - /*return $this->autoInsert(); - - DBUtil::autoInsert("upgrades", array( - "descriptor" => $this->getDescriptor(), - "description" => $this->description, - "date_performed" => $this->date, - "result" => $result, - "parent" => $parentid, - ));*/ + $sql = "INSERT INTO upgrades (`id`, `descriptor`, `description`, `date_performed`, `result`, `parent`) VALUES ('', '". $this->getDescriptor()."', '".$this->description."', '".$this->date."', '".$result."', '".$parentid."')"; + $this->dbUtilities->query($sql); + + return true; } // STATIC @@ -358,15 +378,13 @@ class SQLUpgradeItem extends UpgradeItem { } function _performUpgrade() { -// global $default; $dbType = 'mysql'; $sqlupgradedir = KT_DIR . 'sql/' . $dbType . '/upgrade/'; $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name); - exit('add code'); -// return DBUtil::runQueries($queries, $default->_admindb); + return $this->dbUtilities->runQueries($queries); } - + } class KTRebuildPermissionObserver { @@ -426,8 +444,8 @@ class RecordUpgradeItem extends UpgradeItem { $query = "UPDATE system_settings SET value = '$systemVersion' WHERE name = 'knowledgetreeVersion'"; $this->runDBQuery($query); $query = "UPDATE system_settings SET value = '{$this->version}' WHERE name = 'databaseVersion'"; - $assArray = $this->runDBQuery($query); - return !is_null($assArray); + $result = $this->runDBQuery($query); + return $result; } function _deleteSmartyFiles() { diff --git a/setup/upgrade/steps/upgradeComplete.php b/setup/upgrade/steps/upgradeComplete.php index 99471f4..11f48d8 100644 --- a/setup/upgrade/steps/upgradeComplete.php +++ b/setup/upgrade/steps/upgradeComplete.php @@ -48,6 +48,7 @@ class upgradeComplete extends Step { public function doStep() { $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent); + $this->doRun(); return 'landing'; } @@ -61,6 +62,8 @@ class upgradeComplete extends Step { * */ private function storeSilent() { + $v = $this->getDataFromSession('upgradeProperties'); + $this->temp_variables['sysVersion'] = $v['upgrade_version']; } } diff --git a/setup/upgrade/steps/upgradeDatabase.php b/setup/upgrade/steps/upgradeDatabase.php index 61e05bf..ac34dca 100644 --- a/setup/upgrade/steps/upgradeDatabase.php +++ b/setup/upgrade/steps/upgradeDatabase.php @@ -42,6 +42,7 @@ define('KT_DIR', SYSTEM_DIR); define('KT_LIB_DIR', SYSTEM_DIR.'lib'); +require_once(WIZARD_LIB . 'upgrade.inc.php'); class upgradeDatabase extends Step { @@ -94,8 +95,8 @@ class upgradeDatabase extends Step protected $silent = false; protected $temp_variables = array(); public $paths = ''; - - /** + + /** * Main control of database setup * * @author KnowledgeTree Team @@ -141,16 +142,8 @@ class upgradeDatabase extends Step } private function doRun($action = null) { -// $this->readConfig(KTConfig::getConfigFilename()); - $this->readConfig(); -// if($this->dbSettings['dbPort'] == '') { -// $con = $this->util->dbUtilities->load($this->dbSettings['dbHost'], '', $this->dbSettings['dbUser'],$this->dbSettings['dbPass'], $this->dbSettings['dbName']); -// } else { - $con = $this->util->dbUtilities->load($this->dbSettings['dbHost'], $this->dbSettings['dbPort'], $this->dbSettings['dbUser'], - $this->dbSettings['dbPass'], $this->dbSettings['dbName']); -// } - + $con = $this->util->dbUtilities->load($this->dbSettings['dbHost'], $this->dbSettings['dbPort'], $this->dbSettings['dbUser'],$this->dbSettings['dbPass'], $this->dbSettings['dbName']); $this->temp_variables['action'] = $action; if (is_null($action) || ($action == 'preview')) { $this->temp_variables['title'] = 'Preview Upgrade'; @@ -256,21 +249,30 @@ class upgradeDatabase extends Step require_once("../wizard/steps/configuration.php"); // configuration to read the ini path $wizConfigHandler = new configuration(); $path = $wizConfigHandler->readConfigPathIni(); - $this->util->iniUtilities->load($path); - $dbSettings = $this->util->iniUtilities->getSection('db'); - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], + $this->util->iniUtilities->load($path); + $dbSettings = $this->util->iniUtilities->getSection('db'); + $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], 'dbName'=> $dbSettings['dbName'], 'dbUser'=> $dbSettings['dbUser'], 'dbPass'=> $dbSettings['dbPass'], 'dbPort'=> $dbSettings['dbPort'], 'dbAdminUser'=> $dbSettings['dbAdminUser'], 'dbAdminPass'=> $dbSettings['dbAdminPass'], - ); - $this->paths = $this->util->iniUtilities->getSection('urls'); - $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); - $this->temp_variables['dbSettings'] = $this->dbSettings; - $this->sysVersion = $this->readVersion(); - $this->cachePath = $wizConfigHandler->readCachePath(); + ); + $this->paths = $this->util->iniUtilities->getSection('urls'); + $this->paths = array_merge($this->paths, $this->util->iniUtilities->getSection('cache')); + $this->sysVersion = $this->readVersion(); + $this->cachePath = $wizConfigHandler->readCachePath(); + $this->proxyPath = $this->cachePath."/.."; // Total guess. + $this->proxyPath = realpath($this->proxyPath."/proxies"); + $this->storeSilent(); + } + + public function storeSilent() { + $this->temp_variables['paths'] = $this->paths; + $this->temp_variables['sysVersion'] = $this->sysVersion; + $this->temp_variables['sysVersion'] = $this->sysVersion; + $this->temp_variables['dbSettings'] = $this->dbSettings; } private function upgradeConfirm() @@ -285,8 +287,6 @@ class upgradeDatabase extends Step private function doDatabaseUpgrade() { -// global $default; - $errors = false; $this->temp_variables['detail'] = '
The table below describes the upgrades that have occurred to
@@ -294,18 +294,10 @@ class upgradeDatabase extends Step
$pre_res = $this->performPreUpgradeActions();
- if (PEAR::isError($pre_res)) {
- $errors = true;
- $this->temp_variables['preUpgrade'] = 'Pre-Upgrade actions failed.';
- }
- else {
- $this->temp_variables['preUpgrade'] = 'Pre-Upgrade actions succeeded.';
-
- }
-
$res = $this->performAllUpgrades();
- if (PEAR::isError($res) || PEAR::isError($pres)) {
+ if (!$res) {
$errors = true;
+ $this->error[] = 'An Error has occured';
// TODO instantiate error details hideable section?
$this->temp_variables['upgradeStatus'] = 'Database upgrade failed
@@ -319,13 +311,7 @@ class upgradeDatabase extends Step
}
$post_pres = $this->performPostUpgradeActions();
- if (PEAR::isError($post_res)) {
- $errors = true;
- $this->temp_variables['postUpgrade'] = 'Post-Upgrade actions failed.';
- }
- else {
- $this->temp_variables['postUpgrade'] = 'Post-Upgrade actions succeeded.';
- }
+
return !$errors;
}
@@ -334,40 +320,63 @@ class upgradeDatabase extends Step
// This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
// It should idealy work the same as the upgrades.
-
-// global $default;
-// print_r($this->paths);die;
// Lock the scheduler
- $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
- touch($lockFile);
+ $lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock';
+ @touch($lockFile);
return true;
}
+ private function deleteDirectory($sPath) {
+ if (!WINDOWS_OS) {
+ if (file_exists('/bin/rm')) {
+ $this->util->pexec(array('/bin/rm', '-rf', $sPath));
+ return;
+ }
+ }
+ if (WINDOWS_OS) {
+ // Potentially kills off all the files in the path, speeding
+ // things up a bit
+ exec("del /q /s " . escapeshellarg($sPath));
+ }
+ $hPath = @opendir($sPath);
+ while (($sFilename = readdir($hPath)) !== false) {
+ if (in_array($sFilename, array('.', '..'))) {
+ continue;
+ }
+ $sFullFilename = sprintf("%s/%s", $sPath, $sFilename);
+ if (is_dir($sFullFilename)) {
+ $this->deleteDirectory($sFullFilename);
+ continue;
+ }
+ @chmod($sFullFilename, 0666);
+ @unlink($sFullFilename);
+ }
+ closedir($hPath);
+ @rmdir($sPath);
+ }
+
private function performPostUpgradeActions() {
// This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
// It should idealy work the same as the upgrades.
-// global $default;
-
// Ensure all plugins are re-registered.
$sql = "TRUNCATE plugin_helper";
- $res = DBUtil::runQuery($sql);
-
+ //$res = DBUtil::runQuery($sql);
+ $res = $this->util->dbUtilities->query($sql);
+
// Clear out all caches and proxies - they need to be regenerated with the new code
- $proxyDir = $default->proxyCacheDirectory;
- KTUtil::deleteDirectory($proxyDir);
-
- $oKTCache = new KTCache();
- $oKTCache->deleteAllCaches();
-
+ $this->deleteDirectory($this->proxyPath);
+// $oKTCache = new KTCache();
+// $oKTCache->deleteAllCaches();
+ $this->deleteDirectory($this->cachePath);
// Clear the configuration cache, it'll regenerate on next load
- $oKTConfig = new KTConfig();
- $oKTConfig->clearCache();
+// $oKTConfig = new KTConfig();
+// $oKTConfig->clearCache();
// Unlock the scheduler
- $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
+ $lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock';
if(file_exists($lockFile)){
@unlink($lockFile);
}
@@ -377,18 +386,15 @@ class upgradeDatabase extends Step
}
private function performAllUpgrades () {
-// global $default;
-
$row = 1;
-
- $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table);
- $lastVersion = DBUtil::getOneResultKey($query, 'value');
- $currentVersion = $default->systemVersion;
-
+ $table = 'system_settings';
+ $query = "SELECT value FROM $table WHERE name = 'databaseVersion'";
+ $result = $this->util->dbUtilities->query($query);
+ $assArr = $this->util->dbUtilities->fetchAssoc($result);
+ $lastVersion = $assArr[0]['value'];
+ $currentVersion = $this->sysVersion;
$upgrades = describeUpgrade($lastVersion, $currentVersion);
-
$this->temp_variables['upgradeTable'] = '';
-
foreach ($upgrades as $upgrade) {
if (($row % 2) == 1) {
$class = "odd";
@@ -402,15 +408,17 @@ class upgradeDatabase extends Step
$this->temp_variables['upgradeTable'] .= sprintf('
We would greatly appreciate it if you would allow us to collect anonymous usage statistics to help us provide a better quality product. The information includes a unique identification number, number of users you have created, your operating system type and your IP address. Your privacy is protected by the KnowledgeTree Privacy and Data Protection Agreements.
-- KnowledgeTree, in partnership with Food & Trees for Africa, and as a contributor to the National Tree Distribution Program, will also commit to planting one tree in Africa for every 1000 vertified installations of the product. -
-Help to improve KnowledgeTree by providing anonymous usage statistics