diff --git a/copy_this/application/commands/fixstatescommand.php b/copy_this/application/commands/fixstatescommand.php index 442dd7b..2f657e8 100644 --- a/copy_this/application/commands/fixstatescommand.php +++ b/copy_this/application/commands/fixstatescommand.php @@ -15,11 +15,6 @@ class FixStatesCommand extends oxConsoleCommand { - /** - * @var array|null Available module ids - */ - protected $_aAvailableModuleIds = null; - /** * {@inheritdoc} */ @@ -56,7 +51,6 @@ public function execute(oxIOutput $oOutput) : $oOutput; try { - $aModuleIds = $this->_parseModuleIds(); $aShopConfigs = $this->_parseShopConfigs(); } catch (oxInputException $oEx) { $oOutput->writeLn($oEx->getMessage()); @@ -67,8 +61,15 @@ public function execute(oxIOutput $oOutput) $oStateFixerModule = oxNew('oxStateFixerModule'); foreach ($aShopConfigs as $oConfig) { - - $oDebugOutput->writeLn('[DEBUG] Working on shop id ' . $oConfig->getShopId()); + try { + $aModuleIds = $this->_parseModuleIds($oConfig); + } catch (oxInputException $oEx) { + $oOutput->writeLn($oEx->getMessage()); + return; + } + $sShopId = $oConfig->getShopId(); + $oDebugOutput->writeLn('[DEBUG] Working on shop id ' . $sShopId); + $oStateFixerModule->setConfig($oConfig); foreach ($aModuleIds as $sModuleId) { if (!$oStateFixerModule->load($sModuleId)) { @@ -78,7 +79,6 @@ public function execute(oxIOutput $oOutput) $oDebugOutput->writeLn("[DEBUG] Fixing {$sModuleId} module"); - $oStateFixerModule->setConfig($oConfig); $oStateFixerModule->fixVersion(); $oStateFixerModule->fixExtendGently(); $oStateFixerModule->fixFiles(); @@ -101,12 +101,12 @@ public function execute(oxIOutput $oOutput) * * @throws oxInputException */ - protected function _parseModuleIds() + protected function _parseModuleIds($oConfig) { $oInput = $this->getInput(); if ($oInput->hasOption(array('a', 'all'))) { - return $this->_getAvailableModuleIds(); + return $this->_getAvailableModuleIds($oConfig); } if (count($oInput->getArguments()) < 2) { // Note: first argument is command name @@ -119,7 +119,7 @@ protected function _parseModuleIds() $aModuleIds = $oInput->getArguments(); array_shift($aModuleIds); // Getting rid of command name argument - $aAvailableModuleIds = $this->_getAvailableModuleIds(); + $aAvailableModuleIds = $this->_getAvailableModuleIds($oConfig); // Checking if all provided module ids exist foreach ($aModuleIds as $sModuleId) { @@ -177,19 +177,15 @@ protected function _parseShopConfigs() * * @return array */ - protected function _getAvailableModuleIds() + protected function _getAvailableModuleIds($oConfig) { - if ($this->_aAvailableModuleIds === null) { - $oConfig = oxRegistry::getConfig(); - - // We are calling getModulesFromDir() because we want to refresh - // the list of available modules. This is a workaround for OXID - // bug. - oxNew('oxModuleList')->getModulesFromDir($oConfig->getModulesDir()); - - $this->_aAvailableModuleIds = array_keys($oConfig->getConfigParam('aModulePaths')); - } - - return $this->_aAvailableModuleIds; + // We are calling getModulesFromDir() because we want to refresh + // the list of available modules. This is a workaround for OXID + // bug. + $oModuleList = oxNew('oxModuleList'); + $oModuleList->setConfig($oConfig); + $oModuleList->getModulesFromDir($oConfig->getModulesDir()); + + return array_keys($oConfig->getConfigParam('aModulePaths')); } }