diff --git a/bin/system_info.php b/bin/system_info.php index 8c3ae59..e9b39d0 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,27 @@ function getKTEdition() function getOSInfo() { $server = php_uname(); + $flavour = '';//'|-'; if(strpos($server, 'Darwin') !== false){ $os = 'Mac OS X'; }else if(strpos($server, 'Win') !== false){ $os = 'Windows'; - }else { + }else if(strpos($server, 'Linux') !== false) { + // Again regular expressions would be nice... + // $pos = strpos($server, 'SMP'); + // $flavour = '|'.substr($server, 6, $pos-7); $os = 'Linux'; + }else { + $os = 'Unix'; } - return $os; + return $os.$flavour; } 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/config/cache-path b/config/cache-path index 80a084a..bea5430 100644 --- a/config/cache-path +++ b/config/cache-path @@ -1 +1 @@ -var/cache +var/cache \ No newline at end of file diff --git a/config/config-path b/config/config-path index 4bfe59e..b02c44d 100644 --- a/config/config-path +++ b/config/config-path @@ -1 +1 @@ -config/config.ini +config/config.ini \ No newline at end of file diff --git a/config/config.ini b/config/config.ini index 3168122..61ae5a2 100644 --- a/config/config.ini +++ b/config/config.ini @@ -9,14 +9,14 @@ dbType = mysql ; Database login details -dbHost = localhost -dbName = dms -dbUser = dms -dbPass = djw9281js -dbPort = default +dbHost = localhost +dbName = dms +dbUser = dms +dbPass = djw9281js +dbPort = default -dbAdminUser = dmsadmin -dbAdminPass = js9281djw +dbAdminUser = dmsadmin +dbAdminPass = js9281djw [KnowledgeTree] @@ -43,7 +43,7 @@ serverName = default ; ; Leave as default to have it automatically detected. ; -sslEnabled = default +sslEnabled = false ; Path to the web application from the root of the web site. ; If KT is at http://example.org/foo/, then rootUrl should be '/foo' @@ -146,4 +146,4 @@ encoding = default ; cacheEnabled = true cacheDirectory = ${varDirectory}/cache -cachePlugins = true \ No newline at end of file +cachePlugins = true 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 99849d3..ab78767 100755 --- a/lib/metadata/fieldsetregistry.inc.php +++ b/lib/metadata/fieldsetregistry.inc.php @@ -111,7 +111,7 @@ class KTFieldsetRegistry { */ function getGenericFields($oFieldset, $idPre = 'metadata_') { //return false if this isn't a generic fieldset - if ($oFieldset->getIsGeneric()) { + if (!$oFieldset->getIsGeneric()) { return false; } 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/plugins/multiselect/BulkImport.php b/plugins/multiselect/BulkImport.php old mode 100644 new mode 100755 index 7aa40bd..b42fb88 --- a/plugins/multiselect/BulkImport.php +++ b/plugins/multiselect/BulkImport.php @@ -292,14 +292,17 @@ class InetBulkImportFolderMultiSelectAction extends KTFolderAction { // name='metadata[fieldset][metadata_9]' $aData = $_REQUEST['data']; + $data = $aData; + /* $oForm = $this->getBulkImportForm(); $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError(); } $data = $res['results']; - + */ + $doctypeid = $requestDocumentType; $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); @@ -312,6 +315,7 @@ class InetBulkImportFolderMultiSelectAction extends KTFolderAction { foreach ($fields as $oField) { $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); + if ($oFieldset->getIsConditional()) { if ($val == _kt('No selection.')) @@ -319,16 +323,16 @@ class InetBulkImportFolderMultiSelectAction extends KTFolderAction { $val = null; } } - + if (!is_null($val)) { $MDPack[] = array( $oField, $val ); } - + } - } + } $aOptions = array( 'documenttype' => $oDocumentType, @@ -340,7 +344,7 @@ class InetBulkImportFolderMultiSelectAction extends KTFolderAction { $po->start(); $oUploadChannel =& KTUploadChannel::getSingleton(); $oUploadChannel->addObserver($po); - + $fs =& new KTFSImportStorage($sPath); $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); if(KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin')) diff --git a/plugins/multiselect/BulkUpload.php b/plugins/multiselect/BulkUpload.php old mode 100644 new mode 100755 index f2ce9ac..db2aaa6 --- a/plugins/multiselect/BulkUpload.php +++ b/plugins/multiselect/BulkUpload.php @@ -330,7 +330,6 @@ class InetBulkUploadFolderAction extends KTFolderAction { foreach ($fields as $oField) { //var_dump($oField->getId()); $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); - //var_dump($val); if ($oFieldset->getIsConditional()) { if ($val == _kt('No selection.')) diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/getHtmlFields.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/getHtmlFields.php index 178ec7b..02b96df 100755 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/getHtmlFields.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/getHtmlFields.php @@ -84,7 +84,7 @@ class GetHtmlFieldsDispatcher extends KTDispatcher { $activesets = KTFieldset::getForDocumentType($iDocumentTypeID); foreach ($activesets as $oFieldset) { - $htmlFieldIds = kt_array_merge($htmlFields, $oFReg->getHtmlFields($oFieldset)); + $htmlFieldIds = kt_array_merge($htmlFieldIds, $oFReg->getHtmlFields($oFieldset)); } $jsOptions = '{ "htmlId" : {'; @@ -101,20 +101,19 @@ class GetHtmlFieldsDispatcher extends KTDispatcher { /** * Returns a JSON object containing a list of fields belonging to a generic fieldset - * for the given DocumentId * @return JSON Object * */ - function getGenericFields($iDocumentTypeID) { + function getGenericFields() { $oFReg =& KTFieldsetRegistry::getSingleton(); - $activesets = KTFieldset::getForDocumentType($iDocumentTypeID); + $activesets = KTFieldset::getGenericFieldsets(); $fields = array(); foreach ($activesets as $oFieldset) { - $fieldIds = kt_array_merge($fields, $oFReg->getGenericFields($oFieldset)); + $fieldIds = kt_array_merge($fieldIds, $oFReg->getGenericFields($oFieldset)); } - $jsOptions = '{ "htmlId" : {'; + $jsOptions = '{ "genericId" : {'; foreach($fieldIds as $fieldId) { $jsOptions .= "'$fieldId' : '$fieldId',"; diff --git a/resources/js/kt_bulkupload.js b/resources/js/kt_bulkupload.js index 1ef42c7..180c372 100755 --- a/resources/js/kt_bulkupload.js +++ b/resources/js/kt_bulkupload.js @@ -19,10 +19,10 @@ function swapInItem(docId, elementId, req) { //Need to compare against fields from generic fieldsets to //prevent duplicate date field instanciation. var genericFields = ''; - //Sample { "htmlId" : {'metadata_7' : 'metadata_7','metadata_9' : 'metadata_9'}} + //Sample { "genericId" : {'metadata_7' : 'metadata_7','metadata_9' : 'metadata_9'}} jQuery.getJSON('presentation/lookAndFeel/knowledgeTree/documentmanagement/getHtmlFields.php?fDocumentTypeID=' + docId + '&type=generic', function(json){ - jQuery.each(json.htmlId, function(id) { + jQuery.each(json.genericId, function(id) { //Building a list of generic fields genericFields += id + ','; }); @@ -30,16 +30,15 @@ function swapInItem(docId, elementId, req) { var elems = jQuery(document).find(".kt_date_field"); for (i = 0; i < elems.length; i++) { var fieldName = elems[i].id; - //alert(fieldName); - isGeneric = true; + isGeneric = false; if (genericFields.indexOf(fieldName.match('metadata_[0-9]+')) >= 0){ - isGeneric = false; + isGeneric = true; } if (!isGeneric){ var dp = new Ext.form.DateField({ - name: fieldName, + name: fieldName.replace('div_', ''), allowBlank:false, size:10, format: 'Y-m-d', diff --git a/setup/migrate/migrateUtil.php b/setup/migrate/migrateUtil.php index 28fd474..ac07f0f 100644 --- a/setup/migrate/migrateUtil.php +++ b/setup/migrate/migrateUtil.php @@ -63,14 +63,14 @@ class MigrateUtil extends InstallUtil { $template_vars['error'] = $error; $file = "templates/error.tpl"; if (!file_exists($file)) { - return false; + extract($template_vars); // Extract the vars to local namespace + ob_start(); + include($file); + $contents = ob_get_contents(); + ob_end_clean(); + echo $contents; } - extract($template_vars); // Extract the vars to local namespace - ob_start(); - include($file); - $contents = ob_get_contents(); - ob_end_clean(); - echo $contents; + return false; } /** @@ -89,19 +89,10 @@ class MigrateUtil extends InstallUtil { return true; } - - public function loadInstallDBUtil() { - require_once("../wizard/dbUtilities.php"); - return new dbUtilities(); - } - - public function loadInstallUtil() { - require_once("../wizard/steps/services.php"); - return new services(); - } public function loadInstallServices() { - $s = $this->loadInstallUtil(); + require_once("../wizard/steps/services.php"); + $s = new services(); return $s->getServices(); } @@ -112,11 +103,6 @@ class MigrateUtil extends InstallUtil { return new $serviceName(); } - public function loadInstallIni($path) { - require_once("../wizard/iniUtilities.php"); - return new iniUtilities($path); - } - public function getPort($location) { if(WINDOWS_OS) { $myIni = "my.ini"; @@ -125,8 +111,8 @@ class MigrateUtil extends InstallUtil { } $dbConfigPath = $location.DS."mysql".DS."$myIni"; if(file_exists($dbConfigPath)) { - $ini = $this->loadInstallIni($dbConfigPath); - $dbSettings = $ini->getSection('mysqladmin'); + $this->iniUtilities->load($dbConfigPath); + $dbSettings = $this->iniUtilities->getSection('mysqladmin'); return $dbSettings['port']; } diff --git a/setup/migrate/migrateWizard.php b/setup/migrate/migrateWizard.php index 0bb58d0..03c93fe 100644 --- a/setup/migrate/migrateWizard.php +++ b/setup/migrate/migrateWizard.php @@ -52,16 +52,14 @@ function __autoload($class) { // Attempt and autoload classes if ($class == "template") { // Load existing templating classes require_once("../wizard/template.php"); require_once("../wizard/lib/helpers/htmlHelper.php"); - return ; - } - if(file_exists(WIZARD_DIR."$class.php")) { - require_once(WIZARD_DIR."$class.php"); - } elseif (file_exists(STEP_DIR."$class.php")) { - require_once(STEP_DIR."$class.php"); - } elseif (file_exists(WIZARD_LIB."$class.php")) { - require_once(WIZARD_LIB."$class.php"); } else { - return null; + if(file_exists(WIZARD_DIR."$class.php")) { + require_once(WIZARD_DIR."$class.php"); + } elseif (file_exists(STEP_DIR."$class.php")) { + require_once(STEP_DIR."$class.php"); + } elseif (file_exists(WIZARD_LIB."$class.php")) { + require_once(WIZARD_LIB."$class.php"); + } } } @@ -233,8 +231,6 @@ class MigrateWizard { return true; break; } - - return $res; } /** diff --git a/setup/migrate/migrater.php b/setup/migrate/migrater.php index 249fa36..86f78f5 100644 --- a/setup/migrate/migrater.php +++ b/setup/migrate/migrater.php @@ -157,7 +157,7 @@ class Migrater { $this->simpleXmlObj = simplexml_load_file(CONF_DIR.$name); } catch (Exception $e) { $util = new MigrateUtil(); - $util->error("Error reading configuration file: $name"); + $util->error("Error reading configuration file: $e"); exit(); } } @@ -431,8 +431,7 @@ class Migrater { if($class->runMigrate()) { // Check if step needs to be migrated $class->setDataFromSession($className); // Set Session Information $class->setPostConfig(); // Set any posted variables - $response = $class->migrateStep(); // Run migrate step - // TODO : Break on error response + $class->migrateStep(); // Run migrate step } } else { $util = new MigrateUtil(); diff --git a/setup/migrate/step.php b/setup/migrate/step.php index 897b710..06d4ef1 100644 --- a/setup/migrate/step.php +++ b/setup/migrate/step.php @@ -117,18 +117,8 @@ class Step */ public $util; - /** - * Reference to utility object - * - * @author KnowledgeTree Team - * @access protected - * @var object - */ - public $dbhandler; - public function __construct() { $this->util = new MigrateUtil(); - $this->dbhandler = $this->util->loadInstallDBUtil(); } /** diff --git a/setup/migrate/stepAction.php b/setup/migrate/stepAction.php index 30724ed..e804976 100644 --- a/setup/migrate/stepAction.php +++ b/setup/migrate/stepAction.php @@ -224,17 +224,18 @@ class stepAction { if($this->action->storeInSession()) { // Check if class values need to be stored in session $this->_loadStepToSession($this->stepName); // Send class to session } - if ($response == 'error') { - $this->_handleErrors(); // Send Errors to session - } else { - $this->_clearErrors($this->stepName); // Send Errors to session - } - return $response; } else { $this->stepName = 'errors'; $this->action = $this->createStep(); $this->action->error = array('Class File Missing in Step Directory'); + + } + if ($response == 'error') { + $this->_handleErrors(); // Send Errors to session + } else { + $this->_clearErrors($this->stepName); // Send Errors to session } + return $response; } /** @@ -308,7 +309,7 @@ class stepAction { $menu = ''; $active = false; if($this->stepClassNames) { - foreach ($this->stepClassNames as $k=>$step) { + foreach ($this->stepClassNames as $step) { if($this->step_names[$step] != '') { $item = $this->step_names[$step]; } else { @@ -452,7 +453,7 @@ class stepAction { * @access private * @return void */ - private function _loadValueToSession($class, $k, $v, $overwrite = false) { + private function _loadValueToSession($class, $k, $v) { if($this->session != null) { $this->session->setClass($class, $k, $v); } else { @@ -502,8 +503,7 @@ class stepAction { * @access private * @return void */ - private function _loadErrorToSession($class, $k, $v, $overwrite = false) { - $k = "errors"; + private function _loadErrorToSession($class, $k = "errors", $v) { if($this->session != null) { $this->session->setClassError($class, $k, $v); } else { diff --git a/setup/migrate/steps/migrateDatabase.php b/setup/migrate/steps/migrateDatabase.php index 26fb90b..e9d872b 100644 --- a/setup/migrate/steps/migrateDatabase.php +++ b/setup/migrate/steps/migrateDatabase.php @@ -122,16 +122,16 @@ class migrateDatabase extends Step $manual = false; // If file was exported manually $dbSettings = $installation['dbSettings']; $location = $installation['location']; - $uname = $this->temp_variables['duname']; - $pwrd = $this->temp_variables['dpassword']; +// $uname = $this->temp_variables['duname']; +// $pwrd = $this->temp_variables['dpassword']; $port = $this->util->getPort($location); $tmpFolder = $this->resolveTempDir(); if(WINDOWS_OS) { $termOrBash = "command prompt window"; - $exe = "\"$location\mysql\bin\mysqldump.exe\""; // Location of dump + $exe = DS."$location".DS."mysql".DS."bin".DS."mysqldump.exe".DS; // Location of dump } else { $termOrBash = "terminal window"; - $exe = "'$location/mysql/bin/mysqldump'"; // Location of dump + $exe = "'$location".DS."mysql".DS."bin".DS."mysqldump'"; // Location of dump } $date = date('Y-m-d-H-i-s'); if(isset($database['manual_export'])) { @@ -147,7 +147,7 @@ class migrateDatabase extends Step if(!$manual) { // Try to export database $sqlFile = $tmpFolder."/kt-backup-$date.sql"; $cmd = $exe.' -u"'.$dbAdminUser.'" -p"'.$dbAdminPass.'" --port="'.$port.'" '.$dbName.' > '.$sqlFile; - $response = $this->util->pexec($cmd); + $this->util->pexec($cmd); } if(file_exists($sqlFile)) { $fileContents = file_get_contents($sqlFile); diff --git a/setup/migrate/steps/migrateInstallation.php b/setup/migrate/steps/migrateInstallation.php index 07230bb..4a696e5 100644 --- a/setup/migrate/steps/migrateInstallation.php +++ b/setup/migrate/steps/migrateInstallation.php @@ -85,10 +85,6 @@ class migrateInstallation extends step private $ktSettings = array(); private $urlPaths = array(); - - private $knownWindowsLocations = array("C:\Program Files\ktdms"=>"C:\Program Files\ktdms\knowledgeTree\config\config-path","C:\Program Files x86\ktdms"=>"C:\Program Files x86\ktdms\knowledgeTree\config\config-path","C:\ktdms"=>"C:\ktdms\knowledgeTree\config\config-path"); - - private $knownUnixLocations = array("/opt/ktdms","/var/www/ktdms"); /** * Installation Settings @@ -132,12 +128,14 @@ class migrateInstallation extends step public function detectInstallation() { if(WINDOWS_OS) { - foreach ($this->knownWindowsLocations as $loc=>$configPath) { + $knownWindowsLocations = array("C:\Program Files\ktdms"=>"C:\Program Files\ktdms\knowledgeTree\config\config-path","C:\Program Files x86\ktdms"=>"C:\Program Files x86\ktdms\knowledgeTree\config\config-path","C:\ktdms"=>"C:\ktdms\knowledgeTree\config\config-path"); + foreach ($knownWindowsLocations as $loc=>$configPath) { if(file_exists($configPath)) $this->location = $loc; } } else { - foreach ($this->knownUnixLocations as $loc=>$configPath) { + $knownUnixLocations = array("/opt/ktdms"=>"/opt/ktdms/knowledgeTree/config/config-path","/var/www/ktdms"=>"/var/www/ktdms/knowledgeTree/config/config-path"); + foreach ($knownUnixLocations as $loc=>$configPath) { if(file_exists($configPath)) $this->location = $loc; } @@ -149,7 +147,8 @@ class migrateInstallation extends step $this->storeSilent(); return false; } else { - if($this->readVersion()) { + $this->foundVersion = $this->readVersion(); + if($this->foundVersion) { $this->checkVersion(); } $this->storeSilent(); @@ -162,16 +161,17 @@ class migrateInstallation extends step if($this->foundVersion < $this->supportedVersion) { $this->versionError = true; $this->error[] = "KT installation needs to be 3.6.1 or higher"; - } else { - return true; + return false; } + + return true; } public function readVersion() { $verFile = $this->location."/knowledgeTree/docs/VERSION.txt"; if(file_exists($verFile)) { - $this->foundVersion = file_get_contents($verFile); - return true; + $foundVersion = file_get_contents($verFile); + return $foundVersion; } else { $this->error[] = "KT installation version not found"; } @@ -222,11 +222,13 @@ class migrateInstallation extends step } else { $this->error[] = "Please Enter a Location"; } + + return false; } private function loadConfig($path) { - $ini = $this->util->loadInstallIni($path); - $dbSettings = $ini->getSection('db'); + $this->util->iniUtilities->load($path); + $dbSettings = $this->util->iniUtilities->getSection('db'); $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], 'dbName'=> $dbSettings['dbName'], 'dbUser'=> $dbSettings['dbUser'], @@ -235,14 +237,15 @@ class migrateInstallation extends step 'dbAdminUser'=> $dbSettings['dbAdminUser'], 'dbAdminPass'=> $dbSettings['dbAdminPass'], ); - $ktSettings = $ini->getSection('KnowledgeTree'); + $ktSettings = $this->util->iniUtilities->getSection('KnowledgeTree'); $froot = $ktSettings['fileSystemRoot']; +// print_r($ktSettings); +// die; if ($froot == 'default') { $froot = $this->location; } $this->ktSettings = array('fileSystemRoot'=> $froot, ); - $urlPaths = $ini->getSection('urls'); $varDir = $froot.DS.'var'; $this->urlPaths = array(array('name'=> 'Var Directory', 'path'=> $varDir), array('name'=> 'Log Directory', 'path'=> $varDir.DS.'log'), diff --git a/setup/migrate/steps/migrateServices.php b/setup/migrate/steps/migrateServices.php index b0bc18e..098a58c 100644 --- a/setup/migrate/steps/migrateServices.php +++ b/setup/migrate/steps/migrateServices.php @@ -127,7 +127,6 @@ class migrateServices extends Step public function doStep() { $this->temp_variables = array("step_name"=>"services", "silent"=>$this->silent); - $this->installServices = $this->util->loadInstallUtil(); // Use installer utility class $this->services = $this->util->loadInstallServices(); // Use installer services class $this->storeSilent(); if(!$this->inStep("services")) { @@ -202,11 +201,11 @@ class migrateServices extends Step */ public function unixStop() { $cmd = $this->conf['location']."/dmsctl.sh stop lucene"; - $res = $this->util->pexec($cmd); + $this->util->pexec($cmd); $cmd = $this->conf['location']."/dmsctl.sh stop scheduler"; - $res = $this->util->pexec($cmd); + $this->util->pexec($cmd); $cmd = $this->conf['location']."/dmsctl.sh stop soffice"; - $res = $this->util->pexec($cmd); + $this->util->pexec($cmd); } /** @@ -215,11 +214,11 @@ class migrateServices extends Step */ public function windowsStop() { $cmd = "sc delete KTLucene"; - $res = $this->util->pexec($cmd); + $this->util->pexec($cmd); $cmd = "sc delete KTScheduler"; - $res = $this->util->pexec($cmd); + $this->util->pexec($cmd); $cmd = "sc delete KTOpenoffice"; - $res = $this->util->pexec($cmd); + $this->util->pexec($cmd); } /** @@ -233,7 +232,7 @@ class migrateServices extends Step $serv->load(); $sStatus = $serv->status(); if($sStatus != '') { - $res = $serv->uninstall(); + $serv->uninstall(); } } } diff --git a/setup/migrate/templates/error.tpl b/setup/migrate/templates/error.tpl index 5a93982..958cee8 100644 --- a/setup/migrate/templates/error.tpl +++ b/setup/migrate/templates/error.tpl @@ -1,11 +1,11 @@ + KnowledgeTree Installer - @@ -14,7 +14,7 @@
3.7 - Commercial Edition + Community Edition
diff --git a/setup/migrate/templates/wizard.tpl b/setup/migrate/templates/wizard.tpl index b39cde5..4309d2e 100644 --- a/setup/migrate/templates/wizard.tpl +++ b/setup/migrate/templates/wizard.tpl @@ -1,6 +1,7 @@ + KnowledgeTree Installer js('jquery.js'); ?> js('jquery.form.js'); ?> 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 new file mode 100644 index 0000000..4ed2cd5 --- /dev/null +++ b/setup/upgrade/lib/UpgradeItems.inc.php @@ -0,0 +1,510 @@ +. + * + * 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. + * Contributor( s): ______________________________________ + * + */ + +// {{{ Format of the descriptor +/** + * Format of the descriptor + * + * type*version*phase*simple description for uniqueness + * + * type is: sql, function, subupgrade, upgrade + * version is: 1.2.4, 2.0.0rc5 + * phase is: 0, 1, 0pre. Phase is _only_ evaluated by describeUpgrades. + * description is: anything, unique in terms of version and type. + */ +// }}} + +//require_once(KT_LIB_DIR . '/upgrades/UpgradeFunctions.inc.php'); +require_once('sqlfile.inc.php'); +require_once('datetime.inc'); + +// {{{ Upgrade_Already_Applied +class Upgrade_Already_Applied { //extends PEAR_Error { + function Upgrade_Already_Applied($oUpgradeItem) { + $this->oUpgradeItem = $oUpgradeItem; + } +} +// }}} + +class UpgradeItem extends InstallUtil { + var $type = ""; + var $name; + var $version; + var $description; + var $phase; + var $priority = 0; + var $parent; + var $date; + var $result; + + function UpgradeItem($name, $version, $description = null, $phase = 0, $priority = 0) { + $this->name = $name; + $this->version = $version; + if (is_null($description)) { + $description = $this->type . " upgrade to version " . $version . " phase " . $phase; + } + $this->description = $description; + $this->phase = $phase; + $this->priority = $priority; + parent::__construct(); +// print_r($this); +// die; + } + + function setParent($parent) { + $this->parent = $parent; + } + function setDate($date) { + $this->date = $date; + } + + function getDescriptor() { + return join("*", array($this->type, $this->version, $this->phase, $this->name)); + } + + function getDescription() { + return $this->description; + } + + function getVersion() { + return $this->version; + } + + function getPhase() { + return $this->phase; + } + + function getPriority() { + return $this->priority; + } + + function getType() { + return $this->type; + } + + 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(); + 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); +// 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, true, true); + if($res) { + return true; + } + return false; + } + + function isAlreadyApplied() { + if (!$this->_upgradeTableInstalled()) { + return false; + } + $query = "SELECT id FROM upgrades WHERE descriptor = '".$this->getDescriptor()."' AND result = 1"; + $res = $this->runDBQuery($query, true, false); + + if(!$res) { + return true; + } + return false; + } + + function performUpgrade($force = false) { + $res = $this->isAlreadyApplied(); + if ($res === true) { + if ($force !== true) { + // PHP5: Exception + return new Upgrade_Already_Applied($this); + } + } +// if (!$res) { +// $this->error[] = 'An Error Has Occured'; +// } +// $oCache =& KTCache::getSingleton(); +// $save = $oCache->bEnabled; +// $oCache->bEnabled = false; + $res = $this->_performUpgrade(); +// $oCache->bEnabled = $save; + if (!$res) { + $this->_recordUpgrade(false); + $this->error[] = $this->dbUtilities->getErrors(); + return false; + } + $res = $this->_recordUpgrade(true); + if (!$res) { + $this->error[] = 'An Error Has Occured 1'; + return false; + } + return true; + } + + function _performUpgrade() { + $this->error[] = 'Unimplemented'; + return false; + } + + function _recordUpgrade($result) { + if (is_null($this->date)) { + $this->date = getCurrentDateTime(); + } + if ($this->parent) { + $parentid = $this->parent->getDescriptor(); + } else { + $parentid = null; + } + $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 + function getAllUpgrades() { + return array(); + } + + +} + +class SQLUpgradeItem extends UpgradeItem { + function SQLUpgradeItem($path, $version = null, $description = null, $phase = null, $priority = null) { + $this->type = "sql"; + $this->priority = 0; + $details = $this->_getDetailsFromFileName($path); + if (is_null($version)) { + $version = $details[1]; + } + if (is_null($description)) { + $description = $details[2]; + } + if (is_null($phase)) { + $phase = $details[3]; + } + if (is_null($priority)) { + $priority = isset($details[4]) ? $details[4] : 0; + } + $this->UpgradeItem($path, $version, $description, $phase, $priority); + } + + /** + * Describe the SQL scripts that will be used to upgrade KnowledgeTree + * + * Return an array of arrays with two components: a string identifier + * that uniquely describes the step to be taken and a string which is an + * HTML-formatted description of the step to be taken. These will be + * returned in any order - describeUpgrade performs the ordering. + * + * @param string Original version (e.g., "1.2.4") + * @param string Current version (e.g., "2.0.2") + * + * @return array Array of SQLUpgradeItem describing steps to be taken + * + * STATIC + */ + public static function getUpgrades($origVersion, $currVersion) { +// global $default; + +// $sqlupgradedir = KT_DIR . '/sql/' . $default->dbType . '/upgrade/'; + $dbType = 'mysql'; + $sqlupgradedir = KT_DIR . 'sql/' . $dbType . '/upgrade/'; + $ret = array(); + + if (!is_dir($sqlupgradedir)) { +// return PEAR::raiseError("SQL Upgrade directory ($sqlupgradedir) not accessible"); + } + if (!($dh = opendir($sqlupgradedir))) { +// return PEAR::raiseError("SQL Upgrade directory ($sqlupgradedir) not accessible"); + } + + while (($file = readdir($dh)) !== false) { + // Each entry can be a file or a directory + // + // A file is legacy before the upgrade system was created, but + // will be supported anyway. + // + // A directory is the end-result version: so, 2.0.5 contains + // every script that differentiates it from a previous version, + // say, 2.0.5rc1 or 2.0.4. + // + if (in_array($file, array('.', '..', 'CVS'))) { + continue; + } + $fullpath = $sqlupgradedir . $file; + if (is_file($fullpath)) { + // Legacy file support, will be in form of + // 1.2.4-to-2.0.0.sql. + $details = SQLUpgradeItem::_getDetailsFromFileName($file); + if ($details) { + if (!gte_version($details[0], $origVersion)) { + continue; + } + if (!lte_version($details[1], $currVersion)) { + continue; + } + //print "Will run $file\n"; +// print_r($this->util->dbUtilities); +// die; + $ret[] = new SQLUpgradeItem($file); + } + } + if (is_dir($fullpath)) { + $subdir = $file; + if (!($subdh = opendir($fullpath))) { + continue; + } + while (($file = readdir($subdh)) !== false) { + $relpath = $subdir . '/' . $file; + $details = SQLUpgradeItem::_getDetailsFromFileName($relpath); + if ($details) { + if (!gte_version($details[0], $origVersion)) { + continue; + } + if (!lte_version($details[1], $currVersion)) { + continue; + } + //print "Will run $file\n"; +// print_r(SQLUpgradeItem::); +// die; +// new InstallUtil(); + $ret[] = new SQLUpgradeItem($relpath); + } + } + } + } + closedir($dh); + return $ret; + } + + public static function _getDetailsFromFileName($path) { + // Old format (pre 2.0.6) + $matched = preg_match('#^([\d.]*)-to-([\d.]*).sql$#', $path, $matches); + if ($matched != 0) { + $fromVersion = $matches[1]; + $toVersion = $matches[2]; + $description = "Database upgrade from version $fromVersion to $toVersion"; + $phase = 0; + return array($fromVersion, $toVersion, $description, $phase); + } + $matched = preg_match('#^([\d.]*)/(?:(\d*)-)?(.*)\.sql$#', $path, $matches); + //$matched = preg_match('#^([\d.]*)/(?:(\d*)-)?(.*):(?:(\d*))\.sql$#', $path, $matches); + if ($matched != 0) { + $fromVersion = $matches[1]; + $toVersion = $matches[1]; + $in = array('_'); + $out = array(' '); + $phase = (int)$matches[2]; + + //$priority = (int)$matches[4]; + $priority = 0; + $iPriority = preg_match('#^(.*)-(\d*)$#', $matches[3], $priorities); + if($iPriority != 0){ + $priority = $priorities[2]; + $matches[3] = $priorities[1]; + } + + $description = "Database upgrade to version $toVersion: " . ucfirst(str_replace($in, $out, $matches[3])); + return array($fromVersion, $toVersion, $description, $phase, $priority); + } + // XXX: handle new format + return null; + } + + function _performUpgrade() { + $dbType = 'mysql'; + $sqlupgradedir = KT_DIR . 'sql/' . $dbType . '/upgrade/'; + $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name); + return $this->dbUtilities->runQueries($queries); + } + + +} + +class KTRebuildPermissionObserver { + function start() { + $this->lastBeat = time(); + } + function receiveMessage() { + $now = time(); + if ($this->lastBeat + 15 < $now) { + print ""; + ob_flush(); + flush(); + } + } + function end() { + } +} + +class RecordUpgradeItem extends UpgradeItem { + function RecordUpgradeItem ($version, $oldversion = null) { + $this->type = "upgrade"; + if (is_null($oldversion)) { + $this->description = "Upgrade to version $version"; + } else { + $this->description = "Upgrade from version $oldversion to $version"; + } + $this->phase = 99; + $this->version = $version; + $this->name = 'upgrade' . $version; + } + + function _performUpgrade() { +// $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); + + set_time_limit(0); + ignore_user_abort(true); + +// KTPermissionUtil::rebuildPermissionLookups(true); +// $po->end(); + + $versionFile=KT_DIR . '/docs/VERSION-NAME.txt'; + $fp = fopen($versionFile,'rt'); + $systemVersion = fread($fp, filesize($versionFile)); + fclose($fp); + + $query = "UPDATE system_settings SET value = '$systemVersion' WHERE name = 'knowledgetreeVersion'"; + $this->runDBQuery($query); + $query = "UPDATE system_settings SET value = '{$this->version}' WHERE name = 'databaseVersion'"; + $result = $this->runDBQuery($query); + return $result; + } + + function _deleteSmartyFiles() { + $oConfig =& KTConfig::getSingleton(); + $dir = sprintf('%s/%s', $oConfig->get('urls/varDirectory'), 'tmp'); + + $dh = @opendir($dir); + if (empty($dh)) { + return; + } + $aFiles = array(); + while (false !== ($sFilename = readdir($dh))) { + if (substr($sFilename, -10) == "smarty.inc") { + $aFiles[] = sprintf('%s/%s', $dir, $sFilename); + } + if (substr($sFilename, -10) == "smarty.php") { + $aFiles[] = sprintf('%s/%s', $dir, $sFilename); + } + } + foreach ($aFiles as $sFile) { + @unlink($sFile); + } + } + + + function _deleteProxyFiles() { + $oKTConfig =& KTConfig::getSingleton(); + + + // from ktentityutil::_proxyCreate + $sDirectory = $oKTConfig->get('cache/proxyCacheDirectory'); + + if (!file_exists($sDirectory)) { + return; + } + $sRunningUser = KTUtil::running_user(); + if ($sRunningUser) { + $sDirectory = sprintf("%s/%s", $sDirectory, $sRunningUser); + } + if (!file_exists($sDirectory)) { + return ; + } + + $dh = @opendir($sDirectory); + if (empty($dh)) { + return; + } + $aFiles = array(); + while (false !== ($sFilename = readdir($dh))) { + + if (substr($sFilename, -8) == ".inc.php") { + $aFiles[] = sprintf('%s/%s', $sDirectory, $sFilename); + } + } + + foreach ($aFiles as $sFile) { + @unlink($sFile); + } + } +} + +?> diff --git a/setup/upgrade/lib/datetime.inc b/setup/upgrade/lib/datetime.inc new file mode 100644 index 0000000..6bcffd2 --- /dev/null +++ b/setup/upgrade/lib/datetime.inc @@ -0,0 +1,58 @@ +. + * + * 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. + * Contributor( s): ______________________________________ + */ + +/** + * Returns the current date time + * + * @return string the current date time (Y-m-d H:i:s) + */ +function getCurrentDateTime() { + return date("Y-m-d H:i:s", time()); +} + +/** + * Returns the specified date time, formatted as Y-m-d H:i:s + * + * @param int the date time to format + * @return string the formatted date time + */ +function formatDateTime($dateTime) { + return date("Y-m-d H:i:s", $dateTime); +} +?> diff --git a/setup/upgrade/lib/sqlfile.inc.php b/setup/upgrade/lib/sqlfile.inc.php new file mode 100644 index 0000000..9fb3ebc --- /dev/null +++ b/setup/upgrade/lib/sqlfile.inc.php @@ -0,0 +1,141 @@ +. + * + * 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. + * Contributor( s): ______________________________________ + * + */ + +class SQLFile { + function sqlFromFile($path) { + return SQLFile::splitSQL(file_get_contents($path)); + } + + function splitSQL($sql) { + $instring = false; + $i = 0; + $remaining = $sql; + $query = ""; + $aQueries = array(); + + $strlen = strlen($sql); + + for ($i = 0; $i < $strlen; $i++) { + $c = $remaining[$i]; + if ($c === ";") { + $query .= substr($remaining, 0, $i + 1); + $aQueries[] = $query; + $query = ""; + $remaining = trim(substr($remaining, $i + 1)); + $i = 0; + $strlen = strlen($remaining); + continue; + } + if ($c === "`") { + $next = strpos($remaining, "`", $i); + if ($next === false) { + $query .= $remaining; + $aQueries[] = $query; + return $aQueries; + } + $query .= substr($remaining, 0, $next); + $remaining = substr($remaining, $next); + $i = 0; + $strlen = strlen($remaining); + continue; + } + if (($c === "'") || ($c === '"')) { + $stringchar = $c; + $notfound = true; + + while ($notfound) { + $next = strpos($remaining, $stringchar, $i + 1); + if ($next === false) { + $query .= $remaining; + $aQueries[] = $query; + return $aQueries; + } + $i = $next + 1; + $quotes = true; + $b = 1; + while ($remaining[$next - $b] === "\\") { + $quotes = !$quotes; + $b++; + } + if ($quotes) { + $notfound = false; + } + } + $query .= substr($remaining, 0, $next); + $remaining = substr($remaining, $next); + $i = 0; + $strlen = strlen($remaining); + continue; + } + + $nextdelim = SQLFile::_nextDelim($remaining); + if ($nextdelim === false) { + $query .= $remaining; + $aQueries[] = $query; + return $aQueries; + } + // $query .= substr($remaining, 0, $nextdelim); + } + return $aQueries; + } + + function _nextDelim($string) { + $q = strpos($string, "'"); + $d = strpos($string, '"'); + $b = strpos($string, "`"); + $s = strpos($string, ";"); + + $min = false; + foreach (array($q, $d, $b, $s) as $c) { + if ($min === false) { + $min = $c; + continue; + } + if ($c === false) { + continue; + } + if ($c < $min) { + $min = $c; + continue; + } + } + return $min; + } +} + +?> diff --git a/setup/upgrade/lib/upgrade.inc.php b/setup/upgrade/lib/upgrade.inc.php new file mode 100644 index 0000000..c3dcd18 --- /dev/null +++ b/setup/upgrade/lib/upgrade.inc.php @@ -0,0 +1,217 @@ +. + * + * 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. + * Contributor( s): ______________________________________ + */ + +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(); + +// {{{ Format of the descriptor +/** + * Format of the descriptor + * + * type*version*phase*simple description for uniqueness + * + * type is: sql, function, subupgrade, upgrade + * version is: 1.2.4, 2.0.0rc5 + * phase is: 0, 1, 0pre. Phase is _only_ evaluated by describeUpgrades. + * description is: anything, unique in terms of version and type. + */ +// }}} + +// {{{ describeUpgrade +/** + * Describe the upgrade path between two versions of KnowledgeTree. + * + * @param string Original version (e.g., "1.2.4") + * @param string Current version (e.g., "2.0.2") + * + * @return array Array of UpgradeItem describing steps to be taken + */ +function &describeUpgrade ($origVersion, $currVersion) { + // How to figure out what upgrades to do: + // + // 1. Get all SQL upgrades >= origVersion and <= currVersion + // 2. Categorise each into version they upgrade to + // 3. Sort each version subgroup into correct order + // 5. Add "recordSubUpgrade" for each version there. + // 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); + $scount = count($ssteps); + for ($i = 0; $i < $scount; $i++) { + $steps[] =& $ssteps[$i]; + } + } + $upgradestep = new RecordUpgradeItem($currVersion, $origVersion); + $steps[] =& $upgradestep; + $stepcount = count($steps); + for ($i = 0; $i < $stepcount; $i++) { + $step =& $steps[$i]; + $step->setParent($upgradestep); + } + usort($steps, 'step_sort_func'); + + return $steps; +} +// }}} + +// {{{ step_sort_func +function step_sort_func ($obj1, $obj2) { + // Ugly hack to ensure that upgrade table is made first... + if ($obj1->name === "2.0.6/create_upgrade_table.sql") { + return -1; + } + if ($obj2->name === "2.0.6/create_upgrade_table.sql") { + return 1; + } + + // Priority upgrades run first + if ($obj1->getPriority() < $obj2->getPriority()) { + return 1; + } + if ($obj1->getPriority() > $obj2->getPriority()) { + return -1; + } + + // early version run first + $res = compare_version($obj1->getVersion(), $obj2->getVersion()); + if ($res !== 0) { + return $res; + } + // Order by phase + if ($obj1->getPhase() > $obj2->getPhase()) { + return 1; + } + if ($obj1->getPhase() < $obj2->getPhase()) { + return -1; + } + // Order by name + if ($obj1->name < $obj2->name) { + return -1; + } + if ($obj1->name > $obj2->name) { + return 1; + } + return 0; +} +// }}} + +// {{{ compare_version +/** + * Compares two version numbers and returns a value based on this comparison + * + * Using standard software version rules, such as 2.0.5rc1 comes before + * 2.0.5, and 2.0.5rc1 comes after 2.0.5alpha1, compare two version + * numbers, and determine which is the higher. + * + * XXX: Actually, just does $version1 < $version2 + * + * @param string First version number + * @param string Second version number + * + * @return int -1, 0, 1 + */ +function compare_version($version1, $version2) { + // XXX: Version comparisons should be better. + if ($version1 < $version2) { + return -1; + } + if ($version1 > $version2) { + return 1; + } + return 0; +} +// }}} + +// {{{ lte_version +/** + * Quick-hand for checking if a version number is lower-than-or-equal-to + */ +function lte_version($version1, $version2) { + if (in_array(compare_version($version1, $version2), array(-1, 0))) { + return true; + } + return false; +} +// }} + +// {{ gte_version +/** + * Quick-hand for checking if a version number is greater-than-or-equal-to + */ +function gte_version($version1, $version2) { + if (in_array(compare_version($version1, $version2), array(0, 1))) { + 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 e762275..2cf5254 100644 --- a/setup/upgrade/step.php +++ b/setup/upgrade/step.php @@ -110,7 +110,6 @@ class Step public function __construct() { $this->util = new UpgradeUtil(); - $this->dbhandler = $this->util->loadInstallDBUtil(); } /** 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..fa91eff 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,11 @@ class upgradeBackup extends Step { // TODO error checking (done in backupDone at the moment) $this->backupDone(); } - $this->storeSilent();// Set silent mode variables +// $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 +119,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 +144,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 +186,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 +246,43 @@ class upgradeBackup extends Step { $this->temp_variables['dir'] = $dir; $this->temp_variables['display'] = $stmt['display']; } + + // TODO this function needs to be refactored out into the parent Step class?? + 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'], + // dbSocket doesn't exist as far as I can find, where was it coming from? + //'dbSocket'=> $dbSettings['dbSocket'], + '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(); + } + + // TODO this function needs to be refactored out into the parent Step class + public 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; + } } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeComplete.php b/setup/upgrade/steps/upgradeComplete.php index e8e6857..11f48d8 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'; } @@ -63,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 8987695..ef5d3fd 100644 --- a/setup/upgrade/steps/upgradeDatabase.php +++ b/setup/upgrade/steps/upgradeDatabase.php @@ -40,10 +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'); -//require_once(KT_LIB_DIR . '/upgrades/upgrade.inc.php'); +define('KT_DIR', SYSTEM_DIR); +define('KT_LIB_DIR', SYSTEM_DIR.'lib'); +require_once(WIZARD_LIB . 'upgrade.inc.php'); class upgradeDatabase extends Step { @@ -92,10 +91,12 @@ class upgradeDatabase extends Step */ public $storeInSession = true; + public $sysVersion = ''; 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()); - - if($this->dbSettings['dbPort'] == '') { - $con = $this->dbhandler->load($this->dbSettings['dbHost'], $this->dbSettings['dbUser'], - $this->dbSettings['dbPass'], $this->dbSettings['dbName']); - } else { - $con = $this->dbhandler->load($this->dbSettings['dbHost'].":".$this->dbSettings['dbPort'], $this->dbSettings['dbUser'], - $this->dbSettings['dbPass'], $this->dbSettings['dbName']); - } - + $this->readConfig(); + $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'; @@ -173,20 +166,20 @@ class upgradeDatabase extends Step } private function generateUpgradeTable() { - global $default; + $this->sysVersion = $this->readVersion(); + $this->temp_variables['systemVersion'] = $this->sysVersion; + $dconf = $this->util->iniUtilities->getSection('db'); + $this->util->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); - $this->temp_variables['systemVersion'] = $default->systemVersion; - $query = sprintf('SELECT value FROM %s WHERE name = "databaseVersion"', $default->system_settings_table); - - $result = $this->dbhandler->query($query); + $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) { - $lastVersionObj = $this->dbhandler->fetchNextObject($result); - $lastVersion = $lastVersionObj->value; + $lastVersion = $assArr[0]['value']; } - $currentVersion = $default->systemVersion; - + $currentVersion = $this->sysVersion; + $upgrades = describeUpgrade($lastVersion, $currentVersion); - $ret = "\n"; $ret .= "\n"; $i=0; @@ -202,6 +195,18 @@ class upgradeDatabase extends Step return $ret; } + public 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; + } + /** * Stores varibles used by template * @@ -241,18 +246,34 @@ class upgradeDatabase extends Step } } - private function readConfig($path) { - $ini = $this->util->loadInstallIni($path); - $dbSettings = $ini->getSection('db'); - $this->dbSettings = array('dbHost'=> $dbSettings['dbHost'], + 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->temp_variables['dbSettings'] = $this->dbSettings; + ); + $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() @@ -267,26 +288,17 @@ 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 - upgrade your KnowledgeTree installation to ' . $default->systemVersion . ''; + upgrade your KnowledgeTree installation to ' . $this->sysVersion . ''; $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

@@ -300,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; } @@ -315,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; - // 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); } @@ -358,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"; @@ -383,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; } } @@ -400,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'; @@ -414,6 +442,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..b6fedd6 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,7 +94,7 @@ class upgradeRestore extends Step { $this->restoreDatabase(); } - $this->storeSilent();// Set silent mode variables +// $this->storeSilent();// Set silent mode variables return true; } @@ -101,19 +103,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 +214,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 +222,44 @@ class upgradeRestore extends Step { $this->temp_variables['availableBackups'] = true; $this->temp_variables['selected'] = true; } + + // TODO this function needs to be refactored out into the parent Step class?? + 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'], + // dbSocket doesn't exist as far as I can find, where was it coming from? + //'dbSocket'=> $dbSettings['dbSocket'], + '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(); + } + + // TODO this function needs to be refactored out into the parent Step class + public 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; + } } ?> \ No newline at end of file diff --git a/setup/upgrade/steps/upgradeWelcome.php b/setup/upgrade/steps/upgradeWelcome.php index c3df258..1c232df 100644 --- a/setup/upgrade/steps/upgradeWelcome.php +++ b/setup/upgrade/steps/upgradeWelcome.php @@ -42,10 +42,11 @@ class upgradeWelcome extends step { - protected $silent = false; + 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,32 +82,46 @@ class upgradeWelcome extends step { private function checkPassword($username, $password) { $dconf = $this->getDataFromPackage('installers', 'database'); // Use info from install if($dconf) { - $this->dbhandler->load($dconf['dhost'], $dconf['duname'], $dconf['dpassword'], $dconf['dname']); + $this->util->dbUtilities->load($dconf['dhost'], $dbconf['dport'], $dconf['duname'], $dconf['dpassword'], $dconf['dname']); } else { - require_once("../wizard/iniUtilities.php"); // ini to read the ini content require_once("../wizard/steps/configuration.php"); // configuration to read the ini path $wizConfigHandler = new configuration(); $configPath = $wizConfigHandler->readConfigPathIni(); - $ini = new iniUtilities($configPath); - $dconf = $ini->getSection('db'); - $this->dbhandler->load($dconf['dbHost'], $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); + $this->util->iniUtilities->load($configPath); + $dconf = $this->util->iniUtilities->getSection('db'); + $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); + $ass = $this->util->dbUtilities->fetchAssoc($res); + if($ass[0]['match_count'] == 1) + return true; } - $sQuery = "SELECT count(*) AS match_count FROM users WHERE username = '$username' AND password = '".md5($password)."'"; - $res = $this->dbhandler->query($sQuery); - $ass = $this->dbhandler->fetchAssoc($res); - if(isset($ass[0]['match_count'])) { - if($ass[0]['match_count']) - return true; - } + $this->error[] = 'Could Not Authenticate User'; return false; - } + } + public function getErrors() { return $this->error; } + /** + * Returns step variables + * + * @author KnowledgeTree Team + * @param none + * @access public + * @return array + */ + public function getStepVars() + { + return $this->temp_variables; + } + public function storeSilent() { + + } } ?> \ No newline at end of file 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:

- +

+

Database Upgrade Completed

@@ -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/templates/error.tpl b/setup/upgrade/templates/error.tpl index 5102838..9c6a997 100644 --- a/setup/upgrade/templates/error.tpl +++ b/setup/upgrade/templates/error.tpl @@ -1,6 +1,7 @@ + KnowledgeTree Installer @@ -14,7 +15,7 @@
3.7 - Commercial Edition + Community Edition
diff --git a/setup/upgrade/templates/loading.tpl b/setup/upgrade/templates/loading.tpl index 35f4f9d..ba837db 100644 --- a/setup/upgrade/templates/loading.tpl +++ b/setup/upgrade/templates/loading.tpl @@ -1,5 +1,5 @@ diff --git a/setup/upgrade/templates/progress.tpl b/setup/upgrade/templates/progress.tpl index adc2bf5..7d53178 100644 --- a/setup/upgrade/templates/progress.tpl +++ b/setup/upgrade/templates/progress.tpl @@ -1,6 +1,7 @@ + KnowledgeTree Upgrade Wizard @@ -14,7 +15,7 @@
3.7 - Commercial Edition + Community Edition
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/templates/wizard.tpl b/setup/upgrade/templates/wizard.tpl index 823d3e7..723d255 100644 --- a/setup/upgrade/templates/wizard.tpl +++ b/setup/upgrade/templates/wizard.tpl @@ -1,6 +1,7 @@ + KnowledgeTree Upgrader js('jquery.js'); ?> js('jquery.form.js'); ?> 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 1816df1..24dbfab 100644 --- a/setup/upgrade/upgradeUtil.php +++ b/setup/upgrade/upgradeUtil.php @@ -40,10 +40,9 @@ * @version Version 0.1 */ -//require_once('../../config/dmsDefaults.php'); require_once("../wizard/installUtil.php"); -class UpgradeUtil extends InstallUtil { +class UpgradeUtil extends InstallUtil { /** * Check if system needs to be upgraded * @@ -75,16 +74,6 @@ class UpgradeUtil extends InstallUtil { echo $contents; } - public function loadInstallIni($path) { - require_once("../wizard/iniUtilities.php"); - return new iniUtilities($path); - } - - public function loadInstallDBUtil() { - require_once("../wizard/dbUtilities.php"); - return new dbUtilities(); - } - /** * Function to send output to the browser prior to normal dynamic loading of a template after code execution * @@ -127,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(); @@ -163,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; } @@ -180,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'; } @@ -192,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) { @@ -213,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/dbUtil.php b/setup/wizard/dbUtil.php deleted file mode 100644 index 55c3ed7..0000000 --- a/setup/wizard/dbUtil.php +++ /dev/null @@ -1,256 +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 Installer -* @version Version 0.1 -*/ -class dbUtil { - /** - * Host - * - * @author KnowledgeTree Team - * @access protected - * @var string - */ - protected $dbhost = ''; - - /** - * Host - * - * @author KnowledgeTree Team - * @access protected - * @var string - */ - protected $dbname = ''; - - /** - * Host - * - * @author KnowledgeTree Team - * @access protected - * @var string - */ - protected $dbuname = ''; - - /** - * Host - * - * @author KnowledgeTree Team - * @access protected - * @var string - */ - protected $dbpassword = ''; - - /** - * Host - * - * @author KnowledgeTree Team - * @access protected - * @var object mysql connection - */ - protected $dbconnection = ''; - - /** - * Any errors encountered - * - * @author KnowledgeTree Team - * @access protected - * @var array - */ - protected $error = array(); - - /** - * Constructs database connection object - * - * @author KnowledgeTree Team - * @access public - */ - public function __construct() { - - } - - public function load($dhost = 'localhost', $duname, $dpassword, $dbname) { - $this->dbhost = $dhost; - $this->dbuname = $duname; - $this->dbpassword = $dpassword; - $this->dbconnection = @mysql_connect($dhost, $duname, $dpassword); - if(!$this->dbconnection) { - $this->error[] = @mysql_error(); - } - $this->dbname = $dbname; - } - - public function getDatabaseLink() { - return $this->dbconnection; - } - /** - * Choose a database to use - * - * @param string $dbname name of the database - * @access public - * @return boolean - */ - public function useDb() { - if(@mysql_select_db($this->dbname, $this->dbconnection)) - return true; - else { - $this->error[] = @mysql_error($this->dbconnection); - return false; - } - } - - public function setDb($dbname) { - $this->dbname = $dbname; - } - - /** - * Query the database. - * - * @param $query the sql query. - * @access public - * @return object The result of the query. - */ - public function query($query) { - $this->useDb(); - $result = mysql_query($query, $this->dbconnection); - if($result) { - return $result; - } else { - $this->error[] = @mysql_error($this->dbconnection); - return false; - } - } - - /** - * Do the same as query. - * - * @param $query the sql query. - * @access public - * @return boolean - */ - public function execute($query) { - $this->useDb(); - $result = @mysql_query($query, $this->dbconnection); - if(!$result) { - $this->error[] = @mysql_error($this->dbconnection); - } - - return $result; - } - - /** - * Convenience method for mysql_fetch_object(). - * - * @param $result The resource returned by query(). - * @access public - * @return object An object representing a data row. - */ - public function fetchNextObject($result = NULL) { - if ($result == NULL || @mysql_num_rows($result) < 1) - return NULL; - else - return @mysql_fetch_object($result); - } - - /** - * Convenience method for mysql_fetch_assoc(). - * - * @param $result The resource returned by query(). - * @access public - * @return array Returns an associative array of strings. - */ - public function fetchAssoc($result = NULL) { - $r = array(); - if ($result == NULL || @mysql_num_rows($result) < 1) - return NULL; - else { - while(($r[] = mysql_fetch_assoc($result)) || array_pop($r)); - return $r; - } - } - - /** - * Close the connection with the database server. - * - * @param none. - * @access public - * @return void. - */ - public function close() { - @mysql_close($this->dbconnection); - } - - /** - * Get database errors. - * - * @param none. - * @access public - * @return array. - */ - public function getErrors() { - return $this->error; - } - - public function clearErrors() { - return $this->error = array(); - } - - /** - * Fetches the last generated error - - * @return string - */ - function getLastError() { - return end($this->error); - } - - /** - * Start a database transaction - */ - public function startTransaction() { - $this->query("START TRANSACTION"); - } - - /** - * Roll back a database transaction - */ - public function rollback() { - $this->query("ROLLBACK"); - } -} -?> \ No newline at end of file diff --git a/setup/wizard/dbUtilities.php b/setup/wizard/dbUtilities.php index ff3af9f..39f6876 100644 --- a/setup/wizard/dbUtilities.php +++ b/setup/wizard/dbUtilities.php @@ -101,20 +101,32 @@ class dbUtilities { * @access public */ public function __construct() { - + } - public function load($dhost = 'localhost', $duname, $dpassword, $dbname) { - $this->dbhost = $dhost; - $this->dbuname = $duname; - $this->dbpassword = $dpassword; - $this->dbconnection = @mysql_connect($dhost, $duname, $dpassword); - if(!$this->dbconnection) { - $this->error[] = @mysql_error(); + public function load($dhost = 'localhost', $dport = 'default', $duname, $dpassword, $dbname) { + if(!$this->isConnected($dhost, $duname, $dpassword, $dbname)) { + if($dport == 'default' || $dport == '') + $dport = '3306'; + $this->dbhost = $dhost.":".$dport; + $this->dbuname = $duname; + $this->dbpassword = $dpassword; + $this->dbconnection = @mysql_connect($dhost, $duname, $dpassword); + $this->dbname = $dbname; } - $this->dbname = $dbname; } + public function isConnected($dhost = 'localhost', $duname, $dpassword, $dbname) { + $current = array($this->dbhost, $this->dbuname, $this->dbpassword, $this->dbname); + $new = array($dhost, $duname, $dpassword, $dbname); + $diff = array_diff($new, $current); + if(count($diff) == 0) { + if($this->getDatabaseLink()) // Make sure theres a link + return true; // Already connected + } + return false; // Reconnect + } + public function getDatabaseLink() { return $this->dbconnection; } @@ -223,6 +235,9 @@ class dbUtilities { * @return array. */ public function getErrors() { + if(!$this->dbconnection) { + $this->error[] = @mysql_error(); + } return $this->error; } @@ -252,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/ini.php b/setup/wizard/ini.php deleted file mode 100644 index 3a41f0c..0000000 --- a/setup/wizard/ini.php +++ /dev/null @@ -1,223 +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. - * Contributor( s): ______________________________________ - * - */ - -class Ini { - - private $cleanArray = array(); - private $iniFile = ''; - private $lineNum = 0; - private $exists = ''; - - function Ini($iniFile = '../../config.ini') { - $this->iniFile = $iniFile; - $this->backupIni($iniFile); - $this->read($iniFile); - } - - /** - * Create a backup with the date as an extension in the same location as the original config.ini - * - * @param string $iniFile - * @return boolean - */ - function backupIni($iniFile) - { - $content = file_get_contents($iniFile); - if ($content === false) - { - return false; - } - $date = date('YmdHis'); - - $backupFile = $iniFile . '.' .$date; - if (is_writeable($backupFile)) { - file_put_contents($backupFile, $content); - } - } - - function read($iniFile) { - - $iniArray = file($iniFile); - $section = ''; - foreach($iniArray as $iniLine) { - $this->lineNum++; - $iniLine = trim($iniLine); - $firstChar = substr($iniLine, 0, 1); - if($firstChar == ';') { - if($section == ''){ - $this->cleanArray['_comment_'.$this->lineNum]=$iniLine; - }else { - $this->cleanArray[$section]['_comment_'.$this->lineNum]=$iniLine; - } - continue; - } - if($iniLine == '') { - if($section == ''){ - $this->cleanArray['_blankline_'.$this->lineNum]=''; - }else { - $this->cleanArray[$section]['_blankline_'.$this->lineNum]=''; - } - continue; - } - - if ($firstChar == '[' && substr($iniLine, -1, 1) == ']') { - $section = substr($iniLine, 1, -1); - $this->sections[] = $section; - } else { - $equalsPos = strpos($iniLine, '='); - if ($equalsPos > 0 && $equalsPos != sizeof($iniLine)) { - $key = trim(substr($iniLine, 0, $equalsPos)); - $value = trim(substr($iniLine, $equalsPos+1)); - if (substr($value, 1, 1) == '"' && substr( $value, -1, 1) == '"') { - $value = substr($value, 1, -1); - } - $this->cleanArray[$section][$key] = stripcslashes($value); - } else { - $this->cleanArray[$section][trim($iniLine)]=''; - } - } - } - return $this->cleanArray; - } - - function write($iniFile = "") { - - if(empty($iniFile)) { - $iniFile = $this->iniFile; - } - if (!is_writeable($iniFile)) { - return; - } - - $fileHandle = fopen($iniFile, 'wb'); - foreach ($this->cleanArray as $section => $items) { - if (substr($section, 0, strlen('_blankline_')) === '_blankline_' ) { - fwrite ($fileHandle, "\r\n"); - continue; - } - if (substr($section, 0, strlen('_comment_')) === '_comment_' ) { - fwrite ($fileHandle, "$items\r\n"); - continue; - } - fwrite ($fileHandle, "[".$section."]\r\n"); - foreach ($items as $key => $value) { - if (substr($key, 0, strlen('_blankline_')) === '_blankline_' ) { - fwrite ($fileHandle, "\r\n"); - continue; - } - if (substr($key, 0, strlen('_comment_')) === '_comment_' ) { - fwrite ($fileHandle, "$value\r\n"); - continue; - } - - $value = addcslashes($value,''); - //fwrite ($fileHandle, $key.' = "'.$value."\"\r\n"); - fwrite ($fileHandle, $key.' = '.$value."\r\n"); - } - } - fclose($fileHandle); - } - - function itemExists($checkSection, $checkItem) { - - $this->exists = ''; - foreach($this->cleanArray as $section => $items) { - if($section == $checkSection) { - $this->exists = 'section'; - foreach ($items as $key => $value) { - if($key == $checkItem) { - return true; - } - } - } - } - return false; - } - - function addItem($addSection, $addItem, $value, $itemComment = '', $sectionComment = '') { - - if($this->itemExists($addSection, $addItem)) { - $this->delItem($addSection, $addItem); - } - - if($this->exists != 'section') { - $this->cleanArray['_blankline_'.$this->lineNum++]=''; - if(!empty($sectionComment)) $this->cleanArray['_comment_'.$this->lineNum++] = '; '.$sectionComment; - } - if(!empty($itemComment)) { - $this->cleanArray[$addSection]['_comment_'.$this->lineNum++] = '; '.$itemComment; - } - $this->cleanArray[$addSection][$addItem] = stripcslashes($value); - return true; - } - - function updateItem($addSection, $addItem, $value) { - - $this->cleanArray[$addSection][$addItem] = stripcslashes($value); - return true; - } - - function delItem($delSection, $delItem) { - - if(!$this->itemExists($delSection, $delItem)) return false; - - unset($this->cleanArray[$delSection][$delItem]); - return true; - } - - function delSection($delSection) { - - unset($this->cleanArray[$delSection]); - return true; - } - - // Return file line by line - public function getFileByLine() { - $data = $this->read($this->iniFile); - return $data['']; - } - - public function getSection($section) { - if (isset($this->cleanArray[$section])) { - return $this->cleanArray[$section]; - } - - return false; - } -} -?> \ No newline at end of file diff --git a/setup/wizard/iniUtilities.php b/setup/wizard/iniUtilities.php index b036724..366caf7 100644 --- a/setup/wizard/iniUtilities.php +++ b/setup/wizard/iniUtilities.php @@ -43,12 +43,21 @@ class iniUtilities { private $lineNum = 0; private $exists = ''; - function iniUtilities($iniFile = '../../config.ini') { + + function load($iniFile) { +// if($this->iniFile != $iniFile) { +// $this->cleanArray = array(); +// $this->lineNum = 0; +// $this->exists = ''; +// } $this->iniFile = $iniFile; $this->backupIni($iniFile); $this->read($iniFile); } - + +// function __construct() { +// } + /** * Create a backup with the date as an extension in the same location as the original config.ini * @@ -58,23 +67,23 @@ class iniUtilities { function backupIni($iniFile) { $content = file_get_contents($iniFile); - if ($content === false) + if (!$content === false) { - return false; - } - $date = date('YmdHis'); - - $backupFile = $iniFile . '.' .$date; - if (is_writeable($backupFile)) { - file_put_contents($backupFile, $content); - } + $date = date('YmdHis'); + + $backupFile = $iniFile . '.' .$date; + if (is_writeable($backupFile)) { + file_put_contents($backupFile, $content); + } + } + return false; } function read($iniFile) { $iniArray = file($iniFile); $section = ''; foreach($iniArray as $iniLine) { - $this->lineNum++; + ++$this->lineNum; $iniLine = trim($iniLine); $firstChar = substr($iniLine, 0, 1); if($firstChar == ';') { @@ -111,6 +120,7 @@ class iniUtilities { } } } + return $this->cleanArray; } @@ -153,12 +163,12 @@ class iniUtilities { } function itemExists($checkSection, $checkItem) { - $this->exists = ''; foreach($this->cleanArray as $section => $items) { if($section == $checkSection) { $this->exists = 'section'; - foreach ($items as $key => $value) { + $items = array_flip($items); + foreach ($items as $key) { if($key == $checkItem) { return true; } diff --git a/setup/wizard/installUtil.php b/setup/wizard/installUtil.php index 635817b..ec0865a 100644 --- a/setup/wizard/installUtil.php +++ b/setup/wizard/installUtil.php @@ -39,9 +39,13 @@ * @package Installer * @version Version 0.1 */ +require_once("iniUtilities.php"); +require_once("dbUtilities.php"); + class InstallUtil { - private $salt = 'installers'; + public $dbUtilities = null; + public $iniUtilities = null; /** * Constructs installation object @@ -50,6 +54,8 @@ class InstallUtil { * @access public */ public function __construct() { + $this->dbUtilities = new dbUtilities(); + $this->iniUtilities = new iniUtilities(); } /** @@ -70,15 +76,17 @@ class InstallUtil { public function error($error) { $template_vars['error'] = $error; $file = "templates/error.tpl"; - if (!file_exists($file)) { - return false; + if (file_exists($file)) { + extract($template_vars); // Extract the vars to local namespace + ob_start(); + include($file); + $contents = ob_get_contents(); + ob_end_clean(); + echo $contents; } - extract($template_vars); // Extract the vars to local namespace - ob_start(); - include($file); - $contents = ob_get_contents(); - ob_end_clean(); - echo $contents; + + return false; + } /** * Check if system needs to be installed @@ -165,7 +173,7 @@ class InstallUtil { return $url; } if (!empty($protocol)) { - $url = $protocol .':'. end($array = explode(':', $url, 2)); + $url = $protocol .':'. end(explode(':', $url, 2)); } if (!empty($port)) { $url = preg_replace('!^(([a-z0-9]+)://[^/:]+)(:[\d]+)?!i', @@ -325,9 +333,11 @@ class InstallUtil { return false; elseif(!is_dir($fullpath)) { $perms = substr(sprintf('%o', fileperms($fullpath)), -4); - if($perms != $filemode) - if (!chmod($fullpath, $filemode)) + if($perms != $filemode) { + if (!chmod($fullpath, $filemode)) { return false; + } + } } elseif(!$this->chmodRecursive($fullpath, $filemode)) return false; } @@ -354,7 +364,8 @@ class InstallUtil { */ public function canWriteFile($filename) { $fh = fopen($filename, "w+"); - if($fr = fwrite($fh, 'test') === false) { + $fr = fwrite($fh, 'test'); + if($fr === false) { return false; } @@ -372,9 +383,9 @@ class InstallUtil { */ public function javaBridge() { try { - $javaSystem = new Java('java.lang.System'); + new Java('java.lang.System'); } catch (JavaException $e) { - return false; + return $e; } return true; } @@ -449,6 +460,8 @@ class InstallUtil { return preg_replace('/java:/', '', $r); } } + + return ''; } /** @@ -726,6 +739,7 @@ class InstallUtil { * @return string */ public function installEnvironment() { + $matches = false; preg_match('/Zend/', SYSTEM_DIR, $matches); // Install Type if($matches) { return 'Zend'; @@ -753,7 +767,7 @@ class InstallUtil { array_pop($sysdir); array_pop($sysdir); $zendsys = ''; - foreach ($sysdir as $k=>$v) { + foreach ($sysdir as $v) { $zendsys .= $v.DS; } $bin = $zendsys."ZendServer".DS."bin".DS; @@ -778,15 +792,16 @@ class InstallUtil { if(WINDOWS_OS) { // Mysql bin [Windows] $serverPaths = explode(';',$_SERVER['PATH']); foreach ($serverPaths as $apath) { + $matches = false; preg_match('/mysql/i', $apath, $matches); if($matches) { return $apath.DS; break; } } - } else { - return "mysql"; // Assume its linux and can be executed from command line } + + return "mysql"; // Assume its linux and can be executed from command line } public function sqlInstallDir() { diff --git a/setup/wizard/installWizard.php b/setup/wizard/installWizard.php index a090336..12017e6 100644 --- a/setup/wizard/installWizard.php +++ b/setup/wizard/installWizard.php @@ -63,8 +63,8 @@ function __autoload($class) { // Attempt and autoload classes if(preg_match('/Helper/', $class)) { require_once(HELPER_DIR."$class.php"); } - return null; } + return false; } class InstallWizard { @@ -263,8 +263,6 @@ class InstallWizard { return true; break; } - - return $res; } /** @@ -284,7 +282,7 @@ class InstallWizard { } if(!$this->isSystemInstalled()) { // Check if the systems not installed if($this->util->migrationSpecified()) { // Check if the migrator needs to be accessed - $this->util->redirect('../migrate'); + $this->util->redirect('../migrate/index.php'); } elseif ($this->util->upgradeSpecified()) { $this->util->redirect('../upgrade/index.php?action=installer'); } diff --git a/setup/wizard/installer.php b/setup/wizard/installer.php index e3ae105..aa4e06e 100644 --- a/setup/wizard/installer.php +++ b/setup/wizard/installer.php @@ -157,7 +157,7 @@ class Installer { $this->simpleXmlObj = simplexml_load_file(CONF_DIR.$name); } catch (Exception $e) { $util = new InstallUtil(); - $util->error("Error reading configuration file: $name"); + $util->error("Error reading configuration file: $e"); exit(); } } @@ -431,8 +431,7 @@ class Installer { if($class->runInstall()) { // Check if step needs to be installed $class->setDataFromSession($className); // Set Session Information $class->setPostConfig(); // Set any posted variables - $response = $class->installStep(); // Run install step - // TODO : Break on error response + $class->installStep(); // Run install step } } else { $util = new InstallUtil(); diff --git a/setup/wizard/lib/helpers/htmlHelper.php b/setup/wizard/lib/helpers/htmlHelper.php index 50150b5..f106573 100644 --- a/setup/wizard/lib/helpers/htmlHelper.php +++ b/setup/wizard/lib/helpers/htmlHelper.php @@ -41,7 +41,7 @@ */ class htmlHelper { - var $tags = array( + private $tags = array( 'meta' => '', 'metalink' => '', 'link' => '%s', @@ -114,6 +114,10 @@ class htmlHelper { return $image; } + function url() { + + } + function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) { if (is_array($options)) { $options = array_merge(array('escape' => true), $options); diff --git a/setup/wizard/lib/services/unixLucene.php b/setup/wizard/lib/services/unixLucene.php index ff574e1..1520874 100644 --- a/setup/wizard/lib/services/unixLucene.php +++ b/setup/wizard/lib/services/unixLucene.php @@ -59,7 +59,7 @@ class unixLucene extends unixService { * @param string * @return void */ - public function load($options = null) { + public function load() { $this->setLuceneSource("ktlucene.jar"); $this->setLuceneDir(SYSTEM_DIR."bin".DS."luceneserver".DS); $this->setIndexerDir(SYSTEM_DIR."search2".DS."indexing".DS."bin".DS); @@ -148,14 +148,13 @@ class unixLucene extends unixService { * @return array */ public function stop() { - // TODO: Breaks things $state = $this->status(); if($state != '') { $cmd = "pkill -f ".$this->getLuceneSource(); $response = $this->util->pexec($cmd); return $response; } - + return $state; } public function install() { @@ -173,6 +172,7 @@ class unixLucene extends unixService { if(is_array($response['out'])) { if(count($response['out']) > 1) { foreach ($response['out'] as $r) { + $matches = false; preg_match('/grep/', $r, $matches); // Ignore grep if(!$matches) { return 'STARTED'; @@ -201,26 +201,20 @@ class unixLucene extends unixService { public function start() { $state = $this->status(); if($state != 'STARTED') { - $logFile = $this->outputDir."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 $!"; if(DEBUG) { echo "Command : $cmd
"; - return ; + return false; } $response = $this->util->pexec($cmd); return $response; - } elseif ($state == '') { - // Start Service - return true; - } else { - // Service Running Already - return true; } - return false; + return true; } public function getName() { diff --git a/setup/wizard/lib/services/unixOpenOffice.php b/setup/wizard/lib/services/unixOpenOffice.php index b4b9d1d..86d1066 100644 --- a/setup/wizard/lib/services/unixOpenOffice.php +++ b/setup/wizard/lib/services/unixOpenOffice.php @@ -106,13 +106,14 @@ class unixOpenOffice extends unixService { } } - public function status($updrade = false) { + public function status() { sleep(1); $cmd = "ps ax | grep soffice"; $response = $this->util->pexec($cmd); if(is_array($response['out'])) { if(count($response['out']) > 1) { foreach ($response['out'] as $r) { + $matches = false; preg_match('/grep/', $r, $matches); // Ignore grep if(!$matches) { return 'STARTED'; @@ -140,20 +141,13 @@ class unixOpenOffice extends unixService { $cmd = "nohup ".$this->getBin().' -nofirststartwizard -nologo -headless -"accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" '." > /dev/null 2>&1 & echo $!"; if(DEBUG) { echo "Command : $cmd
"; - return ; + return false; } - $response = $this->util->pexec($cmd); - - return $response; - } elseif ($state == '') { - // Start Service - return true; - } else { - // Service Running Already - return true; + + return $this->util->pexec($cmd); } - return false; + return true; } /** diff --git a/setup/wizard/lib/services/unixScheduler.php b/setup/wizard/lib/services/unixScheduler.php index aae16f3..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."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/lib/validation/openofficeValidation.php b/setup/wizard/lib/validation/openofficeValidation.php index 3f69fbb..e671729 100644 --- a/setup/wizard/lib/validation/openofficeValidation.php +++ b/setup/wizard/lib/validation/openofficeValidation.php @@ -154,7 +154,7 @@ class openofficeValidation extends serviceValidation { $bin = "soffice"; } foreach ($locations as $loc) { - $pathToBinary = $loc.$bin; + $pathToBinary = $loc.DS.$bin; if(file_exists($pathToBinary)) { return $pathToBinary; } diff --git a/setup/wizard/resources/graphics/favicon.ico b/setup/wizard/resources/graphics/favicon.ico new file mode 100644 index 0000000..72a0594 --- /dev/null +++ b/setup/wizard/resources/graphics/favicon.ico 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/resources/js/wizard.js b/setup/wizard/resources/js/wizard.js index 3809f30..7fe4999 100644 --- a/setup/wizard/resources/js/wizard.js +++ b/setup/wizard/resources/js/wizard.js @@ -4,14 +4,29 @@ function wizard() { // Toggle Advance Database options wizard.prototype.toggleClass = function(ele, option) { //adv_options|php_details|php_ext_details|php_con_details - if($('.'+ele).attr('style') == 'display: none;') { - $('.'+ele).attr('style', 'display: block;'); - if($('#'+option).attr('innerHTML') != '  Advanced Options') - $('#'+option).attr('innerHTML', 'Hide Details'); - } else { - $('.'+ele).attr('style', 'display: none;'); - if($('#'+option).attr('innerHTML') != '  Advanced Options') - $('#'+option).attr('innerHTML', 'Show Details'); + var style = $('.'+ele).attr('style'); + style = w.trim(style); + switch(style) { + case 'display: none;': + $('.'+ele).attr('style', 'display: block;'); + if($('#'+option).attr('innerHTML') != '  Advanced Options') + $('#'+option).attr('innerHTML', 'Hide Details'); + break; + case 'DISPLAY: none;': + $('.'+ele).attr('style', 'DISPLAY: block'); + if($('#'+option).attr('innerHTML') != '  Advanced Options') + $('#'+option).attr('innerHTML', 'Hide Details'); + break; + case 'display: block;': + $('.'+ele).attr('style', 'display: none;'); + if($('#'+option).attr('innerHTML') != '  Advanced Options') + $('#'+option).attr('innerHTML', 'Show Details'); + break; + case 'DISPLAY: block;': + $('.'+ele).attr('style', 'DISPLAY: none'); + if($('#'+option).attr('innerHTML') != '  Advanced Options') + $('#'+option).attr('innerHTML', 'Show Details'); + break; } } diff --git a/setup/wizard/step.php b/setup/wizard/step.php index ff0acd0..0c75811 100644 --- a/setup/wizard/step.php +++ b/setup/wizard/step.php @@ -117,17 +117,7 @@ class Step */ public $util; - /** - * Reference to utility object - * - * @author KnowledgeTree Team - * @access protected - * @var object - */ - public $dbhandler; - public function __construct() { - $this->dbhandler = new dbUtilities(); $this->util = new InstallUtil(); } /** diff --git a/setup/wizard/steps/complete.php b/setup/wizard/steps/complete.php index ac73aee..8df2aae 100644 --- a/setup/wizard/steps/complete.php +++ b/setup/wizard/steps/complete.php @@ -142,8 +142,8 @@ class complete extends Step { // retrieve database information from session $dbconf = $this->getDataFromSession("database"); // make db connection - admin - $this->dbhandler->load($dbconf['dhost'], $dbconf['dmsname'], $dbconf['dmspassword'], $dbconf['dname']); - $loaded = $this->dbhandler->getDatabaseLink(); + $this->util->dbUtilities->load($dbconf['dhost'], $dbconf['dport'], $dbconf['dmsname'], $dbconf['dmspassword'], $dbconf['dname']); + $loaded = $this->util->dbUtilities->getDatabaseLink(); if (!$loaded) { $this->temp_variables['dbConnectAdmin'] .= '
' . '' . ''; $this->privileges_check = 'cross'; $this->privileges_check = 'cross'; @@ -183,17 +183,17 @@ class complete extends Step { // check transaction support $sTable = 'system_settings'; - $this->dbhandler->startTransaction(); - $this->dbhandler->query('INSERT INTO ' . $sTable . ' (name, value) VALUES ("transactionTest", "1")'); - $this->dbhandler->rollback(); - $res = $this->dbhandler->query("SELECT id FROM $sTable WHERE name = 'transactionTest' LIMIT 1"); + $this->util->dbUtilities->startTransaction(); + $this->util->dbUtilities->query('INSERT INTO ' . $sTable . ' (name, value) VALUES ("transactionTest", "1")'); + $this->util->dbUtilities->rollback(); + $res = $this->util->dbUtilities->query("SELECT id FROM $sTable WHERE name = 'transactionTest' LIMIT 1"); if (!$res) { $this->temp_variables['dbTransaction'] .= sprintf($html, 'cross', 'class="error"', 'Transaction support not available in database'); $this->privileges_check = 'cross'; } else { $this->temp_variables['dbTransaction'] .= sprintf($html, 'tick', '', 'Database has transaction support'); } - $this->dbhandler->query('DELETE FROM ' . $sTable . ' WHERE name = "transactionTest"'); + $this->util->dbUtilities->query('DELETE FROM ' . $sTable . ' WHERE name = "transactionTest"'); } else { diff --git a/setup/wizard/steps/configuration.php b/setup/wizard/steps/configuration.php index 56abe58..7024af7 100644 --- a/setup/wizard/steps/configuration.php +++ b/setup/wizard/steps/configuration.php @@ -307,41 +307,38 @@ class configuration extends Step { $conf = $this->getDataFromSession("configuration"); // get data from the server $dbconf = $this->getDataFromSession("database"); - $this->dbhandler->load($dbconf['dhost'], $dbconf['dmsname'], $dbconf['dmspassword'], $dbconf['dname']); + $this->util->dbUtilities->load($dbconf['dhost'], $dbconf['dport'], $dbconf['dmsname'], $dbconf['dmspassword'], $dbconf['dname']); $server = $conf['server']; $paths = $conf['paths']; if ($this->util->isMigration()) { // Check if its an upgrade $this->readInstallation(); - $configPath = $paths['configFile']['path']; + $this->confpaths['configIni'] = $paths['configFile']['path']; } else { $this->readConfigPath(); // initialise writing to config.ini } $this->getFromConfigPath(); // Sets config Paths - $ini = false; - if(file_exists($configPath)) { - $ini = new iniUtilities($configPath); + if(file_exists($this->confpaths['configIni'])) { + $this->util->iniUtilities->load($this->confpaths['configIni']); } - $this->writeUrlSection($ini); - $this->writeDBSection($ini, $server); - $this->writeDBPathSection($ini, $paths); - if(!$ini === false){ // write out the config.ini file - $ini->write(); + if(!$this->util->iniUtilities=== false){ // write out the config.ini file + $this->writeUrlSection(); + $this->writeDBSection($server); + $this->writeDBPathSection($paths); + $this->util->iniUtilities->write(); } - $this->dbhandler->close(); // close the database connection - $this->writeCachePath(); // Write cache path file - $this->writeConfigPath($configPath); // Write config file + $this->util->dbUtilities->close(); // close the database connection + $this->writeCachePath($this->getCachePath(), $paths['cacheDirectory']['path']); // Write cache path file + $this->writeConfigPath($this->getContentPath(), $this->confpaths['configIni']); // Write config file } - private function writeUrlSection($ini) { + private function writeUrlSection() { $directories = $this->registerDirs(); foreach($directories as $item) { // write server settings to config_settings table and config.ini - if(!$ini === false) { - $ini->updateItem($item['section'], $item['setting'], $item['value']); - } + $this->util->iniUtilities->updateItem($item['section'], $item['setting'], $item['value']); } } - private function writeDBPathSection($ini, $paths) { + private function writeDBPathSection($paths) { $table = 'config_settings'; if(is_array($paths)) { // write the paths to the config_settings table foreach ($paths as $item){ @@ -351,14 +348,14 @@ class configuration extends Step $value = mysql_real_escape_string($item['path']); $setting = mysql_real_escape_string($item['setting']); $sql = "UPDATE {$table} SET value = '{$value}' WHERE item = '{$setting}'"; - $this->dbhandler->query($sql); + $this->util->dbUtilities->query($sql); } } } - private function writeDBSection($ini, $server) { + private function writeDBSection($server) { $dbconf = $this->getDataFromSession("database"); // retrieve database information from session - $this->dbhandler->load($dbconf['dhost'], $dbconf['duname'], $dbconf['dpassword'], $dbconf['dname']); // initialise the db connection + $this->util->dbUtilities->load($dbconf['dhost'], $dbconf['dport'], $dbconf['duname'], $dbconf['dpassword'], $dbconf['dname']); // initialise the db connection $server = $this->registerDBConfig($server, $dbconf); // add db config to server variables $table = 'config_settings'; foreach($server as $item) { // write server settings to config_settings table and config.ini @@ -371,16 +368,14 @@ class configuration extends Step if($value == 'no'){ $value = 'false'; } - if(!$ini === false){ - $ini->updateItem($item['section'], $item['setting'], $value); - } + $this->util->iniUtilities->updateItem($item['section'], $item['setting'], $value); break; case 'db': $value = mysql_real_escape_string($item['value']); $setting = mysql_real_escape_string($item['setting']); $sql = "UPDATE {$table} SET value = '{$value}' WHERE item = '{$setting}'"; - $this->dbhandler->query($sql); + $this->util->dbUtilities->query($sql); break; } } @@ -578,15 +573,45 @@ class configuration extends Step public function readConfigPathIni() { if(isset($this->temp_variables['paths']['configFile']['path'])) { - return $this->temp_variables['paths']['configFile']['path']; + if($this->temp_variables['paths']['configFile']['path'] != '') + return $this->temp_variables['paths']['configFile']['path']; } $configPath = $this->getContentPath(); - if(!$configPath) return false; - $ini = new iniUtilities($configPath); - $data = $ini->getFileByLine(); + if(!$configPath) { + return false; + } + $this->util->iniUtilities->load($configPath); + $data = $this->util->iniUtilities->getFileByLine(); $firstline = true; foreach ($data as $k=>$v) { if(preg_match('/config.ini/', $k)) { // Find config.ini + if($k == "config/config.ini") { // Source install and source upgrades + $configIniPath = realpath(SYSTEM_DIR.$k); + if($configIniPath) + return $configIniPath; + } + return $k; + } + } + + return false; + } + + public function readCachePath() { + $cachePath = $this->getCachePath(); + if(!$cachePath) { + return false; + } + $this->util->iniUtilities->load($cachePath); + $data = $this->util->iniUtilities->getFileByLine(); + $firstline = true; + foreach ($data as $k=>$v) { + if(preg_match('/cache/', $k)) { // Find config.ini + if($k == "var/cache") { // Source install and source upgrades + $configIniPath = realpath(SYSTEM_DIR.$k); + if($configIniPath) + return $configIniPath; + } return $k; } } @@ -605,8 +630,8 @@ class configuration extends Step private function readConfigPath() { $configPath = $this->getContentPath(); if(!$configPath) return false; - $ini = new iniUtilities($configPath); - $data = $ini->getFileByLine(); + $this->util->iniUtilities->load($configPath); + $data = $this->util->iniUtilities->getFileByLine(); $firstline = true; foreach ($data as $k=>$v) { if($firstline) { // First line holds the var directory @@ -645,46 +670,48 @@ class configuration extends Step * @param none * @return boolean */ - private function writeConfigPath($configPath = '') { - $conf = $this->getDataFromSession("configuration"); // get data from the server - $paths = $conf['paths']; - if(isset($paths['configFile']['path'])) { - $configPath = $this->getContentPath(); - $configContent = $paths['configFile']['path']; - } else { - $configPath = $this->getContentPath(); - if(!$configPath) return false; - $ini = new iniUtilities($configPath); - $data = $ini->getFileByLine(); - $configContent = ''; - foreach ($data as $k=>$v) { - if(preg_match('/config.ini/', $k)) { - $configContent = $k; - break; - } - } - } - $fp = fopen($configPath, 'w'); + private function writeConfigPath($configPath, $configContent) { +// $conf = $this->getDataFromSession("configuration"); // get data from the server +// $paths = $conf['paths']; +// if(isset($paths['configFile']['path'])) { +// $configPath = $this->getContentPath(); +// $configContent = $paths['configFile']['path']; +// } else { +// $configPath = $this->getContentPath(); +// if(!$configPath) return false; +// $this->util->iniHandler->load($configPath); +// $data = $this->util->iniHandler->getFileByLine(); +// $configContent = ''; +// foreach ($data as $k=>$v) { +// if(preg_match('/config.ini/', $k)) { +// $configContent = $k; +// break; +// } +// } +// } +// print_r($configPath); +// print_r($configContent); + $fp = fopen($configPath, 'w+'); if(fwrite($fp, $configContent)) return true; return false; } - private function writeCachePath() { - $cachePath = $this->getCachePath(); - if(!$cachePath) return false; - $configPath = $this->getContentPath(); - if(!$configPath) return false; - $ini = new iniUtilities($configPath); - $data = $ini->getFileByLine(); - $cacheContent = ''; - foreach ($data as $k=>$v) { - if(preg_match('/cache/', $k)) { - $cacheContent = $k; - break; - } - } - $fp = fopen($cachePath, 'w'); + private function writeCachePath($cachePath, $cacheContent) { +// $cachePath = $this->getCachePath(); +// if(!$cachePath) return false; +// $configPath = $this->getContentPath(); +// if(!$configPath) return false; +// $this->util->iniHandler->load($configPath); +// $data = $this->util->iniHandler->getFileByLine(); +// $cacheContent = ''; +// foreach ($data as $k=>$v) { +// if(preg_match('/cache/', $k)) { +// $cacheContent = $k; +// break; +// } +// } + $fp = fopen($cachePath, 'w+'); if($cacheContent != '') { if(fwrite($fp, $cacheContent)) return true; diff --git a/setup/wizard/steps/database.php b/setup/wizard/steps/database.php index 8c3f3dc..4ee436d 100644 --- a/setup/wizard/steps/database.php +++ b/setup/wizard/steps/database.php @@ -319,12 +319,12 @@ class database extends Step $this->error['dmsuserpassword'] = "Passwords do not match: " . $this->dmsuserpassword." ". $this->getPassword2(); return false; } - if($this->dport == '') { - $this->dbhandler->load($this->dhost, $this->duname, $this->dpassword, $this->dname); - } else { - $this->dbhandler->load($this->dhost.":".$this->dport, $this->duname, $this->dpassword, $this->dname); - } - if (!$this->dbhandler->getDatabaseLink()) { +// if($this->dport == '') { +// $this->util->dbUtilities->load($this->dhost, $this->duname, $this->dpassword, $this->dname); +// } else { + $this->util->dbUtilities->load($this->dhost, $this->dport, $this->duname, $this->dpassword, $this->dname); +// } + if (!$this->util->dbUtilities->getDatabaseLink()) { $this->error['con'] = "Could not connect to the database, please check username and password"; return false; } else { @@ -339,7 +339,7 @@ class database extends Step } public function dbExists() { - return $this->dbhandler->useDb(); + return $this->util->dbUtilities->useDb(); } public function match($str1, $str2) { @@ -500,7 +500,6 @@ class database extends Step * @return object SimpleXmlObject */ public function readXml() { -// echo CONF_DIR."databases.xml"; $simplexml = simplexml_load_file(CONF_DIR."databases.xml"); return $simplexml; @@ -583,7 +582,7 @@ class database extends Step * @return object mysql connection */ private function connectMysql() { - $this->dbhandler->load($this->dhost, $this->duname, $this->dpassword, $this->dname); + $this->util->dbUtilities->load($this->dhost, $this->dport, $this->duname, $this->dpassword, $this->dname); } /** @@ -642,7 +641,7 @@ class database extends Step $this->error['con'] = "Could not create database: "; } } - $this->dbhandler->clearErrors(); + $this->util->dbUtilities->clearErrors(); if(!$this->createDmsUser()) { // Create dms users $this->error['con'] = "Could not create database users "; } @@ -666,8 +665,7 @@ class database extends Step */ private function create() { $sql = "CREATE DATABASE {$this->dname}"; - if ($this->dbhandler->query($sql)) { - + if ($this->util->dbUtilities->query($sql)) { return true; } @@ -683,7 +681,7 @@ class database extends Step * @return boolean */ private function usedb() { - if($this->dbhandler->useDb()) { + if($this->util->dbUtilities->useDb()) { return true; } else { $this->error['con'] = "Error using database: {$this->dname}"; @@ -702,7 +700,7 @@ class database extends Step private function dropdb() { if($this->ddrop) { $sql = "DROP DATABASE {$this->dname};"; - if(!$this->dbhandler->query($sql)) { + if(!$this->util->dbUtilities->query($sql)) { $this->error['con'] = "Cannot drop database: {$this->dname}"; return false; } @@ -724,7 +722,7 @@ class database extends Step private function createDmsUser() { $user1 = "GRANT SELECT, INSERT, UPDATE, DELETE ON {$this->dname}.* TO {$this->dmsusername}@{$this->dhost} IDENTIFIED BY \"{$this->dmsuserpassword}\";"; $user2 = "GRANT ALL PRIVILEGES ON {$this->dname}.* TO {$this->dmsname}@{$this->dhost} IDENTIFIED BY \"{$this->dmspassword}\";"; - if ($this->dbhandler->query($user1) && $this->dbhandler->query($user2)) { + if ($this->util->dbUtilities->query($user1) && $this->util->dbUtilities->query($user2)) { return true; } else { $this->error['con'] = "Could not create users for database: {$this->dname}"; @@ -751,7 +749,7 @@ class database extends Step while (!feof($handle)) { $query.= fgets($handle, 4096); if (substr(rtrim($query), -1) == ';') { - $this->dbhandler->query($query); + $this->util->dbUtilities->query($query); $query = ''; } } @@ -778,9 +776,9 @@ class database extends Step $sqlFile = $dbMigrate['dumpLocation']; $this->parse_mysql_dump($sqlFile); $dropPluginHelper = "TRUNCATE plugin_helper;"; - $this->dbhandler->query($dropPluginHelper); + $this->util->dbUtilities->query($dropPluginHelper); $updateUrls = 'UPDATE config_settings c SET c.value = "default" where c.group_name = "urls";'; - $this->dbhandler->query($updateUrls); + $this->util->dbUtilities->query($updateUrls); return true; } /** @@ -793,7 +791,7 @@ class database extends Step */ private function closeMysql() { try { - $this->dbhandler->close(); + $this->util->dbUtilities->close(); } catch (Exeption $e) { $this->error['con'] = "Could not close: " . $e; } @@ -844,7 +842,7 @@ class database extends Step $this->dpassword = 'root'; $this->dname = 'dms_install'; $this->dbbinary = 'mysql'; - $this->dbhandler->load($this->dhost, $this->duname, $this->dpassword, $this->dname); + $this->util->dbUtilities->load($this->dhost, '', $this->duname, $this->dpassword, $this->dname); $this->createSchema(); echo 'Schema loaded
'; } diff --git a/setup/wizard/steps/install.php b/setup/wizard/steps/install.php index 76c4d9c..951e0af 100644 --- a/setup/wizard/steps/install.php +++ b/setup/wizard/steps/install.php @@ -107,14 +107,14 @@ class install extends step public function callHome() { $conf = $this->getDataFromSession("install"); // retrieve database information from session $dbconf = $this->getDataFromSession("database"); - $this->dbhandler->load($dbconf['dhost'], $dbconf['duname'], $dbconf['dpassword'], $dbconf['dname']); // initialise the db connection + $this->util->dbUtilities->load($dbconf['dhost'], '', $dbconf['duname'], $dbconf['dpassword'], $dbconf['dname']); // initialise the db connection $complete = 1; if($conf['call_home'] == 'enable'){ $complete = 0; } $query = "UPDATE scheduler_tasks SET is_complete = {$complete} WHERE task = 'Call Home'"; - $this->dbhandler->query($query); - $this->dbhandler->close(); // close the database connection + $this->util->dbUtilities->query($query); + $this->util->dbUtilities->close(); // close the database connection } } ?> \ No newline at end of file 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/complete.tpl b/setup/wizard/templates/complete.tpl index e422980..35fe8e5 100644 --- a/setup/wizard/templates/complete.tpl +++ b/setup/wizard/templates/complete.tpl @@ -136,13 +136,13 @@ Goto Database Upgrade - Goto Login + Goto Login - " class="back" target="_blank" onclick="javascript:{w.clearSessions();}">Zend Server Configuration + diff --git a/setup/wizard/templates/error.tpl b/setup/wizard/templates/error.tpl index 67b08f0..cd3bbb3 100644 --- a/setup/wizard/templates/error.tpl +++ b/setup/wizard/templates/error.tpl @@ -1,6 +1,7 @@ + KnowledgeTree Installer @@ -15,7 +16,7 @@
3.7 - Commercial Edition + Community Edition
diff --git a/setup/wizard/templates/install.tpl b/setup/wizard/templates/install.tpl index b61c652..f25971f 100644 --- a/setup/wizard/templates/install.tpl +++ b/setup/wizard/templates/install.tpl @@ -5,12 +5,10 @@

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

+

   + Help to improve KnowledgeTree by providing anonymous usage statistics

diff --git a/setup/wizard/templates/welcome.tpl b/setup/wizard/templates/welcome.tpl index c91ce67..91c842b 100644 --- a/setup/wizard/templates/welcome.tpl +++ b/setup/wizard/templates/welcome.tpl @@ -4,7 +4,7 @@

This wizard will lead you through all the steps required to install and configure KnowledgeTree on your server.

Press Next to continue.

-
image('kt_browse.png'); ?>
+
image('kt_browse.png'); ?>
diff --git a/setup/wizard/templates/wizard.tpl b/setup/wizard/templates/wizard.tpl index fc68ba0..612b2b4 100644 --- a/setup/wizard/templates/wizard.tpl +++ b/setup/wizard/templates/wizard.tpl @@ -1,6 +1,7 @@ + KnowledgeTree Installerjs('jquery.js'); ?> js('jquery.form.js'); ?> diff --git a/templates/ktcore/forms/widgets/date.smarty b/templates/ktcore/forms/widgets/date.smarty index d8a8feb..47a7ba4 100755 --- a/templates/ktcore/forms/widgets/date.smarty +++ b/templates/ktcore/forms/widgets/date.smarty @@ -1,7 +1,7 @@ -
+
{literal}
CodeDescriptionApplied
Unable to connect to database (user: ' @@ -157,20 +157,20 @@ class complete extends Step { } // make db connection - user - $this->dbhandler->load($dbconf['dhost'], $dbconf['dmsusername'], $dbconf['dmsuserpassword'], $dbconf['dname']); - $loaded = $this->dbhandler->getDatabaseLink(); + $this->util->dbUtilities->load($dbconf['dhost'], $dbconf['dport'], $dbconf['dmsusername'], $dbconf['dmsuserpassword'], $dbconf['dname']); + $loaded = $this->util->dbUtilities->getDatabaseLink(); // if we can log in to the database, check access // TODO check write access? if ($loaded) { $this->temp_variables['dbConnectUser'] .= sprintf($html, 'tick', '', 'Database connectivity successful (user: ' . $dbconf['dmsusername'] . ')'); - $qresult = $this->dbhandler->query('SELECT COUNT(id) FROM documents'); + $qresult = $this->util->dbUtilities->query('SELECT COUNT(id) FROM documents'); if (!$qresult) { $this->temp_variables['dbPrivileges'] .= '
' - . 'Unable to do a basic database query. Error: ' . $this->dbhandler->getLastError() + . 'Unable to do a basic database query. Error: ' . $this->util->dbUtilities->getLastError() . '