public function __construct($oInstallStatus, $currentStepId = null) { $oStorage = OX_Admin_UI_Install_InstallUtils::getSessionStorage(); $aSteps = $this->initSteps($oInstallStatus, $oStorage); $aParams = array('steps' => $aSteps['steps'], 'stepsMetadata' => $aSteps['meta'], 'current' => $currentStepId); parent::__construct('install', $aParams, $oStorage); }
function testgetTasksUrls() { // Mock install status to mark update process Mock::generatePartial('OX_Admin_UI_Install_InstallStatus', 'OX_Admin_UI_Install_InstallStatusMock', array('isUpgrade')); $oInstallStatus = new OX_Admin_UI_Install_InstallStatusMock($this); $oInstallStatus->setReturnValue('isUpgrade', true); $oStorage = OX_Admin_UI_Install_InstallUtils::getSessionStorage(); @($oStatus = $oStorage->set('installStatus', $oInstallStatus)); include MAX_PATH . '/etc/default_plugins.php'; // set default plugins as installed except last one foreach ($aDefaultPlugins as $idx => $aPlugin) { $GLOBALS['_MAX']['CONF']['plugins'][$aPlugin['name']] = true; $lastPlugin = $aPlugin['name']; $lastPluginData = $aPlugin; } unset($GLOBALS['_MAX']['CONF']['plugins'][$lastPlugin]); $baseInstallUrl = 'my base url'; $GLOBALS['strPluginTaskChecking'] = 'Checking'; $GLOBALS['strPluginTaskInstalling'] = 'Installing'; $aExpected = array(); foreach ($GLOBALS['_MAX']['CONF']['plugins'] as $pluginName => $pluginEnabled) { $aExpected[] = array('id' => 'plugin:' . $pluginName, 'name' => $GLOBALS['strPluginTaskChecking'] . ': <br/> ' . $this->_correctPluginName($pluginName), 'url' => $baseInstallUrl . 'install-plugin.php?status=1&plugin=' . $pluginName); } $aExpected[] = array('id' => 'plugin:' . $lastPlugin, 'name' => $GLOBALS['strPluginTaskInstalling'] . ': <br/> ' . $this->_correctPluginName($lastPlugin), 'url' => $baseInstallUrl . 'install-plugin.php?status=0&plugin=' . $lastPlugin . (empty($lastPluginData['disabled']) ? '' : '&disabled=1')); $result = OX_Upgrade_InstallPlugin_Controller::getTasksUrls($baseInstallUrl); $this->assertEqual($result, $aExpected); $oStatus = $oStorage->set('installStatus', null); }
function testIsInstallerStepCompleted() { $oStorage = OX_Admin_UI_Install_InstallUtils::getSessionStorage(); $oStatus = $oStorage->set('installStatus', null); $aTask = array('name' => 'test', 'type' => 'testtype'); $result = OX_Upgrade_Util_Job::isInstallerStepCompleted('database', $aTask); $this->assertFalse($result); $this->assertEqual($aTask['errors'], array('Installation process not detected')); unset($aTask['errors']); Mock::generatePartial('OX_Admin_UI_Install_InstallStatus', 'OX_Admin_UI_Install_InstallStatusMock', array('isInstall', 'isUpgrade')); $oInstallStatus = new OX_Admin_UI_Install_InstallStatusMock($this); $oInstallStatus->setReturnValue('isInstall', true); $oInstallStatus->setReturnValue('isUpgrade', false); $oStatus = $oStorage->set('installStatus', $oInstallStatus); $result = OX_Upgrade_Util_Job::isInstallerStepCompleted('database', $aTask); $this->assertFalse($result); $this->assertEqual($aTask['errors'], array('Invalid installation step detected')); unset($aTask['errors']); $oWizard = new OX_Admin_UI_Install_Wizard($oInstallStatus); $oWizard->markStepAsCompleted('database'); $result = OX_Upgrade_Util_Job::isInstallerStepCompleted('database', $aTask); $this->assertTrue($result); $this->assertTrue(empty($aTask['errors'])); $oWizard->reset(); $oStatus = $oStorage->set('installStatus', null); }
/** * Prepare urls to run install plugin tasks * * @param string $baseInstalUrl Base install URL (prepared by * OX_Admin_UI_Controller_Request::getBaseUrl) * @return array Array of arrays of 'id', name' and 'url' strings */ static function getTasksUrls($baseInstallUrl) { $aUrls = array(); $aPluginZips = array(); // Collect all plugin files present in the etc/plugins folder... $PLUGINS_DIR = opendir(MAX_PATH . '/etc/plugins'); while ($file = readdir($PLUGINS_DIR)) { if (substr($file, 0, 1) == '.' || substr($file, strrpos($file, '.')) != '.zip') { continue; } $name = substr($file, 0, strrpos($file, '.')); $aPluginZips[$name] = array('id' => 'plugin:' . $name, 'name' => $GLOBALS['strPluginTaskChecking'] . ': <br/> ' . OX_Upgrade_InstallPlugin_Controller::openxToRevivePluginName($name), 'url' => $baseInstallUrl . 'install-plugin.php?status=0&plugin=' . $name . '&disabled=1'); } closedir($PLUGINS_DIR); // Get installed plugins if upgrade $oStorage = OX_Admin_UI_Install_InstallUtils::getSessionStorage(); $oStatus = $oStorage->get('installStatus'); if (isset($oStatus) && $oStatus->isUpgrade()) { foreach ($GLOBALS['_MAX']['CONF']['plugins'] as $name => $enabled) { if (in_array($name, self::$DEPRECATED_PLUGINS)) { $status = '2'; // Remove plugin; deprecated } else { $status = '1'; // Install or migrate } $displayName = $name; $oPluginManager = new OX_PluginManager(); $aPackageInfo = $oPluginManager->getPackageInfo($name); if ($aPackageInfo['displayname']) { $displayName = $aPackageInfo['displayname']; } $aUrls[] = array('id' => 'plugin:' . $name, 'name' => $GLOBALS['strPluginTaskChecking'] . ': <br/> ' . OX_Upgrade_InstallPlugin_Controller::openxToRevivePluginName($displayName), 'url' => $baseInstallUrl . 'install-plugin.php?status=' . $status . '&plugin=' . $name); unset($aPluginZips[$name]); } } // Get the list of bundled plugins, retain order include MAX_PATH . '/etc/default_plugins.php'; if ($aDefaultPlugins) { foreach ($aDefaultPlugins as $idx => $aPlugin) { if (!array_key_exists($aPlugin['name'], $GLOBALS['_MAX']['CONF']['plugins'])) { $url = $baseInstallUrl . 'install-plugin.php?status=0&plugin=' . $aPlugin['name']; if (!empty($aPlugin['disabled'])) { $url .= '&disabled=1'; } $aUrls[] = array('id' => 'plugin:' . $aPlugin['name'], 'name' => $GLOBALS['strPluginTaskInstalling'] . ': <br/> ' . OX_Upgrade_InstallPlugin_Controller::openxToRevivePluginName($aPlugin['name']), 'url' => $url); unset($aPluginZips[$aPlugin['name']]); } } } // Anything left in the $aPluginsZip array are unknown plugins, should be installed but disabled foreach ($aPluginZips as $pluginName => $pluginArray) { $aUrls[] = $pluginArray; } return $aUrls; }
/** * Check if it's install process and given step is completed * * @param string $step * @param string $result result array (should contains name, type, status and errors fields) * @return bool */ public static function isInstallerStepCompleted($step, &$result) { $oStorage = OX_Admin_UI_Install_InstallUtils::getSessionStorage(); $oStatus = $oStorage->get('installStatus'); if (!isset($oStatus) || !$oStatus->isInstall() && !$oStatus->isUpgrade()) { self::logError($result, 'Installation process not detected'); return false; } else { $oWizard = new OX_Admin_UI_Install_Wizard($oStatus); if (!$oWizard->isStepCompleted($step)) { self::logError($result, 'Invalid installation step detected'); return false; } } return true; }
/** * Process input from user and creates admin saves path in config file * * @param OA_Admin_UI_Component_Form $oForm * @param OX_Admin_UI_Install_Wizard $oWizard */ protected function processConfigurationAction($oForm, $oWizard, $isUpgrade) { if ($isUpgrade) { $aConfig['config'] = $this->getUpgrader()->getConfig(); $aUpgradeConfig = $oForm->populateConfig(); //not much here, just previous path $previousInstallationPath = $aUpgradeConfig['config']['previousInstallationPath']; } else { $aConfig = $oForm->populateConfig(); } $oUpgrader = $this->getUpgrader(); $isUpgrade = $this->getInstallStatus()->isUpgrade(); $configStepSuccess = true; $syncEnabled = true; // 1) Import any plugins present from the previous install $path = isset($previousInstallationPath) ? $previousInstallationPath : ''; $path = get_magic_quotes_gpc() ? stripslashes($path) : $path; if ($path && $path != MAX_PATH) { $importOK = OX_Admin_UI_Install_InstallUtils::importPlugins($path); if (!$importOK) { $errMessage = $GLOBALS['strPathToPreviousError']; $configStepSuccess = false; } } // 2) Save config (if previous task was fine) if ($configStepSuccess) { if ($oUpgrader->saveConfig($aConfig['config'])) { $configStepSuccess = true; if (!OX_Admin_UI_Install_InstallUtils::checkFolderPermissions($aConfig['config']['store']['webDir'])) { $errMessage = $GLOBALS['strImageDirLockedDetected']; $configStepSuccess = false; } } else { if ($isUpgrade) { $errMessage = $GLOBALS['strUnableUpdateConfFile']; } else { $errMessage = $GLOBALS['strUnableCreateConfFile']; } } } //3) config saved, go ahead and save admin when new install if ($configStepSuccess && !$isUpgrade) { OA_Permission::switchToSystemProcessUser('Installer'); // we set the default from: in OpenX emails to the administrator's email if (empty($GLOBALS['_MAX']['CONF']['email']['fromAddress'])) { $oUpgrader->oConfiguration->setValue('email', 'fromAddress', $aConfig['admin']['email']); $oUpgrader->oConfiguration->writeConfig(true); } // Save admin credentials $adminSaved = $oUpgrader->putAdmin($aConfig['admin'], $aConfig['prefs']); if (!$adminSaved) { $errMessage = $GLOBALS['strUnableToCreateAdmin']; $configStepSuccess = false; } OA_Permission::switchToSystemProcessUser(); //get back to normal user previously logged in } $configStepSuccess = $configStepSuccess && empty($errMessage); if ($errMessage) { $this->setModelProperty('aMessages', array('error' => array($errMessage))); } return $configStepSuccess; }