diff --git a/lib/dispatcher.inc.php b/lib/dispatcher.inc.php index 788ae24..9b695da 100644 --- a/lib/dispatcher.inc.php +++ b/lib/dispatcher.inc.php @@ -343,8 +343,8 @@ class KTStandardDispatcher extends KTDispatcher { } function loginRequired() { - $oKTConfig =& KTConfig::getSingleton(); - if ($oKTConfig->get('allowAnonymousLogin', false)) { + $oKTConfig =& KTConfig::getSingleton(); + if ($oKTConfig->get('allowAnonymousLogin', false)) { // anonymous logins are now allowed. // the anonymous user is -1. // @@ -352,9 +352,9 @@ class KTStandardDispatcher extends KTDispatcher { $oUser =& User::get(-2); if (PEAR::isError($oUser) || ($oUser->getName() != 'Anonymous')) { - ; // do nothing - the database integrity would break if we log the user in now. + ; // do nothing - the database integrity would break if we log the user in now. } else { - $session = new Session(); + $session = new Session(); $sessionID = $session->create($oUser); $this->sessionStatus = $this->session->verify(); if ($this->sessionStatus === true) { diff --git a/lib/session/Session.inc b/lib/session/Session.inc index 0d4aeb5..f1d4758 100644 --- a/lib/session/Session.inc +++ b/lib/session/Session.inc @@ -228,7 +228,7 @@ class Session { // Compare the system version and the database version to determine if the database needs to be upgraded. $version = KTUtil::getSystemSetting('databaseVersion'); - if ($default->systemVersion != $version) { + if (trim($default->systemVersion) != trim($version)) { if (KTLOG_CACHE) $default->log->info("Session::verify : Database not upgraded"); $_SESSION['errormessage']['login'] = sprintf(_kt('Database incompatibility error:
Please ensure that you have completed the database upgrade procedure.
Please click here to complete.'),'setup/upgrade.php'); return PEAR::raiseError($_SESSION['errormessage']['login']); 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('%s (%s)', $name, $path); diff --git a/setup/precheckup.php b/setup/precheckup.php index 216cf53..d8e5de4 100644 --- a/setup/precheckup.php +++ b/setup/precheckup.php @@ -38,7 +38,7 @@ error_reporting(E_ALL); -require_once('../config/dmsDefaults.php'); +//require_once('../config/dmsDefaults.php'); function get_php_setting($val) { $r = (ini_get($val) == '1' ? 1 : 0); diff --git a/setup/upgrade/lib/UpgradeItems.inc.php b/setup/upgrade/lib/UpgradeItems.inc.php index 36b1aca..4ed2cd5 100644 --- a/setup/upgrade/lib/UpgradeItems.inc.php +++ b/setup/upgrade/lib/UpgradeItems.inc.php @@ -117,7 +117,7 @@ class UpgradeItem extends InstallUtil { return $this->type; } - function runDBQuery($query) { + function runDBQuery($query, $checkResult = false, $typeCheck = false) { require_once("../wizard/steps/configuration.php"); // configuration to read the ini path $wizConfigHandler = new configuration(); $configPath = $wizConfigHandler->readConfigPathIni(); @@ -128,13 +128,36 @@ class UpgradeItem extends InstallUtil { $dconf = $this->iniUtilities->getSection('db'); $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); $result = $this->dbUtilities->query($query); - $assArr = $this->dbUtilities->fetchAssoc($result); - return $assArr; +// echo "$query
"; +// echo '
';
+//        print_r($result);
+//        echo '
'; + if($checkResult) { + $assArr = $this->dbUtilities->fetchAssoc($result); +// echo '
';
+//	        print_r($assArr);
+//	        echo '
'; +// if(is_null($assArr)) { +// echo '=== null ===
'; +// return false; +// } else { +// echo '=== not null ===
'; +// } + if($typeCheck) { + return !is_null($assArr); + } else { + return is_null($assArr); + } + } +// echo '
';
+//        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 @@ -249,7 +269,7 @@ class SQLUpgradeItem extends UpgradeItem { * * STATIC */ - function getUpgrades($origVersion, $currVersion) { + public static function getUpgrades($origVersion, $currVersion) { // global $default; // $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/'; @@ -323,7 +343,7 @@ class SQLUpgradeItem extends UpgradeItem { return $ret; } - function _getDetailsFromFileName($path) { + public static function _getDetailsFromFileName($path) { // Old format (pre 2.0.6) $matched = preg_match('#^([\d.]*)-to-([\d.]*).sql$#', $path, $matches); if ($matched != 0) { @@ -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/lib/upgrade.inc.php b/setup/upgrade/lib/upgrade.inc.php index f083351..c3dcd18 100644 --- a/setup/upgrade/lib/upgrade.inc.php +++ b/setup/upgrade/lib/upgrade.inc.php @@ -92,25 +92,24 @@ function &describeUpgrade ($origVersion, $currVersion) { // How to figure out what upgrades to do: // // 1. Get all SQL upgrades >= origVersion and <= currVersion - // 2. Get all Function upgrades >= origVersion and <= currVersion - // 3. Categorise each into version they upgrade to - // 4. Sort each version subgroup into correct order + // 2. Categorise each into version they upgrade to + // 3. Sort each version subgroup into correct order // 5. Add "recordSubUpgrade" for each version there. - // 6. Add back into one big list again - // 7. Add "recordUpgrade" for whole thing + // 5. Add back into one big list again + // 6. Add "recordUpgrade" for whole thing // $recordUpgrade = array('upgrade*' . $currVersion, 'Upgrade to ' . $currVersion, null); $steps = array(); foreach (array('SQLUpgradeItem') as $itemgen) { $f = array($itemgen, 'getUpgrades'); - $ssteps =& call_user_func($f, $origVersion, $currVersion); + $ssteps = call_user_func($f, $origVersion, $currVersion); $scount = count($ssteps); for ($i = 0; $i < $scount; $i++) { $steps[] =& $ssteps[$i]; } } - $upgradestep =& new RecordUpgradeItem($currVersion, $origVersion); + $upgradestep = new RecordUpgradeItem($currVersion, $origVersion); $steps[] =& $upgradestep; $stepcount = count($steps); for ($i = 0; $i < $stepcount; $i++) { 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..ef5d3fd 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'; @@ -176,15 +169,16 @@ class upgradeDatabase extends Step $this->sysVersion = $this->readVersion(); $this->temp_variables['systemVersion'] = $this->sysVersion; $dconf = $this->util->iniUtilities->getSection('db'); - $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', 'system_settings'); $this->util->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); + + $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', 'system_settings'); $result = $this->util->dbUtilities->query($query); $assArr = $this->util->dbUtilities->fetchAssoc($result); if ($result) { $lastVersion = $assArr[0]['value']; } $currentVersion = $this->sysVersion; - require_once("lib/upgrade.inc.php"); + $upgrades = describeUpgrade($lastVersion, $currentVersion); $ret = "\n"; $ret .= "\n"; @@ -256,21 +250,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 +288,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 +295,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 +312,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 +321,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 +387,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 +409,17 @@ class upgradeDatabase extends Step $this->temp_variables['upgradeTable'] .= sprintf('

%s
', $this->showResult($res)); $this->temp_variables['upgradeTable'] .= '
' . "\n"; $this->temp_variables['upgradeTable'] .= "\n"; - if (PEAR::isError($res)) { - if (!is_a($res, 'Upgrade_Already_Applied')) { - break; - } else { - $res = true; - } - } +// if (!$res) { +// if (!is_a($res, 'Upgrade_Already_Applied')) { +// $res = false; +// } else { +// $res = true; +// } +// } if ($res === false) { - $res = PEAR::raiseError("Upgrade returned false"); + die; + $this->error = $this->util->dbUtilities->getErrors(); +// print_r($this->error); break; } } @@ -419,11 +428,11 @@ class upgradeDatabase extends Step } private function showResult($res) { - if (PEAR::isError($res)) { + if ($res) { if (is_a($res, 'Upgrade_Already_Applied')) { return 'Already applied'; } - return sprintf('%s', htmlspecialchars($res->toString())); +// return sprintf('%s', htmlspecialchars($res)); } if ($res === true) { return 'Success'; @@ -433,6 +442,5 @@ class upgradeDatabase extends Step } return $res; } - } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeWelcome.php b/setup/upgrade/steps/upgradeWelcome.php index 3e4d056..1c232df 100644 --- a/setup/upgrade/steps/upgradeWelcome.php +++ b/setup/upgrade/steps/upgradeWelcome.php @@ -45,7 +45,8 @@ class upgradeWelcome extends step { protected $silent = true; protected $temp_variables = array(); protected $error = array() ; - + protected $storeInSession = true; + public function doStep() { $this->temp_variables = array("step_name"=>"welcome"); if($this->next()) { @@ -88,8 +89,6 @@ class upgradeWelcome extends step { $configPath = $wizConfigHandler->readConfigPathIni(); $this->util->iniUtilities->load($configPath); $dconf = $this->util->iniUtilities->getSection('db'); - if($dconf['dbPort'] == 'default') - $dconf['dbPort'] = 3306; $this->util->dbUtilities->load($dconf['dbHost'],$dconf['dbPort'], $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); $sQuery = "SELECT count(*) AS match_count FROM users WHERE username = '$username' AND password = '".md5($password)."'"; $res = $this->util->dbUtilities->query($sQuery); diff --git a/setup/upgrade/templates/complete.tpl b/setup/upgrade/templates/complete.tpl index d32a3ce..9b35d08 100644 --- a/setup/upgrade/templates/complete.tpl +++ b/setup/upgrade/templates/complete.tpl @@ -6,8 +6,8 @@

- Your database has been upgraded to systemVersion; ?> + Your database has been upgraded to
- Goto Login + Goto Login \ No newline at end of file diff --git a/setup/upgrade/templates/database.tpl b/setup/upgrade/templates/database.tpl index 46b3aec..4fb564b 100644 --- a/setup/upgrade/templates/database.tpl +++ b/setup/upgrade/templates/database.tpl @@ -3,6 +3,13 @@
This step performs the necessary Database Upgrades. + "; + foreach ($errors as $error) { + if($error != '') + echo "$error
"; + } + ?>


diff --git a/setup/upgrade/upgradeSession.php b/setup/upgrade/upgradeSession.php deleted file mode 100644 index 019fded..0000000 --- a/setup/upgrade/upgradeSession.php +++ /dev/null @@ -1,224 +0,0 @@ -. -* -* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, -* California 94120-7775, or email info@knowledgetree.com. -* -* The interactive user interfaces in modified source and object code versions -* of this program must display Appropriate Legal Notices, as required under -* Section 5 of the GNU General Public License version 3. -* -* In accordance with Section 7(b) of the GNU General Public License version 3, -* these Appropriate Legal Notices must retain the display of the "Powered by -* KnowledgeTree" logo and retain the original copyright notice. If the display of the -* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices -* must display the words "Powered by KnowledgeTree" and retain the original -* copyright notice. -* -* @copyright 2008-2009, KnowledgeTree Inc. -* @license GNU General Public License version 3 -* @author KnowledgeTree Team -* @package Upgrader -* @version Version 0.1 -*/ -class UpgradeSession -{ - private $salt = 'upgrade'; - /** - * Constructs session object - * - * @author KnowledgeTree Team - * @access public - * @param none - */ - public function __construct() { - $this->startSession(); - } - - /** - * Starts a session if one does not exist - * - * @author KnowledgeTree Team - * @param none - * @access public - * @return void - */ - public function startSession() { - if(!isset($_SESSION[$this->salt]['ready'])) { - session_start(); - $_SESSION[$this->salt] ['ready'] = TRUE; - } - } - - /** - * Sets a value key pair in session - * - * @author KnowledgeTree Team - * @param string $fld - * @param string $val - * @access public - * @return void - */ - public function set($fld, $val) { - $this->startSession(); - $_SESSION[$this->salt] [$fld] = $val; - } - - /** - * Sets a value key pair in a class in session - * - * @author KnowledgeTree Team - * @param string $class - * @param string $fld - * @param string $val - * @access public - * @return void - */ - public function setClass($class , $k, $v) { - $this->startSession(); - $classArray = $this->get($class); - if(isset($classArray[$k])) { - $classArray[$k] = $v; - } else { - $classArray[$k] = $v; - } - $_SESSION[$this->salt] [ $class] = $classArray; - } - - /** - * Sets a error value key pair in a class in session - * - * @author KnowledgeTree Team - * @param string $class - * @param string $fld - * @param string $val - * @access public - * @return void - */ - public function setClassError($class, $k, $v) { - $this->startSession(); - $classArray = $this->get($class); - if(isset($classArray[$k])) { - $classArray[$k] = $v; - } else { - $classArray[$k] = $v; - } - $_SESSION[$this->salt] [ $class] = $classArray; - } - - /** - * Clear error values in a class session - * - * @author KnowledgeTree Team - * @param string $class - * @param string $fld - * @param string $val - * @access public - * @return void - */ - public function clearErrors($class) { - $classArray = $this->get($class); - unset($classArray['errors']); - $_SESSION[$this->salt] [ $class] = $classArray; - } - - /** - * Unset a value in session - * - * @author KnowledgeTree Team - * @param string $fld - * @access public - * @return void - */ - public function un_set($fld) { - $this->startSession(); - unset($_SESSION[$this->salt] [$fld]); - } - - /** - * Unset a class value in session - * - * @author KnowledgeTree Team - * @param string $class - * @access public - * @return void - */ - public function un_setClass($class) { - $this->startSession(); - if(isset($_SESSION[$this->salt] [$class])) - unset($_SESSION[$this->salt] [$class]); - } - - /** - * Destroy the session - * - * @author KnowledgeTree Team - * @param none - * @access public - * @return void - */ - public function destroy() { - $this->startSession(); - unset($_SESSION[$this->salt]); - session_destroy(); - } - - /** - * Get a session value - * - * @author KnowledgeTree Team - * @param string $fld - * @access public - * @return string - */ - public function get($fld) { - $this->startSession(); - if(isset($_SESSION[$this->salt] [$fld])) - return $_SESSION[$this->salt] [$fld]; - return false; - } - - /** - * Check if a field exists in session - * - * @author KnowledgeTree Team - * @param string $fld - * @access public - * @return string - */ - public function is_set($fld) { - $this->startSession(); - return isset($_SESSION[$this->salt] [$fld]); - } - - /** - * Return a class from session - * - * @author KnowledgeTree Team - * @param string $fld - * @access public - * @return string - */ - public function getClass($class) { - return $_SESSION[$this->salt][$class]; - } -} -?> \ No newline at end of file diff --git a/setup/wizard/dbUtilities.php b/setup/wizard/dbUtilities.php index 6206fe6..39f6876 100644 --- a/setup/wizard/dbUtilities.php +++ b/setup/wizard/dbUtilities.php @@ -267,5 +267,15 @@ class dbUtilities { public function rollback() { $this->query("ROLLBACK"); } + + public function runQueries($aQueries) { + foreach ($aQueries as $sQuery) { + $res = $this->query($sQuery); + if (!$res) { + return $res; + } + } + return true; + } } ?> \ No newline at end of file diff --git a/setup/wizard/iniUtilities.php b/setup/wizard/iniUtilities.php index e47053a..366caf7 100644 --- a/setup/wizard/iniUtilities.php +++ b/setup/wizard/iniUtilities.php @@ -45,11 +45,11 @@ class iniUtilities { function load($iniFile) { - if($this->iniFile != $iniFile) { - $this->cleanArray = array(); - $this->lineNum = 0; - $this->exists = ''; - } +// if($this->iniFile != $iniFile) { +// $this->cleanArray = array(); +// $this->lineNum = 0; +// $this->exists = ''; +// } $this->iniFile = $iniFile; $this->backupIni($iniFile); $this->read($iniFile); diff --git a/setup/wizard/lib/services/unixLucene.php b/setup/wizard/lib/services/unixLucene.php index a87ca88..1520874 100644 --- a/setup/wizard/lib/services/unixLucene.php +++ b/setup/wizard/lib/services/unixLucene.php @@ -201,7 +201,7 @@ class unixLucene extends unixService { public function start() { $state = $this->status(); if($state != 'STARTED') { - $logFile = $this->outputDir."log".DS."lucene.log"; + $logFile = $this->outputDir.DS."lucene.log"; @unlink($logFile); $cmd = "cd ".$this->getLuceneDir()."; "; $cmd .= "nohup java {$this->getJavaXmx()} {$this->getJavaXmx()} -jar ".$this->getLuceneSource()." > ".$logFile." 2>&1 & echo $!"; diff --git a/setup/wizard/lib/services/unixScheduler.php b/setup/wizard/lib/services/unixScheduler.php index 6f8fada..9c5a4c0 100644 --- a/setup/wizard/lib/services/unixScheduler.php +++ b/setup/wizard/lib/services/unixScheduler.php @@ -180,7 +180,7 @@ class unixScheduler extends unixService { // TODO : Write sh on the fly? Not sure the reasoning here $source = $this->getSchedulerSourceLoc(); $this->writeSchedulerTask(); - $logFile = $this->outputDir."log".DS."scheduler.log"; + $logFile = $this->outputDir.DS."scheduler.log"; @unlink($logFile); if($source) { // Source $cmd = "nohup ".$source." > ".$logFile." 2>&1 & echo $!"; diff --git a/setup/wizard/resources/graphics/greenit.jpg b/setup/wizard/resources/graphics/greenit.jpg new file mode 100644 index 0000000..6498c37 --- /dev/null +++ b/setup/wizard/resources/graphics/greenit.jpg diff --git a/setup/wizard/steps/complete.php b/setup/wizard/steps/complete.php index 8df2aae..d32a648 100644 --- a/setup/wizard/steps/complete.php +++ b/setup/wizard/steps/complete.php @@ -96,6 +96,7 @@ class complete extends Step { foreach ($paths as $path) { $output = ''; + $path['path'] = $class = strtolower(substr($path['path'],0,1)).substr($path['path'],1); // Damn you windows $result = $this->util->checkPermission($path['path']); $output = sprintf($pathhtml, $result['class'], $path['path'], (($result['class'] == 'tick') ? 'class="green"' : 'class="error"' ), diff --git a/setup/wizard/steps/configuration.php b/setup/wizard/steps/configuration.php index 7024af7..bdfca7d 100644 --- a/setup/wizard/steps/configuration.php +++ b/setup/wizard/steps/configuration.php @@ -450,7 +450,7 @@ class configuration extends Step } $dirs = $this->getFromConfigPath(); // Store contents } - $varDirectory = $fileSystemRoot . DS . 'var'; + foreach ($dirs as $key => $dir){ $path = (isset($_POST[$dir['setting']])) ? $_POST[$dir['setting']] : $dir['path']; @@ -460,6 +460,7 @@ class configuration extends Step if(WINDOWS_OS) $path = preg_replace('/\//', '\\',$path); $dirs[$key]['path'] = $path; + $path = $class = strtolower(substr($path,0,1)).substr($path,1); // Damn you windows if(isset($dir['file'])) $class = $this->util->checkPermission($path, $dir['create'], true); else diff --git a/setup/wizard/steps/services.php b/setup/wizard/steps/services.php index 6f5d309..153796d 100644 --- a/setup/wizard/steps/services.php +++ b/setup/wizard/steps/services.php @@ -219,7 +219,7 @@ class services extends Step $srv = new $className(); $srv->load(); $status = $this->serviceInstalled($srv); - if($status != 'STARTED') { + if($status != 'STARTED' || $status != 'STOPPED') { if(!WINDOWS_OS) { $binary = $this->$class->getBinary(); } // Get binary, if it exists $passed = $this->$class->binaryChecks(); // Run Binary Pre Checks if ($passed) { // Install Service diff --git a/setup/wizard/templates/install.tpl b/setup/wizard/templates/install.tpl index 1e1a8f2..f25971f 100644 --- a/setup/wizard/templates/install.tpl +++ b/setup/wizard/templates/install.tpl @@ -5,10 +5,7 @@

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. -

-
image('img_fatlogo.jpg'); ?>
+
image('greenit.jpg'); ?>


   Help to improve KnowledgeTree by providing anonymous usage statistics

diff --git a/webservice/clienttools/ajaxhandler.php b/webservice/clienttools/ajaxhandler.php index cc2109a..4e3e9a5 100644 --- a/webservice/clienttools/ajaxhandler.php +++ b/webservice/clienttools/ajaxhandler.php @@ -8,6 +8,7 @@ class ajaxHandler{ public $kt=NULL; public $authenticator=NULL; public $noAuthRequireList=array(); + public $standardServices=array('system'); public function __construct(&$ret=NULL,&$kt,$noAuthRequests=''){ // set a local copy of the json request wrapper @@ -30,6 +31,7 @@ class ajaxHandler{ } $this->ret->setRequest($this->req->jsonArray); $this->ret->setTitle($this->request['service'].'::'.$this->request['function']); + $this->ret->setDebug('Server Versions',$this->getServerVersions()); if(get_class($kt)=='KTAPI'){ $this->kt=&$kt; @@ -38,20 +40,22 @@ class ajaxHandler{ return $this->render(); } - // Prepar - $this->loadService('auth'); - $this->authenticator=new auth($this->ret,$this->kt,$this->request,$this->auth); - - - //Make sure a token exists before continuing - if(!$this->verifyToken())return $this->render(); - - - if(!$this->verifySession()){ - $this->doLogin(); - $isAuthRequired=$this->isNoAuthRequiredRequest(); - $isAuthenticated=$this->isAuthenticated(); - if(!$isAuthRequired && !$isAuthenticated)return $this->render(); + // Prepare + if(!$this->isStandardService()){ + $this->loadService('auth'); + $this->authenticator=new auth($this,$this->ret,$this->kt,$this->request,$this->auth); + + + //Make sure a token exists before continuing + if(!$this->verifyToken())return $this->render(); + + + if(!$this->verifySession()){ + $this->doLogin(); + $isAuthRequired=$this->isNoAuthRequiredRequest(); + $isAuthenticated=$this->isAuthenticated(); + if(!$isAuthRequired && !$isAuthenticated)return $this->render(); + } } $this->dispatch(); @@ -70,11 +74,15 @@ class ajaxHandler{ $service=$this->authenticator; }else{ $this->loadService($request['service']); - $service=new $request['service']($this->ret,$this->kt,$this->request,$this->auth); + if(class_exists($request['service'])){ + $service=new $request['service']($this,$this->ret,$this->kt,$this->request,$this->auth); + }else{ + $this->ret->setDebug('Service could not be loaded',$request['service']); + } } $this->ret->setdebug('dispatch_request','The service class loaded'); if(method_exists($service,$request['function'])){ - $this->ret->setdebug('dispatch_execution','The service method was found. Executing'); + $this->ret->setDebug('dispatch_execution','The service method was found. Executing'); $service->$request['function']($request['parameters']); }else{ $this->ret->addError("Service {$request['service']} does not contain the method: {$request['function']}"); @@ -82,16 +90,34 @@ class ajaxHandler{ } } + public function isStandardService(){ + return in_array($this->request['service'],$this->standardServices); + } + public function loadService($serviceName=NULL){ - $version=$this->getVersion(); - if(!class_exists($serviceName)){ - if(file_exists('services/'.$version.'/'.$serviceName.'.php')){ - require_once('services/'.$version.'/'.$serviceName.'.php'); - return true; - }else{ - throw new Exception('Service could not be found: '.$serviceName); - return false; + if(in_array($serviceName,$this->standardServices)){ + $fileName=dirname(__FILE__).'/standardservices/'.$serviceName.'.php'; + $this->ret->setDebug('standardService Found',$fileName); + if(!class_exists($serviceName)){ + if(file_exists($fileName)){ + require_once($fileName); + return true; + }else{ + throw new Exception('Standard Service could not be found: '.$serviceName); + return false; + } + } + }else{ + $version=$this->getVersion(); + if(!class_exists($serviceName)){ + if(file_exists('services/'.$version.'/'.$serviceName.'.php')){ + require_once('services/'.$version.'/'.$serviceName.'.php'); + return true; + }else{ + throw new Exception('Service could not be found: '.$serviceName); + return false; + } } } } @@ -106,10 +132,22 @@ class ajaxHandler{ return true; } - protected function getVersion(){ + public function getVersion(){ if(!$this->version)$this->version=$this->req->getVersion(); return $this->version; } + + public function getServerVersions(){ + $folder='services/'; + $contents=scandir($folder); + $dir=array(); + foreach($contents as $item){ + if(is_dir($folder.$item) && $item!='.' && $item!=='..'){ + $dir[]=$item; + } + } + return $dir; + } protected function verifySession(){ return $this->authenticator->pickup_session(); diff --git a/webservice/clienttools/client_service.php b/webservice/clienttools/client_service.php index 971fc30..078dd5a 100644 --- a/webservice/clienttools/client_service.php +++ b/webservice/clienttools/client_service.php @@ -5,8 +5,9 @@ class client_service{ public $KT; public $Request; public $AuthInfo; + public $handler; - public function __construct(&$ResponseObject,&$KT_Instance,&$Request,&$AuthInfo){ + public function __construct(&$handler,&$ResponseObject,&$KT_Instance,&$Request,&$AuthInfo){ // set the response object // if(get_class($ResponseObject)=='jsonResponseObject'){ // $this->Response=&$ResponseObject; @@ -14,7 +15,7 @@ class client_service{ // $this->Response=new jsonResponseObject(); // } - + $this->handler=$handler; $this->Response=&$ResponseObject; $this->KT=&$KT_Instance; $this->AuthInfo=&$AuthInfo; diff --git a/webservice/clienttools/jsonWrapper.php b/webservice/clienttools/jsonWrapper.php index df4e092..c025f35 100644 --- a/webservice/clienttools/jsonWrapper.php +++ b/webservice/clienttools/jsonWrapper.php @@ -14,7 +14,7 @@ class jsonResponseObject{ public $additional=array(); public $isDataSource=false; - public $includeDebug=false; + public $includeDebug=true; public $response=array( 'requestName' =>'', diff --git a/webservice/clienttools/services/0.1/auth.php b/webservice/clienttools/services/0.1/auth.php index 67a62e7..e7cdc65 100644 --- a/webservice/clienttools/services/0.1/auth.php +++ b/webservice/clienttools/services/0.1/auth.php @@ -100,17 +100,25 @@ class auth extends client_service { public function ping(){ global $default; $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']); + $versions=$this->handler->getServerVersions(); + $bestVer=$versions[count($versions)-1]; + $clientVer=$this->handler->getVersion(); $ret=array( 'response' =>'pong', 'loginLocation' => '/index.html', - 'currentversion' =>$default->systemVersion, - 'requiredversion' =>$default->systemVersion, - 'versionok' =>true, - 'fullName' =>PEAR::isError($user)?'':$user->getName() + 'versionok' =>in_array($clientVer,$versions), + 'fullName' =>PEAR::isError($user)?'':$user->getName(), + 'serverVersions' =>$versions, + 'serverBestVersion' =>$bestVer, + 'clientVersion' =>$clientVer, + 'canUpgradeClient' =>($clientVer<$bestVer?true:false), + 'canUpgradeServer' =>($clientVer>$bestVer?true:false) + ); $this->setResponse($ret); return true; } + function logout($params){ $params=$this->AuthInfo; diff --git a/webservice/clienttools/services/0.2/auth.php b/webservice/clienttools/services/0.2/auth.php index 67a62e7..5d7275f 100644 --- a/webservice/clienttools/services/0.2/auth.php +++ b/webservice/clienttools/services/0.2/auth.php @@ -100,13 +100,20 @@ class auth extends client_service { public function ping(){ global $default; $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']); + $versions=$this->handler->getServerVersions(); + $bestVer=$versions[count($versions)-1]; + $clientVer=$this->handler->getVersion(); $ret=array( 'response' =>'pong', 'loginLocation' => '/index.html', - 'currentversion' =>$default->systemVersion, - 'requiredversion' =>$default->systemVersion, - 'versionok' =>true, - 'fullName' =>PEAR::isError($user)?'':$user->getName() + 'versionok' =>in_array($clientVer,$versions), + 'fullName' =>PEAR::isError($user)?'':$user->getName(), + 'serverVersions' =>$versions, + 'serverBestVersion' =>$bestVer, + 'clientVersion' =>$clientVer, + 'canUpgradeClient' =>($clientVer<$bestVer?true:false), + 'canUpgradeServer' =>($clientVer>$bestVer?true:false) + ); $this->setResponse($ret); return true; diff --git a/webservice/clienttools/services/0.2/kt.php b/webservice/clienttools/services/0.2/kt.php index f267f1b..da76840 100644 --- a/webservice/clienttools/services/0.2/kt.php +++ b/webservice/clienttools/services/0.2/kt.php @@ -140,6 +140,7 @@ class kt extends client_service { $folder=&$kt->get_folder_by_id($arr['node']); if (PEAR::isError($folder)){ + echo '
'.print_r($arr,true).'
'; $this->addError('Folder Not found'); return false; } @@ -430,6 +431,7 @@ class kt extends client_service { } } $this->setResponse(array('items'=>$items, 'count'=>count($items))); + return true; } function update_document_type($params) { @@ -599,9 +601,10 @@ class kt extends client_service { $filename=$params['filename']; $reason=$params['reason']; $tempfilename=$params['tempfilename']; + $major_update=$params['major_update']; $application=$this->AuthInfo['appType']; - $this->addDebug('Checkin',"checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application')"); + $this->addDebug('Checkin',"checkin_document('$session_id',$document_id,'$filename','$reason','$tempfilename', '$application', $major_update)"); $kt=&$this->KT; // we need to add some security to ensure that people don't frig the checkin process to access restricted files. @@ -620,7 +623,7 @@ class kt extends client_service { } // checkin - $result=$document->checkin($filename, $reason, $tempfilename, false); + $result=$document->checkin($filename, $reason, $tempfilename, $major_update); if (PEAR::isError($result)) { $this->setResponse(array('status_code'=>14)); @@ -676,7 +679,7 @@ class kt extends client_service { $status_code=$update_result['status_code']; if ($status_code != 0) { - $this->delete_document($arr['session_id'], $document_id, 'Rollback because metadata could not be added', $arr['application']); + $this->delete_document(array('session_id' => $arr['session_id'], 'document_id' => $document_id, 'reason' => 'Rollback because metadata could not be added', 'application' => $arr['application'])); $this->response= $update_result; } @@ -824,7 +827,12 @@ class kt extends client_service { $this->setResponse($detail); } - function delete_document($session_id, $document_id, $reason, $application){ + function delete_document($params){ + $session_id = $params['session_id']; + $document_id = $params['document_id']; + $reason = $params['reason']; + $application = $params['application']; + $kt=&$this->KT; $document=&$kt->get_document_by_id($document_id); diff --git a/webservice/clienttools/standardservices/system.php b/webservice/clienttools/standardservices/system.php new file mode 100644 index 0000000..17b4a01 --- /dev/null +++ b/webservice/clienttools/standardservices/system.php @@ -0,0 +1,26 @@ +KT->get_user_object_by_username($this->AuthInfo['user']); + $versions=$this->handler->getServerVersions(); + $bestVer=$versions[count($versions)-1]; + $clientVer=$this->handler->getVersion(); + $ret=array( + 'response' =>'pong', + 'loginLocation' => '/index.html', + 'versionok' =>in_array($clientVer,$versions), + 'fullName' =>PEAR::isError($user)?'':$user->getName(), + 'serverVersions' =>$versions, + 'serverBestVersion' =>$bestVer, + 'clientVersion' =>$clientVer, + 'canUpgradeClient' =>($clientVer<$bestVer?true:false), + 'canUpgradeServer' =>($clientVer>$bestVer?true:false) + + ); + $this->setResponse($ret); + return true; + } +} + +?> \ No newline at end of file
CodeDescriptionApplied