From ec3c42e87c73f8745a49950453d6c56386da9f7d Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Fri, 12 Oct 2012 12:15:06 +0000 Subject: [PATCH] - Changes to the setup program: Backup now works for real - A few cosmetic changes... SVN:trunk[2252] --- setup/ajax.dataloader.php | 40 +++++++-------- setup/applicationinstaller.class.inc.php | 20 +++++--- setup/setuputils.class.inc.php | 4 +- setup/wizardsteps.class.inc.php | 62 +++++++++++++++++++----- 4 files changed, 84 insertions(+), 42 deletions(-) diff --git a/setup/ajax.dataloader.php b/setup/ajax.dataloader.php index dcaa60c19..934a633ba 100644 --- a/setup/ajax.dataloader.php +++ b/setup/ajax.dataloader.php @@ -141,31 +141,31 @@ try ini_set('display_errors', true); ini_set('display_startup_errors', true); - $sConfigFile = utils::GetConfigFilePath(); - if (file_exists($sConfigFile) && !is_writable($sConfigFile)) + require_once(APPROOT.'/setup/wizardcontroller.class.inc.php'); + require_once(APPROOT.'/setup/wizardsteps.class.inc.php'); + + $sClass = utils::ReadParam('step_class', ''); + $sState = utils::ReadParam('step_state', ''); + $sActionCode = utils::ReadParam('code', ''); + $aParams = utils::ReadParam('params', array(), false, 'raw_data'); + $oPage = new ajax_page(''); + $oDummyController = new WizardController(''); + if (is_subclass_of($sClass, 'WizardStep')) { - $oPage->error("Error: the configuration file '".$sConfigFile."' already exists and cannot be overwritten."); - $oPage->p("The wizard cannot modify the configuration file for you. If you want to upgrade ".ITOP_APPLICATION.", make sure that the file '".realpath($sConfigFile)."' can be modified by the web server."); - $oPage->output(); - } - else - { - require_once(APPROOT.'/setup/wizardcontroller.class.inc.php'); - require_once(APPROOT.'/setup/wizardsteps.class.inc.php'); - - $sClass = utils::ReadParam('step_class', ''); - $sState = utils::ReadParam('step_state', ''); - $sActionCode = utils::ReadParam('code', ''); - $aParams = utils::ReadParam('params', array(), false, 'raw_data'); - $oPage = new ajax_page(''); - $oDummyController = new WizardController(''); - if (is_subclass_of($sClass, 'WizardStep')) + $oStep = new $sClass($oDummyController, $sState); + $sConfigFile = utils::GetConfigFilePath(); + if (file_exists($sConfigFile) && !is_writable($sConfigFile) && $oStep->RequiresWritableConfig()) + { + $oPage->error("Error: the configuration file '".$sConfigFile."' already exists and cannot be overwritten."); + $oPage->p("The wizard cannot modify the configuration file for you. If you want to upgrade ".ITOP_APPLICATION.", make sure that the file '".realpath($sConfigFile)."' can be modified by the web server."); + $oPage->output(); + } + else { - $oStep = new $sClass($oDummyController, $sState); $oStep->AsyncAction($oPage, $sActionCode, $aParams); } - $oPage->output(); } + $oPage->output(); break; ////////////////////////////// diff --git a/setup/applicationinstaller.class.inc.php b/setup/applicationinstaller.class.inc.php index 760f21403..a7eb117c9 100644 --- a/setup/applicationinstaller.class.inc.php +++ b/setup/applicationinstaller.class.inc.php @@ -127,7 +127,7 @@ class ApplicationInstaller $aCopies = $aPreinstall['copies']; $sReport = self::DoCopy($aCopies); - $sReport = "copy disabled..."; + $sReport = "Copying..."; $aResult = array( 'status' => self::OK, @@ -136,7 +136,7 @@ class ApplicationInstaller if (isset($aPreinstall['backup'])) { $aResult['next-step'] = 'backup'; - $aResult['next-step-label'] = 'Backuping the database'; + $aResult['next-step-label'] = 'Performing a backup of the database'; $aResult['percentage-completed'] = 20; } else @@ -224,7 +224,7 @@ class ApplicationInstaller 'status' => self::OK, 'message' => '', 'next-step' => 'after-db-create', - 'next-step-label' => 'Creating Profiles', + 'next-step-label' => 'Creating profiles', 'percentage-completed' => 60, ); break; @@ -260,7 +260,7 @@ class ApplicationInstaller 'status' => self::OK, 'message' => '', 'next-step' => 'sample-data', - 'next-step-label' => 'Loading Sample Data', + 'next-step-label' => 'Loading sample data', 'percentage-completed' => 80, ); @@ -268,7 +268,7 @@ class ApplicationInstaller if (!$bLoadData) { $aResult['next-step'] = 'create-config'; - $aResult['next-step-label'] = 'Creating the Configuration File'; + $aResult['next-step-label'] = 'Creating the configuration File'; } break; @@ -291,7 +291,7 @@ class ApplicationInstaller 'status' => self::INFO, 'message' => 'All data loaded', 'next-step' => 'create-config', - 'next-step-label' => 'Creating the Configuration File', + 'next-step-label' => 'Creating the configuration File', 'percentage-completed' => 99, ); break; @@ -401,7 +401,13 @@ class ApplicationInstaller } $sSourcePath = APPROOT.$sSourceDir; + $aDirsToScan = array($sSourcePath); $sExtensionsPath = APPROOT.$sExtensionDir; + if (is_dir($sExtensionsPath)) + { + // if the extensions dir exists, scan it for additional modules as well + $aDirsToScan[] = $sExtensionsPath; + } $sTargetPath = APPROOT.$sTargetDir; if (!is_dir($sSourcePath)) { @@ -421,7 +427,7 @@ class ApplicationInstaller } } - $oFactory = new ModelFactory(array($sSourcePath, $sExtensionsPath)); + $oFactory = new ModelFactory($aDirsToScan); $aModules = $oFactory->FindModules(); foreach($aModules as $foo => $oModule) diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 4758e095b..193604404 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -617,10 +617,10 @@ class SetupUtils $oPage->add(''); if ($bAllowDBCreation) { - $oPage->add(''); - $oPage->add(''); $oPage->add(''); $oPage->add(''); + $oPage->add(''); + $oPage->add(''); $oPage->add(''); } else diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index f04bacc5c..8694cb8ee 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -465,14 +465,7 @@ EOF $sInstalledVersion = $aInstalledInfo['product_version']; $sInstalledDataModelVersion = $aInstalledInfo['datamodel_version']; - - if ($sInstalledDataModelVersion == '$ITOP_VERSION$.$WCREV$') - { - // Special case for upgrading some development versions (temporary) - $sLatestDMDir = SetupUtils::GetLatestDataModelDir(); - $sInstalledDataModelVersion = SetupUtils::GetDataModelVersion($sLatestDMDir); - } - + $oPage->add("

Information about the upgrade from version $sInstalledVersion to ".ITOP_VERSION.'.'.ITOP_REVISION."

"); if ($sInstalledVersion == (ITOP_VERSION.'.'.ITOP_REVISION)) @@ -481,13 +474,25 @@ EOF $bDisplayLicense = false; } $this->oWizard->SetParameter('license', $bDisplayLicense); // Remember for later + + echo "sInstalledDataModelVersion: $sInstalledDataModelVersion"; + if ($sInstalledDataModelVersion == '$ITOP_VERSION$.$WCREV$') + { + // Special case for upgrading some development versions (temporary) + $sCompatibleDMDir = SetupUtils::GetLatestDataModelDir(); + $sInstalledDataModelVersion = SetupUtils::GetDataModelVersion($sLatestDMDir); + } + else + { $sCompatibleDMDir = SetupUtils::GetCompatibleDataModelDir($sInstalledDataModelVersion); + } + if ($sCompatibleDMDir === false) { // No compatible version exists... cannot upgrade. Either it is too old, or too new (downgrade !) $this->bCanMoveForward = false; - $oPage->p("The current version of ".ITOP_APPLICATION." (".ITOP_VERSION.'.'.ITOP_REVISION.") does not sem to be compatible with the installed version ($sInstalledVersion)."); + $oPage->p("The current version of ".ITOP_APPLICATION." (".ITOP_VERSION.'.'.ITOP_REVISION.") does not seem to be compatible with the installed version ($sInstalledVersion)."); $oPage->p("The upgrade cannot continue, sorry."); } else @@ -668,7 +673,7 @@ class WizStepLicense extends WizardStep foreach($aLicenses as $index => $oLicense) { $oPage->add('
  • '.$oLicense->product.', licensed by '.$oLicense->author.' under the '.$oLicense->license_type.' license. (Details)'); - $oPage->add('
  • Use a prefix for the tables:
    '); SetupUtils::DisplayDBParameters($oPage, true, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sNewDBName); $oPage->add('
    '); - $sCreateDB = $this->oWizard->GetParameter('create_db', 'no'); + $sCreateDB = $this->oWizard->GetParameter('create_db', 'yes'); if ($sCreateDB == 'no') { $oPage->add_ready_script('$("#existing_db").attr("checked", "checked");'); @@ -1845,7 +1850,7 @@ EOF if ($sBackupDestination != '') { - $aInstallParams['backup'] = array ( + $aInstallParams['preinstall']['backup'] = array ( 'destination' => $sBackupDestination, 'configuration_file' => $sPreviousConfigurationFile, ); @@ -1973,13 +1978,30 @@ class WizStepDone extends WizardStep $oPage->add("

    Congratulations for installing iTop

    "); $oPage->ok("The installation completed successfully."); } + + if ($this->oWizard->GetParameter('db_backup', false)) + { + $sBackupDestination = $this->oWizard->GetParameter('db_backup_path', ''); + if (file_exists($sBackupDestination)) + { + // To mitigate security risks: pass only the filename without the extension, the download will add the extensino itself + $sTruncatedFilePath = preg_replace('/\.zip$/', '', $sBackupDestination); + $oPage->p('Your backup is ready'); + $oPage->p(' Download '.basename($sBackupDestination).''); + } + else + { + $oPage->p(' Warning: Backup creation failed !'); + } + } + // Form goes here.. No back button since the job is done ! $oPage->add(''); $oPage->add(""); $oPage->add(""); $oPage->add(""); $oPage->add('
    '); - $sForm = '
    '; + $sForm = ''; $sForm .= ''; $sForm .= ''; $sForm .= "

    "; @@ -2007,4 +2029,18 @@ class WizStepDone extends WizardStep return false; //This step executes once the config was written and secured } + public function AsyncAction(WebPage $oPage, $sCode, $aParameters) + { + $oParameters = new PHPParameters(); + // For security reasons: add the extension now so that this action can be used to read *only* .zip files from the disk... + $sBackupFile = $aParameters['backup'].'.zip'; + if (file_exists($sBackupFile)) + { + // Make sure there is NO output at all before our content, otherwise the document will be corrupted + $sPreviousContent = ob_get_clean(); + $oPage->SetContentType('application/zip'); + $oPage->SetContentDisposition('attachment', basename($sBackupFile)); + $oPage->add(file_get_contents($sBackupFile)); + } + } }