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);
 }
示例#2
0
 /**
  * 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;
 }
 public function jobsAction()
 {
     $oWizard = new OX_Admin_UI_Install_Wizard($this->getInstallStatus());
     if ($oWizard->isStep('configuration')) {
         //this will be visible under config wizard entry
         $current = 'configuration';
     } else {
         $current = 'database';
     }
     $this->setCurrentStepIfReachable($oWizard, $current);
     $oUpgrader = $this->getUpgrader();
     $isUpgrade = $this->getInstallStatus()->isUpgrade();
     $oRequest = $this->getRequest();
     $oStorage = OX_Admin_UI_Install_InstallUtils::getSessionStorage();
     if ($oRequest->isGet()) {
         $oStorage->set('aJobStatuses', null);
     }
     if ($oRequest->isPost()) {
         $aJobErrors = $oRequest->getParam('jobError');
         //check if there were any PHP errors when executing jobs
         //these are kind of errros which task and plugin runners might be
         //unable to catch and report in session eg. fatal error, timeout etc.
         if (!empty($aJobErrors)) {
             //push any errors through session so they can be presented in next step
             $aJobStatuses = $oStorage->get('aJobStatuses');
             foreach ($aJobErrors as $id => $errMessage) {
                 $aJobStatuses[$id]['errors'][] = $errMessage;
                 list($type, $name) = explode(':', $id);
                 $aJobStatuses[$id]['name'] = $name;
                 $aJobStatuses[$id]['type'] = $type;
             }
             $oStorage->set('aJobStatuses', $aJobStatuses);
         }
         $this->redirect($oWizard->getNextStep());
     }
     // Perform auto-login at this stage, so that the install-plugin can verify
     if ($this->getInstallStatus()->isInstall()) {
         OA_Upgrade_Login::autoLogin();
     }
     // Use current url as base path for calling install-plugin
     $baseInstallUrl = $this->getRequest()->getBaseUrl();
     //collect tasks
     $aUrls = OX_Upgrade_InstallPlugin_Controller::getTasksUrls($baseInstallUrl);
     $aUrls = array_merge($aUrls, OX_Upgrade_PostUpgradeTask_Controller::getTasksUrls($baseInstallUrl, $oUpgrader));
     $json = new Services_JSON();
     $jsonJobs = $json->encode($aUrls);
     $this->setModelProperty('oWizard', $oWizard);
     $this->setModelProperty('isUpgrade', $isUpgrade);
     $this->setModelProperty('jobs', $jsonJobs);
 }