From bdef9e59de35c85821c96487c83db34589f9a61c Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Mon, 12 Feb 2018 12:33:47 +0000 Subject: [PATCH] (retrofit from trunk) Bug fixes: - support an upgrade of a givne component (same directory in data/production-modules) - deployment no longer blocked after a failed attempt (cleanup of the data/production-build-modules directory) - load of the "structural data" of newly added extensions Enhancements: - All traces go to log/setup.log, and traces have been added to clearly identify the different phases of the deployment. SVN:2.4[5342] --- datamodels/2.x/itop-hub-connector/ajax.php | 30 +++++++++++++------ .../hubruntimeenvironment.class.inc.php | 11 +++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/datamodels/2.x/itop-hub-connector/ajax.php b/datamodels/2.x/itop-hub-connector/ajax.php index 9908f0390a..8a5554274b 100644 --- a/datamodels/2.x/itop-hub-connector/ajax.php +++ b/datamodels/2.x/itop-hub-connector/ajax.php @@ -22,8 +22,7 @@ * @copyright Copyright (C) 2010-2017 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ -if (!defined('__DIR__')) - define('__DIR__', dirname(__FILE__)); +if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__)); require_once (APPROOT.'application/webpage.class.inc.php'); require_once (APPROOT.'application/ajaxwebpage.class.inc.php'); require_once (APPROOT.'application/utils.inc.php'); @@ -34,6 +33,7 @@ require_once (APPROOT.'setup/runtimeenv.class.inc.php'); require_once (APPROOT.'setup/backup.class.inc.php'); require_once (APPROOT.'core/mutex.class.inc.php'); require_once (APPROOT.'core/dict.class.inc.php'); +require_once (APPROOT.'setup/xmldataloader.class.inc.php'); require_once (__DIR__.'/hubruntimeenvironment.class.inc.php'); /** @@ -218,6 +218,7 @@ try try { + SetupPage::log_info('Backup starts...'); set_time_limit(0); $sBackupPath = APPROOT.'/data/backups/manual/backup-'; $iSuffix = 1; @@ -235,20 +236,26 @@ try $aErrors = $oBackup->GetErrors(); if (count($aErrors)>0) { - ReportError(Dict::S('iTopHub:BackupFailed'), -1, $aErrors); + SetupPage::log_error('Backup failed.'); + SetupPage::log_error(implode("\n", $aErrors)); + ReportError(Dict::S('iTopHub:BackupFailed'), -1, $aErrors); } else { + SetupPage::log_info('Backup successfully completed.'); ReportSuccess(Dict::S('iTopHub:BackupOk')); } } catch (Exception $e) { + SetupPage::log_error($e->getMessage()); ReportError($e->getMessage(), $e->getCode()); } break; case 'compile': + SetupPage::log_info('Deployment starts...'); + // First step: prepare the datamodel, if it fails, roll-back $aSelectedExtensionCodes = utils::ReadParam('extension_codes', array()); $aSelectedExtensionDirs = utils::ReadParam('extension_dirs', array()); @@ -274,6 +281,7 @@ try $oRuntimeEnv->Commit(); // Report the success in a way that will be detected by the ajax caller + SetupPage::log_info('Compilation completed...'); ReportSuccess('Ok'); // No access to Dict::S here break; @@ -284,7 +292,8 @@ try try { - // Load the "production" config file to clone & update it + SetupPage::log_info('Move to production starts...'); + // Load the "production" config file to clone & update it $oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE); $oRuntimeEnv->InitDataModel($oConfig, true /* model only */); @@ -294,7 +303,7 @@ try $aSelectedModules = array(); foreach ($aAvailableModules as $sModuleId => $aModule) { - if (($sModuleId==ROOT_MODULE)||($sModuleId==DATAMODEL_MODULE)) + if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) { continue; } @@ -315,6 +324,8 @@ try $oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDatabaseSetup'); + $oRuntimeEnv->LoadData($aAvailableModules, $aSelectedModules, false /* no sample data*/); + // Record the installation so that the "about box" knows about the installed modules $sDataModelVersion = $oRuntimeEnv->GetCurrentDataModelVersion(); @@ -339,13 +350,14 @@ try $oRuntimeEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModules, $aSelectedExtensionCodes, 'Done by the iTop Hub Connector'); // Report the success in a way that will be detected by the ajax caller + SetupPage::log_info('Deployment successfully completed.'); ReportSuccess(Dict::S('iTopHub:CompiledOK')); } catch (Exception $e) { // Note: at this point, the dictionnary is not necessarily loaded - IssueLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage()); - IssueLog::Error('Debug trace: '.$e->getTraceAsString()); + SetupPage::log_error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage()); + SetupPage::log_error('Debug trace: '.$e->getTraceAsString()); ReportError($e->getMessage(), $e->getCode()); } break; @@ -356,8 +368,8 @@ try } catch (Exception $e) { - IssueLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage()); - IssueLog::Error('Debug trace: '.$e->getTraceAsString()); + SetupPage::log_error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage()); + SetupPage::log_error('Debug trace: '.$e->getTraceAsString()); utils::PopArchiveMode(); diff --git a/datamodels/2.x/itop-hub-connector/hubruntimeenvironment.class.inc.php b/datamodels/2.x/itop-hub-connector/hubruntimeenvironment.class.inc.php index 597d2230c7..5b7b18d267 100644 --- a/datamodels/2.x/itop-hub-connector/hubruntimeenvironment.class.inc.php +++ b/datamodels/2.x/itop-hub-connector/hubruntimeenvironment.class.inc.php @@ -12,6 +12,10 @@ class HubRunTimeEnvironment extends RunTimeEnvironment if ($sEnvironment != $this->sTargetEnv) { + if (is_dir(APPROOT.'/data/'.$this->sTargetEnv.'-modules')) + { + SetupUtils::rrmdir(APPROOT.'/data/'.$this->sTargetEnv.'-modules'); + } SetupUtils::copydir(APPROOT.'/data/'.$sEnvironment.'-modules', APPROOT.'/data/'.$this->sTargetEnv.'-modules'); } } @@ -37,6 +41,13 @@ class HubRunTimeEnvironment extends RunTimeEnvironment if (!mkdir(APPROOT.'/data/'.$this->sTargetEnv.'-modules')) throw new Exception("ERROR: failed to create directory:'".(APPROOT.'/data/'.$this->sTargetEnv.'-modules')."'"); } $sDestinationPath = APPROOT.'/data/'.$this->sTargetEnv.'-modules/'; + + // Make sure that the destination directory of the extension does not already exist + if (is_dir($sDestinationPath.basename($sExtensionDirectory))) + { + // Cleanup before moving... + SetupUtils::rrmdir($sDestinationPath.basename($sExtensionDirectory)); + } if (!rename($sExtensionDirectory, $sDestinationPath.basename($sExtensionDirectory))) throw new Exception("ERROR: failed move directory:'$sExtensionDirectory' to '".$sDestinationPath.basename($sExtensionDirectory)."'"); }