diff --git a/.gitignore b/.gitignore index 661da2b..9027b17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *~ bin/luceneserver/lucene.pid +bin/schedulerTask.sh *.tmproj .DS_Store .buildpath diff --git a/bin/system_info.php b/bin/system_info.php index 8c3ae59..c61ed8d 100644 --- a/bin/system_info.php +++ b/bin/system_info.php @@ -43,7 +43,12 @@ * The following data is collected: * Unique installation information: installation GUID, number of users in repository, number of documents in repository, * operating system (platform, platform version, flavor if Linux), version and edition. + +|||| +||| +||| */ + chdir(realpath(dirname(__FILE__))); require_once('../config/dmsDefaults.php'); @@ -56,7 +61,7 @@ function getGuid() $guid = KTUtil::getSystemIdentifier(); if(PEAR::isError($guid)){ - $guid = ''; + $guid = '-'; } return $guid; } @@ -68,42 +73,43 @@ function getUserCnt() $result = DBUtil::getResultArray($query); if(empty($result) || PEAR::isError($result)){ - return ''; + return '-|-|-'; } - $users = ''; + $enabled = '-'; + $disabled = '-'; + $deleted = '-'; foreach ($result as $row){ - $str = ''; switch($row['disabled']){ - case 0: $str = 'Enabled'; break; - case 1: $str = 'Disabled'; break; - case 2: $str = 'Deleted'; break; + case 0: $enabled = $row['cnt']; break; + case 1: $disabled = $row['cnt']; break; + case 2: $deleted = $row['cnt']; break; } - - $str .= ': '.$row['cnt']; - - $users .= (!empty($users)) ? '; ' : ''; - $users .= $str; } - return $users; + return "{$enabled}|{$disabled}|{$deleted}"; } // Get the number of documents in the repository function getDocCnt() { - $query = 'select count(*) as cnt, s.name from documents d, status_lookup s WHERE s.id = d.status_id group by d.status_id;'; + $query = 'select count(*) as cnt, status_id from documents d WHERE status_id IN (1,3,4) group by d.status_id;'; $result2 = DBUtil::getResultArray($query); if(empty($result2) || PEAR::isError($result2)){ - return ''; + return '-|-|-'; } - $docs = ''; + $live = '-'; + $deleted = '-'; + $archived = '-'; foreach ($result2 as $row){ - $docs .= (!empty($docs)) ? '; ' : ''; - $docs .= $row['name'].': '.$row['cnt']; + switch($row['status_id']){ + case 1: $live = $row['cnt']; break; + case 3: $deleted = $row['cnt']; break; + case 4: $archived = $row['cnt']; break; + } } - return $docs; + return "{$live}|{$deleted}|{$archived}"; } // Get the version of KT @@ -121,15 +127,21 @@ function getKTVersion() // Get the edition of KT function getKTEdition() { - $edition = 'Community'; + $edition = 'Community|-'; if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { $path = KTPluginUtil::getPluginPath('ktdms.wintools'); require_once($path . 'baobabkeyutil.inc.php'); $edition = BaobabKeyUtil::getName(); + // this could be done with regular expressions... // Remove the brackets around the name $edition = substr($edition, 1); $edition = substr($edition, 0, strlen($edition)-1); + // Remove the "users" + $pos = strpos($edition, 'users'); + $edition = ($pos === false) ? $edition.'|-' : substr($edition, 0, $pos-1); + // Replace the , with | + $edition = str_replace(', ', '|', $edition); } return $edition; } @@ -139,22 +151,33 @@ function getKTEdition() function getOSInfo() { $server = php_uname(); + $server_arr = explode(' ', $server); + + // kernel version and os type - 32bit / 64bit + $kernel_v = $server_arr[2]; + $os_v = array_pop($server_arr); if(strpos($server, 'Darwin') !== false){ $os = 'Mac OS X'; }else if(strpos($server, 'Win') !== false){ $os = 'Windows'; - }else { + // windows differs from *nix + // kernel version = windows version + // os version = build number + $kernel_v = $server_arr[3]; + $os_v = array_pop($server_arr); + }else if(strpos($server, 'Linux') !== false) { $os = 'Linux'; + }else { + $os = 'Unix'; } - return $os; + return $os.'|'.$kernel_v.'|'.$os_v; } function sendForm($data) { $url = 'http://ktnetwork.knowledgetree.com/call_home.php'; - //$url = 'http://10.33.20.250/knowledgetree/call_home.php'; $data = http_build_query($data); $ch = curl_init($url); diff --git a/clienttools/.gitignore b/clienttools/.gitignore deleted file mode 100644 index 0bde6cd..0000000 --- a/clienttools/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -*~ -bin/luceneserver/lucene.pid -*.tmproj -.DS_Store -.buildpath -.project -.settings/ -dummy.php -var/* -plugins/commercial diff --git a/ktwebservice/KTDownloadManager.inc.php b/ktwebservice/KTDownloadManager.inc.php index 9efc4e5..cbe0075 100644 --- a/ktwebservice/KTDownloadManager.inc.php +++ b/ktwebservice/KTDownloadManager.inc.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * Portions copyright The Jam Warehouse Software (Pty) Limited + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the diff --git a/ktwebservice/KTUploadManager.inc.php b/ktwebservice/KTUploadManager.inc.php index be50f93..eb1b7cd 100644 --- a/ktwebservice/KTUploadManager.inc.php +++ b/ktwebservice/KTUploadManager.inc.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * Portions copyright The Jam Warehouse Software (Pty) Limited + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the diff --git a/ktwebservice/KTWebService.php b/ktwebservice/KTWebService.php index d65a19a..a6936de 100644 --- a/ktwebservice/KTWebService.php +++ b/ktwebservice/KTWebService.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * Portions copyright The Jam Warehouse Software (Pty) Limited + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -671,4 +671,4 @@ $ws->handle(); exit(); -?> \ No newline at end of file +?> diff --git a/ktwebservice/checkup.php b/ktwebservice/checkup.php index ac9fd62..fa78c3a 100644 --- a/ktwebservice/checkup.php +++ b/ktwebservice/checkup.php @@ -32,4 +32,4 @@ $uploadsWritable = !is_writable($uploadsDir)?'The upload directory is not writab Upload Directory Writable - \ No newline at end of file + diff --git a/ktwebservice/download.php b/ktwebservice/download.php index f3170c4..1a4a468 100644 --- a/ktwebservice/download.php +++ b/ktwebservice/download.php @@ -7,7 +7,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * Portions copyright The Jam Warehouse Software (Pty) Limited + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -81,4 +81,4 @@ if (PEAR::isError($response)) exit; } -?> \ No newline at end of file +?> diff --git a/ktwebservice/download_cleanup.php b/ktwebservice/download_cleanup.php index 783a3ae..5162c90 100644 --- a/ktwebservice/download_cleanup.php +++ b/ktwebservice/download_cleanup.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * Portions copyright The Jam Warehouse Software (Pty) Limited + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the diff --git a/ktwebservice/index.php b/ktwebservice/index.php index f6836cf..f295520 100644 --- a/ktwebservice/index.php +++ b/ktwebservice/index.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * Portions copyright The Jam Warehouse Software (Pty) Limited + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the diff --git a/ktwebservice/json.php b/ktwebservice/json.php index c288131..51b6f64 100644 --- a/ktwebservice/json.php +++ b/ktwebservice/json.php @@ -3,4 +3,4 @@ define('JSON_WEBSERVICE',1); require_once('webservice.php'); -?> \ No newline at end of file +?> diff --git a/ktwebservice/upload.php b/ktwebservice/upload.php index 35f96aa..94430da 100644 --- a/ktwebservice/upload.php +++ b/ktwebservice/upload.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * Portions copyright The Jam Warehouse Software (Pty) Limited + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -207,4 +207,4 @@ function respond($code, $msg, $uploads=array()) } -?> \ No newline at end of file +?> 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/metadata/fieldsetregistry.inc.php b/lib/metadata/fieldsetregistry.inc.php index ab78767..5fab0a0 100755 --- a/lib/metadata/fieldsetregistry.inc.php +++ b/lib/metadata/fieldsetregistry.inc.php @@ -139,26 +139,26 @@ class KTFieldsetRegistry { // FIXME delegate. $oFieldset =& $fieldsetOrType; - $widgets = array(); - $fields = $oFieldset->getFields(); + $widgets = array(); + $fields = $oFieldset->getFields(); - if ($oFieldset->getIsConditional()) { - $iMasterId = $oFieldset->getMasterFieldId(); + if ($oFieldset->getIsConditional()) { + $iMasterId = $oFieldset->getMasterFieldId(); - $oMasterField = DocumentField::get($iMasterId); + $oMasterField = DocumentField::get($iMasterId); - $newfields = array(); - $newfields[] = $oMasterField; - foreach($fields as $oField) { - if($oField->getId() != $iMasterId) { - $newfields[] = $oField; - } - } + $newfields = array(); + $newfields[] = $oMasterField; + foreach($fields as $oField) { + if($oField->getId() != $iMasterId) { + $newfields[] = $oField; + } + } foreach ($newfields as $oField) { $fname = 'metadata_' . $oField->getId(); $value = null; - + if (!is_null($oDocument)) { $oFL = DocumentFieldLink::getByDocumentAndField($oDocument, $oField); if (!is_null($oFL) && (!PEAR::isError($oFL))) { @@ -166,7 +166,7 @@ class KTFieldsetRegistry { } } - $widgets[] = $this->oWF->get('ktcore.widgets.conditionalselection', + $widgets[] = $this->oWF->get('ktcore.widgets.conditionalselection', array( 'label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 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/lib/widgets/forms.inc.php b/lib/widgets/forms.inc.php index af06652..7b6ce91 100644 --- a/lib/widgets/forms.inc.php +++ b/lib/widgets/forms.inc.php @@ -328,7 +328,7 @@ class KTForm { $aOldData = array(); $aErrors = array(); $old_data = KTUtil::arrayGet((array) $_SESSION['_kt_old_data'], - $this->_kt_form_name, array()); + $this->_kt_form_name, array()); if (KTUtil::arrayGet($old_data, 'identifier') == $this->sIdentifier) { $bUseOld = true; $aStoredData = (array) unserialize(KTUtil::arrayGet($old_data, 'data')); diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/getTypeMetadataFields.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/getTypeMetadataFields.php index fc679e3..595a023 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/getTypeMetadataFields.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/getTypeMetadataFields.php @@ -44,6 +44,7 @@ require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); require_once(KT_LIB_DIR . '/widgets/fieldsetDisplay.inc.php'); require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php"); +require_once(KT_LIB_DIR . "/widgets/forms.inc.php"); require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php"); require_once(KT_LIB_DIR . "/widgets/widgetfactory.inc.php"); 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..561401c 100644 --- a/setup/upgrade/lib/UpgradeItems.inc.php +++ b/setup/upgrade/lib/UpgradeItems.inc.php @@ -49,19 +49,24 @@ */ // }}} -//require_once(KT_LIB_DIR . '/upgrades/UpgradeFunctions.inc.php'); require_once('sqlfile.inc.php'); -require_once('datetime.inc'); +require_once('datetime.inc.php'); + +require_once("../wizard/iniUtilities.php"); +require_once("../wizard/dbUtilities.php"); // {{{ Upgrade_Already_Applied -class Upgrade_Already_Applied { //extends PEAR_Error { +class Upgrade_Already_Applied { + function Upgrade_Already_Applied($oUpgradeItem) { $this->oUpgradeItem = $oUpgradeItem; } + } // }}} -class UpgradeItem extends InstallUtil { +class UpgradeItem { + var $type = ""; var $name; var $version; @@ -81,9 +86,9 @@ class UpgradeItem extends InstallUtil { $this->description = $description; $this->phase = $phase; $this->priority = $priority; - parent::__construct(); -// print_r($this); -// die; + + $this->dbUtilities = new dbUtilities(); + $this->iniUtilities = new iniUtilities(); } function setParent($parent) { @@ -117,24 +122,41 @@ class UpgradeItem extends InstallUtil { return $this->type; } - function runDBQuery($query) { - require_once("../wizard/steps/configuration.php"); // configuration to read the ini path + /** + * Runs a DB query and returns a result based on arguments which specify what to look for + * + * @param string $query The query to run + * @param boolean $checkResult Whether to check that a result was found (not needed for update/delete, only select): This result may be empty + * @param boolean $resultCheck Whether to check for returned results from the query + * @return unknown + */ + function runDBQuery($query, $checkResult = false, $resultCheck = false) { + if(!isset($this->iniUtilities) || !is_object($this->iniUtilities)) { + $this->dbUtilities = new dbUtilities(); + $this->iniUtilities = new iniUtilities(); + } + $wizConfigHandler = new configuration(); $configPath = $wizConfigHandler->readConfigPathIni(); - if(!is_object($this->iniUtilities)) { - parent::__construct(); - } + $this->iniUtilities->load($configPath); $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; + if($checkResult) { + $assArr = $this->dbUtilities->fetchAssoc($result); + if($resultCheck) { + return !is_null($assArr); + } else { + return is_null($assArr); + } + } + 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 +168,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 +184,23 @@ class UpgradeItem extends InstallUtil { return new Upgrade_Already_Applied($this); } } -// if (PEAR::isError($res)) { -// return $res; -// } - $oCache =& KTCache::getSingleton(); - $save = $oCache->bEnabled; - $oCache->bEnabled = false; $res = $this->_performUpgrade(); - $oCache->bEnabled = $save; -// if (PEAR::isError($res)) { -// $this->_recordUpgrade(false); -// return $res; -// } + 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'; + return false; + } return true; } function _performUpgrade() { -// return PEAR::raiseError("Unimplemented"); + $this->error[] = 'Unimplemented'; + return false; } function _recordUpgrade($result) { @@ -193,28 +212,20 @@ 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 (NULL, '". $this->getDescriptor()."', '".$this->description."', '".$this->date."', '".$result."', '".$parentid."')"; + $this->dbUtilities->query($sql); + + return true; } - // STATIC function getAllUpgrades() { return array(); } - -} +} // end class UpgradeItem class SQLUpgradeItem extends UpgradeItem { + function SQLUpgradeItem($path, $version = null, $description = null, $phase = null, $priority = null) { $this->type = "sql"; $this->priority = 0; @@ -249,19 +260,16 @@ class SQLUpgradeItem extends UpgradeItem { * * STATIC */ - function getUpgrades($origVersion, $currVersion) { -// global $default; - -// $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/'; - $dbType = 'mysql'; - $sqlupgradedir = KT_DIR . 'sql/' . $dbType . '/upgrade/'; + public static function getUpgrades($origVersion, $currVersion) { + $dbType = 'mysql'; + $sqlupgradedir = KT_DIR . 'sql/' . $dbType . '/upgrade/'; $ret = array(); if (!is_dir($sqlupgradedir)) { -// return PEAR::raiseError("SQL Upgrade directory ($sqlupgradedir) not accessible"); + return false; } if (!($dh = opendir($sqlupgradedir))) { -// return PEAR::raiseError("SQL Upgrade directory ($sqlupgradedir) not accessible"); + return false; } while (($file = readdir($dh)) !== false) { @@ -289,9 +297,6 @@ class SQLUpgradeItem extends UpgradeItem { if (!lte_version($details[1], $currVersion)) { continue; } - //print "Will run $file\n"; -// print_r($this->util->dbUtilities); -// die; $ret[] = new SQLUpgradeItem($file); } } @@ -310,10 +315,6 @@ class SQLUpgradeItem extends UpgradeItem { if (!lte_version($details[1], $currVersion)) { continue; } - //print "Will run $file\n"; -// print_r(SQLUpgradeItem::); -// die; -// new InstallUtil(); $ret[] = new SQLUpgradeItem($relpath); } } @@ -323,7 +324,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,18 +359,16 @@ 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); } - -} +} // end class SQLUpgradeItem class KTRebuildPermissionObserver { + function start() { $this->lastBeat = time(); } @@ -383,9 +382,11 @@ class KTRebuildPermissionObserver { } function end() { } + } class RecordUpgradeItem extends UpgradeItem { + function RecordUpgradeItem ($version, $oldversion = null) { $this->type = "upgrade"; if (is_null($oldversion)) { @@ -399,24 +400,30 @@ class RecordUpgradeItem extends UpgradeItem { } function _performUpgrade() { -// $this->_deleteSmartyFiles(); -// $this->_deleteProxyFiles(); -// require_once(KT_LIB_DIR . '/cache/cache.inc.php'); -// $oCache =& KTCache::getSingleton(); -// $oCache->deleteAllCaches(); + // What did this do? + /* + $this->_deleteSmartyFiles(); + $this->_deleteProxyFiles(); + require_once(KT_LIB_DIR . '/cache/cache.inc.php'); + $oCache =& KTCache::getSingleton(); + $oCache->deleteAllCaches(); // TODO : clear cache folder -// require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); - // TODO : What does this do -// $po =& new KTRebuildPermissionObserver($this); -// $po->start(); -// $oChannel =& KTPermissionChannel::getSingleton(); -// $oChannel->addObserver($po); + require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); + TODO : What does this do + $po =& new KTRebuildPermissionObserver($this); + $po->start(); + $oChannel =& KTPermissionChannel::getSingleton(); + $oChannel->addObserver($po); + */ set_time_limit(0); ignore_user_abort(true); -// KTPermissionUtil::rebuildPermissionLookups(true); -// $po->end(); + // What did this do? + /* + KTPermissionUtil::rebuildPermissionLookups(true); + $po->end(); + */ $versionFile=KT_DIR . '/docs/VERSION-NAME.txt'; $fp = fopen($versionFile,'rt'); @@ -426,8 +433,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() { @@ -452,7 +459,6 @@ class RecordUpgradeItem extends UpgradeItem { } } - function _deleteProxyFiles() { $oKTConfig =& KTConfig::getSingleton(); @@ -487,6 +493,7 @@ class RecordUpgradeItem extends UpgradeItem { @unlink($sFile); } } -} + +} // end class RecordUpgradeItem ?> diff --git a/setup/upgrade/lib/datetime.inc b/setup/upgrade/lib/datetime.inc.php index 6bcffd2..6bcffd2 100644 --- a/setup/upgrade/lib/datetime.inc +++ b/setup/upgrade/lib/datetime.inc.php diff --git a/setup/upgrade/lib/upgrade.inc.php b/setup/upgrade/lib/upgrade.inc.php index f083351..2fa9a9a 100644 --- a/setup/upgrade/lib/upgrade.inc.php +++ b/setup/upgrade/lib/upgrade.inc.php @@ -40,31 +40,34 @@ require_once('UpgradeItems.inc.php'); -//function setupAdminDatabase() { -// global $default; -// $dsn = array( -// 'phptype' => $default->dbType, -// 'username' => $default->dbAdminUser, -// 'password' => $default->dbAdminPass, -// 'hostspec' => $default->dbHost, -// 'database' => $default->dbName, -// 'port' => $default->dbPort, -// ); -// -// $options = array( -// 'debug' => 2, -// 'portability' => DB_PORTABILITY_ERRORS, -// 'seqname_format' => 'zseq_%s', -// ); -// -// $default->_admindb = &DB::connect($dsn, $options); -// if (PEAR::isError($default->_admindb)) { -// die($default->_admindb->toString()); -// } -// $default->_admindb->setFetchMode(DB_FETCHMODE_ASSOC); -// return; -//} -//setupAdminDatabase(); +// What did this do? +/* +function setupAdminDatabase() { + global $default; + $dsn = array( + 'phptype' => $default->dbType, + 'username' => $default->dbAdminUser, + 'password' => $default->dbAdminPass, + 'hostspec' => $default->dbHost, + 'database' => $default->dbName, + 'port' => $default->dbPort, + ); + + $options = array( + 'debug' => 2, + 'portability' => DB_PORTABILITY_ERRORS, + 'seqname_format' => 'zseq_%s', + ); + + $default->_admindb = &DB::connect($dsn, $options); + if (PEAR::isError($default->_admindb)) { + die($default->_admindb->toString()); + } + $default->_admindb->setFetchMode(DB_FETCHMODE_ASSOC); + return; +} +setupAdminDatabase(); +*/ // {{{ Format of the descriptor /** @@ -92,25 +95,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++) { @@ -197,7 +199,7 @@ function compare_version($version1, $version2) { */ function lte_version($version1, $version2) { if (in_array(compare_version($version1, $version2), array(-1, 0))) { - return true; + return true; } return false; } @@ -209,7 +211,7 @@ function lte_version($version1, $version2) { */ function gte_version($version1, $version2) { if (in_array(compare_version($version1, $version2), array(0, 1))) { - return true; + return true; } return false; } diff --git a/setup/upgrade/session.php b/setup/upgrade/session.php index 3942b4f..35ec698 100644 --- a/setup/upgrade/session.php +++ b/setup/upgrade/session.php @@ -63,7 +63,7 @@ class session */ public function startSession() { if(!isset($_SESSION[$this->salt]['ready'])) { -// session_start(); + session_start(); $_SESSION[$this->salt] ['ready'] = TRUE; } } diff --git a/setup/upgrade/step.php b/setup/upgrade/step.php index 2cf5254..355fabe 100644 --- a/setup/upgrade/step.php +++ b/setup/upgrade/step.php @@ -39,6 +39,9 @@ * @package Upgrader * @version Version 0.1 */ + +require_once("../wizard/steps/configuration.php"); // configuration to read the ini path + class Step { /** @@ -435,6 +438,44 @@ class Step return $_SESSION[$package][$class]; } + + protected function readConfig() { + $wizConfigHandler = new configuration(); + $path = $wizConfigHandler->readConfigPathIni(); + $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->sysVersion = $this->readVersion(); + $this->cachePath = $wizConfigHandler->readCachePath(); + $this->proxyPath = $this->cachePath."/.."; // Total guess. + $this->proxyPath = realpath($this->proxyPath."/proxies"); + $this->storeSilent(); + } + + protected function readVersion() { + $verFile = SYSTEM_DIR."docs".DS."VERSION.txt"; + if(file_exists($verFile)) { + $foundVersion = file_get_contents($verFile); + return $foundVersion; + } else { + $this->error[] = "KT installation version not found"; + } + + return false; + } + + protected function storeSilent() { + + } } ?> \ No newline at end of file diff --git a/setup/upgrade/stepAction.php b/setup/upgrade/stepAction.php index 438df77..ac20a9c 100644 --- a/setup/upgrade/stepAction.php +++ b/setup/upgrade/stepAction.php @@ -382,12 +382,12 @@ class stepAction { $step_errors = $this->action->getErrors(); // Get errors $step_warnings = $this->action->getWarnings(); // Get warnings if($this->displayConfirm()) { // Check if theres a confirm step - $template = "templates/{$this->stepName}_confirm.tpl"; + $template = "templates" . DS . "{$this->stepName}_confirm.tpl"; } else { if($this->displayFirst()) { - $template = "templates/{$this->stepName}_confirm.tpl"; + $template = "templates" . DS . "{$this->stepName}_confirm.tpl"; } else { - $template = "templates/{$this->stepName}.tpl"; + $template = "templates" . DS . "{$this->stepName}.tpl"; } } $step_tpl = new Template($template); @@ -402,7 +402,7 @@ class stepAction { } } $content = $step_tpl->fetch(); - $tpl = new Template("templates/wizard.tpl"); + $tpl = new Template("templates" . DS . "wizard.tpl"); $vars = $this->getVars(); // Get template variables $tpl->set("vars", $vars); // Set template errors $tpl->set('content', $content); diff --git a/setup/upgrade/steps/upgradeBackup.php b/setup/upgrade/steps/upgradeBackup.php index 8ce6505..51f28d8 100644 --- a/setup/upgrade/steps/upgradeBackup.php +++ b/setup/upgrade/steps/upgradeBackup.php @@ -40,9 +40,8 @@ * @version Version 0.1 */ -//require_once('../../config/dmsDefaults.php'); - class upgradeBackup extends Step { + protected $silent = false; protected $temp_variables = array(); @@ -83,13 +82,14 @@ class upgradeBackup extends Step { return 'landing'; } - private function backupNow() - { + private function backupNow() { return isset($_POST['BackupNow']); } private function doRun($action = null) { + $this->readConfig(); $this->temp_variables['action'] = $action; + $this->temp_variables['backupStatus'] = false; if (is_null($action) || ($action == 'confirm')) { $this->temp_variables['title'] = 'Confirm Backup'; @@ -101,18 +101,10 @@ class upgradeBackup extends Step { // TODO error checking (done in backupDone at the moment) $this->backupDone(); } - $this->storeSilent();// Set silent mode variables return true; } - /** - * Set all silent mode varibles - * - */ - private function storeSilent() { - } - private function backup() { $targetfile = $_SESSION['backupFile']; $stmt = $this->create_backup_stmt($targetfile); @@ -126,11 +118,11 @@ class upgradeBackup extends Step { $handle = popen($stmt['cmd'], 'r'); $read = fread($handle, 10240); pclose($handle); - $_SESSION['backupOutput']=$read; + $_SESSION['backupOutput'] = $read; $dir = $this->util->resolveTempDir(); - $_SESSION['backupFile'] = $stmt['target']; + $_SESSION['backupFile'] = $stmt['target']; - if (OS_UNIX) { + if (!WINDOWS_OS) { chmod($stmt['target'],0600); } @@ -151,7 +143,7 @@ class upgradeBackup extends Step { if ($status) { - $stmt = $this->util->create_restore_stmt($filename); + $stmt = $this->util->create_restore_stmt($filename, $this->dbSettings); $this->temp_variables['display'] = 'The backup file "' . $filename . '" has been created.

It appears as though the backup has been successful.

'; @@ -193,56 +185,54 @@ class upgradeBackup extends Step { } private function create_backup_stmt($targetfile=null) - { - $oKTConfig =& KTConfig::getSingleton(); - - $adminUser = $oKTConfig->get('db/dbAdminUser'); - $adminPwd = $oKTConfig->get('db/dbAdminPass'); - $dbHost = $oKTConfig->get('db/dbHost'); - $dbName = $oKTConfig->get('db/dbName'); - - $dbPort = trim($oKTConfig->get('db/dbPort')); + { + $adminUser = $this->dbSettings['dbAdminUser']; + $adminPwd = $this->dbSettings['dbAdminPass']; + $dbHost = $this->dbSettings['dbHost']; + $dbName = $this->dbSettings['dbName']; + + $dbPort = trim($this->dbSettings['dbPort']); if (empty($dbPort) || $dbPort=='default') $dbPort = get_cfg_var('mysql.default_port'); if (empty($dbPort)) $dbPort='3306'; - $dbSocket = trim($oKTConfig->get('db/dbSocket')); + // dbSocket doesn't exist as far as I can find, where was it coming from? + //$dbSocket = trim($this->dbSettings['dbSocket']); + $dbSocket = ''; if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; $date=date('Y-m-d-H-i-s'); - $dir=$this->util->resolveMysqlDir(); + $dir = $this->util->resolveMysqlDir(); - $info['dir']=$dir; - - $prefix=''; - if (OS_UNIX) + $info['dir'] = $dir; + $prefix = ''; + if (!WINDOWS_OS) { $prefix .= "./"; } if (@stat($dbSocket) !== false) { - $mechanism="--socket=\"$dbSocket\""; + $mechanism = "--socket=\"$dbSocket\""; } else { - $mechanism="--port=\"$dbPort\""; + $mechanism = "--port=\"$dbPort\""; } - $tmpdir=$this->util->resolveTempDir(); + $tmpdir = $this->util->resolveTempDir(); if (is_null($targetfile)) { - $targetfile="$tmpdir/kt-backup-$date.sql"; + $targetfile = "$tmpdir/kt-backup-$date.sql"; } $stmt = $prefix . "mysqldump --user=\"$adminUser\" -p $mechanism \"$dbName\" > \"$targetfile\""; - $info['display']=$stmt; - $info['target']=$targetfile; - + $info['display'] = $stmt; + $info['target'] = $targetfile; $stmt = $prefix. "mysqldump --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" > \"$targetfile\""; - $info['cmd']=$stmt; + $info['cmd'] = $stmt; return $info; } @@ -255,5 +245,6 @@ class upgradeBackup extends Step { $this->temp_variables['dir'] = $dir; $this->temp_variables['display'] = $stmt['display']; } + } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeComplete.php b/setup/upgrade/steps/upgradeComplete.php index e8e6857..efa0ef9 100644 --- a/setup/upgrade/steps/upgradeComplete.php +++ b/setup/upgrade/steps/upgradeComplete.php @@ -40,8 +40,6 @@ * @version Version 0.1 */ -//require_once('../../config/dmsDefaults.php'); - class upgradeComplete extends Step { protected $silent = false; @@ -50,6 +48,7 @@ class upgradeComplete extends Step { public function doStep() { $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent); + $this->doRun(); return 'landing'; } @@ -62,7 +61,9 @@ class upgradeComplete extends Step { * Set all silent mode varibles * */ - private function storeSilent() { + protected 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 d84565f..c3360c7 100644 --- a/setup/upgrade/steps/upgradeDatabase.php +++ b/setup/upgrade/steps/upgradeDatabase.php @@ -40,12 +40,9 @@ * @version Version 0.1 */ -//require_once('../../config/dmsDefaults.php'); -//require_once(KT_LIB_DIR . '/config/config.inc.php'); -//require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php'); define('KT_DIR', SYSTEM_DIR); define('KT_LIB_DIR', SYSTEM_DIR.'lib'); -//require_once(SYSTEM_DIR . 'lib/upgrades/upgrade.inc.php'); +require_once(WIZARD_LIB . 'upgrade.inc.php'); class upgradeDatabase extends Step { @@ -68,15 +65,6 @@ class upgradeDatabase extends Step private $dbBinary = ''; // TODO:multiple databases /** - * List of errors encountered - * - * @author KnowledgeTree Team - * @access public - * @var array - */ - public $error = array(); - - /** * List of errors used in template * * @author KnowledgeTree Team @@ -93,11 +81,13 @@ class upgradeDatabase extends Step * @var array */ public $storeInSession = true; + public $sysVersion = ''; protected $silent = false; protected $temp_variables = array(); public $paths = ''; - /** + + /** * Main control of database setup * * @author KnowledgeTree Team @@ -143,17 +133,11 @@ 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'; $this->temp_variables['upgradeTable'] = $this->generateUpgradeTable(); @@ -178,15 +162,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"; @@ -214,30 +199,6 @@ class upgradeDatabase extends Step return false; } - /** - * Stores varibles used by template - * - * @author KnowledgeTree Team - * @params none - * @access public - * @return array - */ - public function getStepVars() { - return $this->temp_variables; - } - - /** - * Returns database errors - * - * @author KnowledgeTree Team - * @access public - * @params none - * @return array - */ - public function getErrors() { - - return $this->error; - } /** * Initialize errors to false @@ -253,25 +214,11 @@ class upgradeDatabase extends Step } } - private function readConfig() { - 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'], - '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(); + 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() @@ -286,8 +233,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 @@ -295,18 +240,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

@@ -320,13 +257,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; } @@ -335,40 +266,59 @@ 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 (empty($sPath) || !is_dir($sPath)) return; + + 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 = $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(); - - // Clear the configuration cache, it'll regenerate on next load - $oKTConfig = new KTConfig(); - $oKTConfig->clearCache(); + $this->deleteDirectory($this->proxyPath); + $this->deleteDirectory($this->cachePath); // Unlock the scheduler - $lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock'; + $lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock'; if(file_exists($lockFile)){ @unlink($lockFile); } @@ -378,18 +328,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"; @@ -403,15 +350,8 @@ 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 === false) { - $res = PEAR::raiseError("Upgrade returned false"); + $this->error = $this->util->dbUtilities->getErrors(); break; } } @@ -420,11 +360,8 @@ class upgradeDatabase extends Step } private function showResult($res) { - if (PEAR::isError($res)) { - if (is_a($res, 'Upgrade_Already_Applied')) { - return 'Already applied'; - } - return sprintf('%s', htmlspecialchars($res->toString())); + if ($res && is_a($res, 'Upgrade_Already_Applied')) { + return 'Already applied'; } if ($res === true) { return 'Success'; @@ -434,6 +371,5 @@ class upgradeDatabase extends Step } return $res; } - } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeRestore.php b/setup/upgrade/steps/upgradeRestore.php index 0d3f503..1cdc480 100644 --- a/setup/upgrade/steps/upgradeRestore.php +++ b/setup/upgrade/steps/upgradeRestore.php @@ -40,18 +40,18 @@ * @version Version 0.1 */ -//require_once('../../config/dmsDefaults.php'); - class upgradeRestore extends Step { protected $silent = false; protected $temp_variables = array(); - public function doStep() { + public function doStep() { $this->temp_variables = array("step_name"=>"restore", "silent"=>$this->silent, "loadingText"=>"The database restore is under way. Please wait until it completes"); $this->temp_variables['restore'] = false; + $this->temp_variables['display'] = ''; + $this->temp_variables['dir'] = ''; if(!$this->inStep("restore")) { $this->doRun(); @@ -79,6 +79,8 @@ class upgradeRestore extends Step { } private function doRun($restore = false) { + $this->readConfig(); + if (!$restore) { $this->temp_variables['selected'] = false; if ($this->select()) { @@ -92,8 +94,6 @@ class upgradeRestore extends Step { $this->restoreDatabase(); } - $this->storeSilent();// Set silent mode variables - return true; } @@ -101,19 +101,12 @@ class upgradeRestore extends Step { return isset($_POST['RestoreSelect']); } - /** - * Set all silent mode varibles - * - */ - private function storeSilent() { - } - private function restoreDatabase() { $this->temp_variables['restore'] = true; $status = $_SESSION['backupStatus']; $filename = $_SESSION['backupFile']; - $stmt = $this->util->create_restore_stmt($filename); + $stmt = $this->util->create_restore_stmt($filename, $this->dbSettings); $dir = $stmt['dir']; if (is_file($dir . '/mysql') || is_file($dir . '/mysql.exe')) @@ -219,7 +212,7 @@ class upgradeRestore extends Step { $status = $_SESSION['backupStatus']; $filename = $_SESSION['backupFile']; - $stmt = $this->util->create_restore_stmt($filename); + $stmt = $this->util->create_restore_stmt($filename, $this->dbSettings); $this->temp_variables['title'] = 'Confirm Restore'; $this->temp_variables['dir'] = $stmt['dir']; @@ -227,6 +220,6 @@ class upgradeRestore extends Step { $this->temp_variables['availableBackups'] = true; $this->temp_variables['selected'] = true; } - + } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeWelcome.php b/setup/upgrade/steps/upgradeWelcome.php index 3e4d056..37c8ab0 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()) { @@ -81,15 +82,13 @@ class upgradeWelcome extends step { private function checkPassword($username, $password) { $dconf = $this->getDataFromPackage('installers', 'database'); // Use info from install if($dconf) { - $this->util->dbUtilities->load($dconf['dhost'], $dbconf['dport'], $dconf['duname'], $dconf['dpassword'], $dconf['dname']); + $this->util->dbUtilities->load($dconf['dhost'], $dconf['dport'], $dconf['duname'], $dconf['dpassword'], $dconf['dname']); } else { require_once("../wizard/steps/configuration.php"); // configuration to read the ini path $wizConfigHandler = new configuration(); $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/backup.tpl b/setup/upgrade/templates/backup.tpl index b1aeea7..39bdaeb 100644 --- a/setup/upgrade/templates/backup.tpl +++ b/setup/upgrade/templates/backup.tpl @@ -46,7 +46,7 @@ You can continue to do the backup manually using the following process:

- +



- 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..8f78772 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
"; + } + ?>


@@ -13,13 +20,11 @@ + if ($backupStatus) { ?>

We are about to start the upgrade process.

-
- Please ensure that you have made a backup before continuing with the upgrade process. -

+

Please ensure that you have made a backup before continuing with the upgrade process.

- +

diff --git a/setup/upgrade/templates/restore.tpl b/setup/upgrade/templates/restore.tpl index 8c23929..d45ec12 100644 --- a/setup/upgrade/templates/restore.tpl +++ b/setup/upgrade/templates/restore.tpl @@ -92,7 +92,7 @@ Press Next to attempt the command(s) above. ?>
- +
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/upgrade/upgradeUtil.php b/setup/upgrade/upgradeUtil.php index ad78277..24dbfab 100644 --- a/setup/upgrade/upgradeUtil.php +++ b/setup/upgrade/upgradeUtil.php @@ -116,35 +116,35 @@ class UpgradeUtil extends InstallUtil { return true; } - public function create_restore_stmt($targetfile) + public function create_restore_stmt($targetfile, $dbConfig) { - $oKTConfig =& KTConfig::getSingleton(); +// $oKTConfig =& KTConfig::getSingleton(); - $adminUser = $oKTConfig->get('db/dbAdminUser'); - $adminPwd = $oKTConfig->get('db/dbAdminPass'); - $dbHost = $oKTConfig->get('db/dbHost'); - $dbName = $oKTConfig->get('db/dbName'); - $dbPort = trim($oKTConfig->get('db/dbPort')); + $adminUser = $dbConfig['dbAdminUser']; + $adminPwd = $dbConfig['dbAdminPass']; + $dbHost = $dbConfig['dbHost']; + $dbName = $dbConfig['dbName']; + $dbPort = trim($dbConfig['dbPort']); if ($dbPort=='' || $dbPort=='default')$dbPort = get_cfg_var('mysql.default_port'); if (empty($dbPort)) $dbPort='3306'; - $dbSocket = trim($oKTConfig->get('db/dbSocket')); + $dbSocket = ''; if (empty($dbSocket) || $dbSocket=='default') $dbSocket = get_cfg_var('mysql.default_socket'); if (empty($dbSocket)) $dbSocket='../tmp/mysql.sock'; $dir = $this->resolveMysqlDir(); - $info['dir']=$dir; + $info['dir'] = $dir; - $prefix=''; - if (OS_UNIX) { + $prefix = ''; + if (!WINDOWS_OS) { $prefix .= "./"; } if (@stat($dbSocket) !== false) { - $mechanism="--socket=\"$dbSocket\""; + $mechanism = "--socket=\"$dbSocket\""; } else { - $mechanism="--port=\"$dbPort\""; + $mechanism = "--port=\"$dbPort\""; } $tmpdir = $this->resolveTempDir(); @@ -152,16 +152,14 @@ class UpgradeUtil extends InstallUtil { $stmt = $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism drop \"$dbName\"
"; $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" -p $mechanism create \"$dbName\"
"; - $stmt .= $prefix ."mysql --user=\"$adminUser\" -p $mechanism \"$dbName\" < \"$targetfile\"\n"; $info['display']=$stmt; - $stmt = $prefix ."mysqladmin --user=\"$adminUser\" --force --password=\"$adminPwd\" $mechanism drop \"$dbName\"\n"; $stmt .= $prefix ."mysqladmin --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism create \"$dbName\"\n"; $stmt .= $prefix ."mysql --user=\"$adminUser\" --password=\"$adminPwd\" $mechanism \"$dbName\" < \"$targetfile\""; - $info['cmd']=$stmt; + $info['cmd'] = $stmt; return $info; } @@ -169,7 +167,7 @@ class UpgradeUtil extends InstallUtil { { // possibly detect existing installations: - if (OS_UNIX) { + if (!WINDOWS_OS) { $dirs = array('/opt/mysql/bin','/usr/local/mysql/bin'); $mysqlname ='mysql'; } @@ -181,8 +179,9 @@ class UpgradeUtil extends InstallUtil { $mysqlname ='mysql.exe'; } - $oKTConfig =& KTConfig::getSingleton(); - $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); + // I don't know if this value exists anymore? +// $mysqldir = $oKTConfig->get('backup/mysqlDirectory',$mysqldir); + $mysqldir = ''; $dirs[] = $mysqldir; if (strpos(__FILE__,'knowledgeTree') !== false && strpos(__FILE__,'ktdms') != false) { @@ -202,14 +201,16 @@ class UpgradeUtil extends InstallUtil { public function resolveTempDir() { - if (OS_UNIX) { + $dir = ''; + if (!WINDOWS_OS) { $dir='/tmp/kt-db-backup'; } else { $dir='c:/kt-db-backup'; } - $oKTConfig =& KTConfig::getSingleton(); - $dir = $oKTConfig->get('backup/backupDirectory',$dir); + +// $oKTConfig =& KTConfig::getSingleton(); +// $dir = $oKTConfig->get('backup/backupDirectory',$dir); if (!is_dir($dir)) { mkdir($dir); diff --git a/setup/upgrade/upgradeWizard.php b/setup/upgrade/upgradeWizard.php index 3ae5497..9e05d1c 100644 --- a/setup/upgrade/upgradeWizard.php +++ b/setup/upgrade/upgradeWizard.php @@ -50,8 +50,8 @@ include("../wizard/path.php"); // Paths function __autoload($class) { // Attempt and autoload classes $class = strtolower(substr($class,0,1)).substr($class,1); // Linux Systems. if ($class == "template") { // Load existing templating classes - require_once("../wizard/template.php"); - require_once("../wizard/lib/helpers/htmlHelper.php"); + require_once(WIZARD_DIR."../wizard/template.php"); + require_once(WIZARD_DIR."../wizard/lib/helpers/htmlHelper.php"); return ; } if(file_exists(WIZARD_DIR."$class.php")) { 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..fdf9bb1 100644 --- a/setup/wizard/steps/configuration.php +++ b/setup/wizard/steps/configuration.php @@ -390,17 +390,25 @@ class configuration extends Step */ private function getServerInfo() { + $iis = false; $script = $_SERVER['SCRIPT_NAME']; $file_system_root = $_SERVER['DOCUMENT_ROOT']; + if(preg_match('/inetpub/', $file_system_root)) { + $iis = true; + $file_system_root = $_SERVER['APPL_PHYSICAL_PATH']; + } $host = $_SERVER['SERVER_NAME']; $port = $_SERVER['SERVER_PORT']; $ssl_enabled = isset($_SERVER['HTTPS']) ? (strtolower($_SERVER['HTTPS']) === 'on' ? 'yes' : 'no') : 'no'; $pos = strpos($script, '/setup/wizard/'); $root_url = substr($script, 0, $pos); - $root_url = (isset($_POST['root_url'])) ? $_POST['root_url'] : $root_url; - $file_system_root = (isset($_POST['file_system_root'])) ? $_POST['file_system_root'] : $file_system_root.$root_url; + if($iis) { + $file_system_root = (isset($_POST['file_system_root'])) ? $_POST['file_system_root'] : $file_system_root; + } else { + $file_system_root = (isset($_POST['file_system_root'])) ? $_POST['file_system_root'] : $file_system_root.$root_url; + } $host = (isset($_POST['host'])) ? $_POST['host'] : $host; $port = (isset($_POST['port'])) ? $_POST['port'] : $port; $ssl_enabled = (isset($_POST['ssl_enabled'])) ? $_POST['ssl_enabled'] : $ssl_enabled; @@ -460,6 +468,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/template.php b/setup/wizard/template.php index 28d5c35..ba0f088 100644 --- a/setup/wizard/template.php +++ b/setup/wizard/template.php @@ -96,6 +96,8 @@ class Template public function fetch($file = null) { if (is_null($file)) $file = $this->file; + + $file = WIZARD_DIR . $file; if (!file_exists($file)) { trigger_error('Template file '.$file.' does not exist ', E_USER_ERROR); } 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..db3c395 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' =>'', @@ -91,6 +91,7 @@ class jsonWrapper{ public $jsonArray=array(); public function __construct($content=NULL){ + $content=stripslashes($content); $this->raw=$content; $content=@json_decode($content,true); if(!is_array($content))throw new jsonContentException('Invalid JSON input',jsonContentException::INPUT_ERROR); 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..db7f273 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); @@ -847,7 +855,7 @@ class kt extends client_service { private function update_document_metadata($session_id, $document_id, $metadata, $application, $sysdata=null){ - $this->addDebug('','entered update_document_metadata'); + $this->addDebug('update_document_metadata','entered update_document_metadata'); $kt=&$this->KT; $responseType='kt_document_detail'; @@ -915,27 +923,44 @@ class kt extends client_service { public function update_metadata($arr){ $metadata=array(); - $packed=@json_decode($arr['metadata']); + $meta=$arr['metadata']; $this->addDebug('','Entered add_document_with_metadata'); + $this->addDebug('metadata received',$meta); $special=array(); - - foreach($packed as $key=>$val) { - if(substr($val->name,0,2) != '__') { - if(!is_array($metadata[$val->fieldset])) { - $metadata[$val->fieldset]['fieldset']=$val->fieldset; - $metadata[$val->fieldset]['fields']=array(); - } - $metadata[$val->fieldset]['fields'][]=array( - 'name'=>$val->name, - 'value'=>$val->value - ); +// foreach($apacked as $packed){ +// foreach($packed as $key=>$val) { +// if(substr($val->name,0,2) != '__') { +// if(!is_array($metadata[$val->fieldset])) { +// $metadata[$val->fieldset]['fieldset']=$val->fieldset; +// $metadata[$val->fieldset]['fields']=array(); +// } +// $metadata[$val->fieldset]['fields'][]=array( +// 'name'=>$val->name, +// 'value'=>$val->value +// ); +// }else{ +// $special[$val->name]=$val->value; +// } +// } +// } + + foreach($meta as $item){ + $isSpecial=substr($item['name'],0,2)=='__'; + if($isSpecial){ + $special[$item['name']]=$item['value']; }else{ - $special[$val->name]=$val->value; - } + $fieldSet=$item['fieldset']; + unset($item['fieldset']); + $metadata[$fieldSet]['fieldset']=$fieldSet; + $metadata[$fieldSet]['fields'][]=$item; + } } - + + + $this->addDebug('after processing',array('metadata'=>$metadata,'special'=>$special)); + $document_id=$arr['document_id']; $update_result=$this->update_document_metadata($arr['session_id'], $document_id, $metadata, $arr['application'], array()); diff --git a/webservice/clienttools/standardservices/system.php b/webservice/clienttools/standardservices/system.php new file mode 100644 index 0000000..9e6b891 --- /dev/null +++ b/webservice/clienttools/standardservices/system.php @@ -0,0 +1,30 @@ +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; + } + + public function jsondecode($params){ + $this->setResponse(@json_decode(trim($params['code']))); + } +} + +?> \ No newline at end of file
CodeDescriptionApplied