From e5e089f59347b7606f4a2dfa0e42b594135486ff Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Thu, 22 Aug 2024 11:20:09 +0200 Subject: [PATCH] Removed Magento 2 code (#1462) --- src/N98/Magento/Application.php | 68 +--------------- .../Command/AbstractMagentoCommand.php | 79 ++++--------------- .../Admin/User/AbstractAdminUserCommand.php | 6 +- .../Command/Admin/User/CreateUserCommand.php | 17 +--- .../Command/Cache/AbstractCacheCommand.php | 14 +--- .../Magento/Command/Cms/Block/ListCommand.php | 2 +- .../Command/Cms/Block/ToggleCommand.php | 2 +- .../Command/Config/AbstractConfigCommand.php | 13 +-- .../Customer/AbstractCustomerCommand.php | 19 ++--- .../Developer/Ide/PhpStorm/MetaCommand.php | 35 ++++---- .../Setup/Script/AttributeCommand.php | 7 +- .../Developer/Theme/DuplicatesCommand.php | 42 +++++----- .../Command/Developer/Theme/ListCommand.php | 10 --- .../Indexer/AbstractMviewIndexerCommand.php | 7 +- .../System/Setup/ChangeVersionCommand.php | 2 +- .../System/Setup/CompareVersionsCommand.php | 2 +- .../Command/System/Setup/RemoveCommand.php | 2 +- src/N98/Util/Console/Helper/MagentoHelper.php | 15 +--- .../Command/Cache/CleanCommandTest.php | 4 - .../Command/Cache/DisableCommandTest.php | 34 ++++---- .../Command/Cache/EnableCommandTest.php | 34 ++++---- .../Command/Cache/FlushCommandTest.php | 13 ++- .../Command/Customer/DeleteCommandTest.php | 26 ++---- .../System/Setup/RemoveCommandTest.php | 6 +- tests/N98/Magento/TestApplication.php | 4 +- .../N98/Util/Console/Helper/MagentoHelper.php | 26 ------ 26 files changed, 127 insertions(+), 362 deletions(-) diff --git a/src/N98/Magento/Application.php b/src/N98/Magento/Application.php index 61ca0e46d..f1007c4c4 100644 --- a/src/N98/Magento/Application.php +++ b/src/N98/Magento/Application.php @@ -46,16 +46,6 @@ class Application extends BaseApplication */ public const APP_VERSION = '3.0.0-dev'; - /** - * @var int - */ - public const MAGENTO_MAJOR_VERSION_1 = 1; - - /** - * @var int - */ - public const MAGENTO_MAJOR_VERSION_2 = 2; - /** * @var string */ @@ -104,12 +94,7 @@ class Application extends BaseApplication /** * @var int */ - protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_1; - - /** - * @var EntryPoint - */ - protected $_magento2EntryPoint = null; + protected $_magentoMajorVersion = 1; /** * @var bool @@ -465,12 +450,7 @@ public function initMagento($soft = false) return false; } - $isMagento2 = $this->_magentoMajorVersion === self::MAGENTO_MAJOR_VERSION_2; - if ($isMagento2) { - $this->_initMagento2(); - } else { - $this->_initMagento1($soft); - } + $this->_initMagento1($soft); return true; } @@ -791,50 +771,6 @@ protected function _initMagento1($soft = false) } } - /** - * @return void - */ - protected function _initMagento2() - { - $this->outputMagerunCompatibilityNotice('2'); - } - - /** - * Show a hint that this is Magento incompatible with Magerun and how to obtain the correct Magerun for it - * - * @param string $version of Magento, "1" or "2", that is incompatible - */ - private function outputMagerunCompatibilityNotice($version) - { - $file = $version === '2' ? $version : ''; - $magentoHint = <<Download with curl ------------------- - - curl -O https://files.magerun.net/n98-magerun$file.phar - -Download with wget ------------------- - - wget https://files.magerun.net/n98-magerun$file.phar - -MAGENTOHINT; - - $output = new ConsoleOutput(); - - /** @var FormatterHelper $formatter */ - $formatter = $this->getHelperSet()->get('formatter'); - - $output->writeln(['', $formatter->formatBlock('Compatibility Notice', 'bg=blue;fg=white', true), '', $magentoHint]); - - throw new RuntimeException('This version of n98-magerun is not compatible with Magento ' . $version); - } - /** * @return EventDispatcher */ diff --git a/src/N98/Magento/Command/AbstractMagentoCommand.php b/src/N98/Magento/Command/AbstractMagentoCommand.php index 60ff7c702..72307ab65 100644 --- a/src/N98/Magento/Command/AbstractMagentoCommand.php +++ b/src/N98/Magento/Command/AbstractMagentoCommand.php @@ -11,6 +11,7 @@ use Composer\Package\PackageInterface; use InvalidArgumentException; use Mage; +use Mage_Core_Model_Abstract; use N98\Magento\Application; use N98\Magento\Command\SubCommand\ConfigBag; use N98\Magento\Command\SubCommand\SubCommandFactory; @@ -38,16 +39,6 @@ */ abstract class AbstractMagentoCommand extends Command { - /** - * @var int - */ - public const MAGENTO_MAJOR_VERSION_1 = 1; - - /** - * @var int - */ - public const MAGENTO_MAJOR_VERSION_2 = 2; - /** * @var string */ @@ -56,7 +47,7 @@ abstract class AbstractMagentoCommand extends Command /** * @var int */ - protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_1; + protected $_magentoMajorVersion = 1; /** * @var bool @@ -219,9 +210,6 @@ protected function requireEnterprise(OutputInterface $output) */ protected function getCoreHelper() { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - return Mage::helper('Mage_Core_Helper_Data'); - } return Mage::helper('core'); } @@ -375,83 +363,48 @@ protected function checkDeprecatedAliases(InputInterface $input, OutputInterface } /** - * Magento 1 / 2 switches - * * @param string $mage1code Magento 1 class code - * @param string $mage2class Magento 2 class name - * @return \Mage_Core_Model_Abstract + * @return Mage_Core_Model_Abstract */ - protected function _getModel($mage1code, $mage2class) + protected function _getModel($mage1code) { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - return Mage::getModel($mage2class); - } else { - return Mage::getModel($mage1code); - } + return Mage::getModel($mage1code); } /** - * Magento 1 / 2 switches - * * @param string $mage1code Magento 1 class code - * @param string $mage2class Magento 2 class name * @return \Mage_Core_Helper_Abstract */ - protected function _getHelper($mage1code, $mage2class) + protected function _getHelper($mage1code) { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - return Mage::helper($mage2class); - } else { - return Mage::helper($mage1code); - } + return Mage::helper($mage1code); } /** - * Magento 1 / 2 switches - * * @param string $mage1code Magento 1 class code - * @param string $mage2class Magento 2 class name - * @return \Mage_Core_Model_Abstract + * @return Mage_Core_Model_Abstract */ - protected function _getSingleton($mage1code, $mage2class) + protected function _getSingleton($mage1code) { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - return Mage::getModel($mage2class); - } else { - return Mage::getModel($mage1code); - } + return Mage::getModel($mage1code); } /** - * Magento 1 / 2 switches - * * @param string $mage1code Magento 1 class code - * @param string $mage2class Magento 2 class name - * @return \Mage_Core_Model_Abstract + * @return Mage_Core_Model_Abstract */ - protected function _getResourceModel($mage1code, $mage2class) + protected function _getResourceModel($mage1code) { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - return Mage::getResourceModel($mage2class); - } else { - return Mage::getResourceModel($mage1code); - } + return Mage::getResourceModel($mage1code); } /** - * Magento 1 / 2 switches - * * @param string $mage1code Magento 1 class code - * @param string $mage2class Magento 2 class name - * @return \Mage_Core_Model_Abstract + * @return Mage_Core_Model_Abstract */ - protected function _getResourceSingleton($mage1code, $mage2class) + protected function _getResourceSingleton($mage1code) { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - return Mage::getResourceSingleton($mage2class); - } else { - return Mage::getResourceSingleton($mage1code); - } + return Mage::getResourceSingleton($mage1code); } /** diff --git a/src/N98/Magento/Command/Admin/User/AbstractAdminUserCommand.php b/src/N98/Magento/Command/Admin/User/AbstractAdminUserCommand.php index 699b5e471..1d09cf3ed 100644 --- a/src/N98/Magento/Command/Admin/User/AbstractAdminUserCommand.php +++ b/src/N98/Magento/Command/Admin/User/AbstractAdminUserCommand.php @@ -16,7 +16,7 @@ abstract class AbstractAdminUserCommand extends AbstractMagentoCommand */ protected function getUserModel() { - return $this->_getModel('admin/user', 'Mage_User_Model_User'); + return $this->_getModel('admin/user'); } /** @@ -24,7 +24,7 @@ protected function getUserModel() */ protected function getRoleModel() { - return $this->_getModel('admin/roles', 'Mage_User_Model_Role'); + return $this->_getModel('admin/roles'); } /** @@ -32,6 +32,6 @@ protected function getRoleModel() */ protected function getRulesModel() { - return $this->_getModel('admin/rules', 'Mage_User_Model_Rules'); + return $this->_getModel('admin/rules'); } } diff --git a/src/N98/Magento/Command/Admin/User/CreateUserCommand.php b/src/N98/Magento/Command/Admin/User/CreateUserCommand.php index 19f7950c1..5bb0cdce3 100644 --- a/src/N98/Magento/Command/Admin/User/CreateUserCommand.php +++ b/src/N98/Magento/Command/Admin/User/CreateUserCommand.php @@ -64,14 +64,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int ->setRoleType('G') ->save(); - // @todo check cmuench correct class name? - $resourceAll = ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) ? - Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL : 'all'; - // give "all" privileges to role $this->getRulesModel() ->setRoleId($role->getId()) - ->setResources([$resourceAll]) + ->setResources(['all']) ->saveRel(); $output->writeln('The role Development was automatically created.'); @@ -82,14 +78,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $user = $this->getUserModel() ->setData(['username' => $username, 'firstname' => $firstname, 'lastname' => $lastname, 'email' => $email, 'password' => $password, 'is_active' => 1])->save(); - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - $user->setRoleId($role->getId()) - ->save(); - } else { - $user->setRoleIds([$role->getId()]) - ->setRoleUserId($user->getUserId()) - ->saveRelations(); - } + $user->setRoleIds([$role->getId()]) + ->setRoleUserId($user->getUserId()) + ->saveRelations(); $output->writeln('User ' . $username . ' successfully created'); } diff --git a/src/N98/Magento/Command/Cache/AbstractCacheCommand.php b/src/N98/Magento/Command/Cache/AbstractCacheCommand.php index fea8254d2..226793fec 100644 --- a/src/N98/Magento/Command/Cache/AbstractCacheCommand.php +++ b/src/N98/Magento/Command/Cache/AbstractCacheCommand.php @@ -23,11 +23,7 @@ class AbstractCacheCommand extends AbstractMagentoCommand */ protected function _getCacheModel() { - if ($this->_magentoMajorVersion == AbstractMagentoCommand::MAGENTO_MAJOR_VERSION_2) { - throw new RuntimeException('There global Mage class was removed from Magento 2. What should we do here?'); - } else { - return Mage::app()->getCacheInstance(); - } + return Mage::app()->getCacheInstance(); } /** @@ -98,12 +94,4 @@ protected function _canUseBanCacheFunction() { return method_exists('\Mage_Core_Model_App', 'baseInit'); } - - /** - * @return bool - */ - public function isEnabled() - { - return $this->getApplication()->getMagentoMajorVersion() === Application::MAGENTO_MAJOR_VERSION_1; - } } diff --git a/src/N98/Magento/Command/Cms/Block/ListCommand.php b/src/N98/Magento/Command/Cms/Block/ListCommand.php index 13feaba95..529840d17 100644 --- a/src/N98/Magento/Command/Cms/Block/ListCommand.php +++ b/src/N98/Magento/Command/Cms/Block/ListCommand.php @@ -32,7 +32,7 @@ protected function configure() */ protected function _getBlockModel() { - return $this->_getModel('cms/block', '\Mage_Cms_Model_Block'); + return $this->_getModel('cms/block'); } /** diff --git a/src/N98/Magento/Command/Cms/Block/ToggleCommand.php b/src/N98/Magento/Command/Cms/Block/ToggleCommand.php index a228aa1a6..e742907fa 100644 --- a/src/N98/Magento/Command/Cms/Block/ToggleCommand.php +++ b/src/N98/Magento/Command/Cms/Block/ToggleCommand.php @@ -33,7 +33,7 @@ protected function configure() */ protected function _getBlockModel() { - return $this->_getModel('cms/block', '\Mage_Cms_Model_Block'); + return $this->_getModel('cms/block'); } /** diff --git a/src/N98/Magento/Command/Config/AbstractConfigCommand.php b/src/N98/Magento/Command/Config/AbstractConfigCommand.php index 941b63e99..d373c074b 100644 --- a/src/N98/Magento/Command/Config/AbstractConfigCommand.php +++ b/src/N98/Magento/Command/Config/AbstractConfigCommand.php @@ -21,16 +21,11 @@ abstract class AbstractConfigCommand extends AbstractMagentoCommand protected $_scopes = ['default', 'websites', 'stores']; /** - * @return \Mage_Core_Model_Encryption|null returns null for Magento2 + * @return \Mage_Core_Model_Encryption */ protected function getEncryptionModel() { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - // @TODO Magento 2 support - return null; - } else { - return Mage::helper('core')->getEncryptor(); - } + return Mage::helper('core')->getEncryptor(); } /** @@ -38,7 +33,7 @@ protected function getEncryptionModel() */ protected function _getConfigDataModel() { - return $this->_getModel('core/config_data', 'Mage_Core_Model_Config_Data'); + return $this->_getModel('core/config_data'); } /** @@ -154,6 +149,6 @@ private function invalidScopeId($condition, $mask, $scopeId) */ protected function _getConfigModel() { - return $this->_getModel('core/config', 'Mage_Core_Model_Config'); + return $this->_getModel('core/config'); } } diff --git a/src/N98/Magento/Command/Customer/AbstractCustomerCommand.php b/src/N98/Magento/Command/Customer/AbstractCustomerCommand.php index 0b1a3d2cd..c3af858ed 100644 --- a/src/N98/Magento/Command/Customer/AbstractCustomerCommand.php +++ b/src/N98/Magento/Command/Customer/AbstractCustomerCommand.php @@ -21,7 +21,7 @@ abstract class AbstractCustomerCommand extends AbstractMagentoCommand */ protected function getCustomerModel() { - return $this->_getModel('customer/customer', 'Mage_Customer_Model_Customer'); + return $this->_getModel('customer/customer'); } /** @@ -29,10 +29,7 @@ protected function getCustomerModel() */ protected function getCustomerCollection() { - return $this->_getResourceModel( - 'customer/customer_collection', - 'Mage_Customer_Model_Resource_Customer_Collection' - ); + return $this->_getResourceModel('customer/customer_collection'); } /** @@ -40,7 +37,7 @@ protected function getCustomerCollection() */ protected function getAddressModel() { - return $this->_getModel('customer/address', 'Mage_Customer_Model_Address'); + return $this->_getModel('customer/address'); } /** @@ -48,10 +45,7 @@ protected function getAddressModel() */ protected function getRegionCollection() { - return $this->_getResourceModel( - 'directory/region_collection', - 'Mage_Directory_Model_Resource_Region_Collection' - ); + return $this->_getResourceModel('directory/region_collection'); } /** @@ -59,9 +53,6 @@ protected function getRegionCollection() */ protected function getCountryCollection() { - return $this->_getResourceModel( - 'directory/country_collection', - 'Mage_Directory_Model_Resource_Country_Collection' - ); + return $this->_getResourceModel('directory/country_collection'); } } diff --git a/src/N98/Magento/Command/Developer/Ide/PhpStorm/MetaCommand.php b/src/N98/Magento/Command/Developer/Ide/PhpStorm/MetaCommand.php index 6038534f0..1a49e278b 100644 --- a/src/N98/Magento/Command/Developer/Ide/PhpStorm/MetaCommand.php +++ b/src/N98/Magento/Command/Developer/Ide/PhpStorm/MetaCommand.php @@ -78,30 +78,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_1) { - $classMaps = []; + $classMaps = []; - foreach ($this->groups as $group) { - $classMaps[$group] = $this->getClassMapForGroup($group, $output); + foreach ($this->groups as $group) { + $classMaps[$group] = $this->getClassMapForGroup($group, $output); - if (!$input->getOption('stdout') && count($classMaps[$group]) > 0) { - $output->writeln( - 'Generated definitions for ' . $group . ' group' - ); - } + if (!$input->getOption('stdout') && count($classMaps[$group]) > 0) { + $output->writeln( + 'Generated definitions for ' . $group . ' group' + ); } + } - $version = $input->getOption('meta-version'); - if ($version == self::VERSION_OLD) { - $this->writeToOutputOld($input, $output, $classMaps); - } elseif ($version == self::VERSION_2017) { - $this->writeToOutputV2017($input, $output, $classMaps); - } elseif ($version == self::VERSION_2019) { - $this->writeToOutputV2019($input, $output, $classMaps); - } - } else { - $output->write('Magento 2 is currently not supported'); + $version = $input->getOption('meta-version'); + if ($version == self::VERSION_OLD) { + $this->writeToOutputOld($input, $output, $classMaps); + } elseif ($version == self::VERSION_2017) { + $this->writeToOutputV2017($input, $output, $classMaps); + } elseif ($version == self::VERSION_2019) { + $this->writeToOutputV2019($input, $output, $classMaps); } + return 0; } diff --git a/src/N98/Magento/Command/Developer/Setup/Script/AttributeCommand.php b/src/N98/Magento/Command/Developer/Setup/Script/AttributeCommand.php index ac337677d..e4c2e9e25 100644 --- a/src/N98/Magento/Command/Developer/Setup/Script/AttributeCommand.php +++ b/src/N98/Magento/Command/Developer/Setup/Script/AttributeCommand.php @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $generator = Factory::create($entityType, $attribute); $generator->setReadConnection( - $this->_getModel('core/resource', 'Mage_Core_Model_Resource')->getConnection('core_read') + $this->_getModel('core/resource')->getConnection('core_read') ); $code = $generator->generateCode(); $warnings = $generator->getWarnings(); @@ -75,9 +75,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int */ protected function getAttribute($entityType, $attributeCode) { - $attribute = $this->_getModel('catalog/resource_eav_attribute', 'Mage_Catalog_Model_Resource_Eav_Attribute') - ->loadByCode($entityType, $attributeCode); - - return $attribute; + return $this->_getModel('catalog/resource_eav_attribute')->loadByCode($entityType, $attributeCode); } } diff --git a/src/N98/Magento/Command/Developer/Theme/DuplicatesCommand.php b/src/N98/Magento/Command/Developer/Theme/DuplicatesCommand.php index 72565a8b2..bee02cc7a 100644 --- a/src/N98/Magento/Command/Developer/Theme/DuplicatesCommand.php +++ b/src/N98/Magento/Command/Developer/Theme/DuplicatesCommand.php @@ -59,35 +59,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $time = microtime(true); $this->detectMagento($output); - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - $output->writeln('Magento 2 is currently not supported.'); - } else { - $referenceFiles = $this->getChecksums( - $this->_magentoRootFolder . '/app/design/frontend/' . $input->getArgument('originalTheme') - ); - $themeFolder = $this->_magentoRootFolder . '/app/design/frontend/' . $input->getArgument('theme'); - $themeFiles = $this->getChecksums($themeFolder); + $referenceFiles = $this->getChecksums( + $this->_magentoRootFolder . '/app/design/frontend/' . $input->getArgument('originalTheme') + ); + + $themeFolder = $this->_magentoRootFolder . '/app/design/frontend/' . $input->getArgument('theme'); + $themeFiles = $this->getChecksums($themeFolder); - $duplicates = []; - foreach ($themeFiles as $themeFilename => $themeFileChecksum) { - if (isset($referenceFiles[$themeFilename]) - && $themeFileChecksum == $referenceFiles[$themeFilename] - ) { - $duplicates[] = $themeFolder . '/' . $themeFilename; - } + $duplicates = []; + foreach ($themeFiles as $themeFilename => $themeFileChecksum) { + if (isset($referenceFiles[$themeFilename]) + && $themeFileChecksum == $referenceFiles[$themeFilename] + ) { + $duplicates[] = $themeFolder . '/' . $themeFilename; } + } - if ($input->getOption('log-junit')) { - $this->logJUnit($input, $duplicates, $input->getOption('log-junit'), microtime($time) - $time); + if ($input->getOption('log-junit')) { + $this->logJUnit($input, $duplicates, $input->getOption('log-junit'), microtime($time) - $time); + } else { + if (count($duplicates) === 0) { + $output->writeln('No duplicates were found'); } else { - if (count($duplicates) === 0) { - $output->writeln('No duplicates were found'); - } else { - $output->writeln($duplicates); - } + $output->writeln($duplicates); } } + return 0; } diff --git a/src/N98/Magento/Command/Developer/Theme/ListCommand.php b/src/N98/Magento/Command/Developer/Theme/ListCommand.php index 3230d76ff..03f96a189 100644 --- a/src/N98/Magento/Command/Developer/Theme/ListCommand.php +++ b/src/N98/Magento/Command/Developer/Theme/ListCommand.php @@ -55,16 +55,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int */ protected function getThemes() { - if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) { - $collection = Mage::getModel('Mage_Core_Model_Theme')->getLabelsCollection(); - $themes = []; - foreach ($collection as $theme) { - $themes[] = $theme['label']; - } - - return [$themes]; - } - return Mage::getModel('core/design_package')->getThemeList(); } } diff --git a/src/N98/Magento/Command/Indexer/AbstractMviewIndexerCommand.php b/src/N98/Magento/Command/Indexer/AbstractMviewIndexerCommand.php index d8862ad1f..026c9347f 100644 --- a/src/N98/Magento/Command/Indexer/AbstractMviewIndexerCommand.php +++ b/src/N98/Magento/Command/Indexer/AbstractMviewIndexerCommand.php @@ -24,8 +24,7 @@ public function isEnabled() */ public function getMetaDataCollection() { - $collection = $this->_getModel('enterprise_mview/metadata', '\Enterprise_Mview_Model_Resource_Metadata_Collection')->getCollection(); - return $collection; + return $this->_getModel('enterprise_mview/metadata')->getCollection(); } /** @@ -34,7 +33,7 @@ public function getMetaDataCollection() protected function getIndexers() { /** @var \Enterprise_Index_Helper_Data $helper */ - $helper = $this->_getHelper('enterprise_index', '\Enterprise_Index_Helper_Data'); + $helper = $this->_getHelper('enterprise_index'); $indexers = []; foreach ($helper->getIndexers(true) as $indexer) { @@ -55,6 +54,6 @@ protected function getIndexers() */ protected function getMviewClient() { - return $this->_getModel('enterprise_mview/client', '\Enterprise_Mview_Model_Client'); + return $this->_getModel('enterprise_mview/client'); } } diff --git a/src/N98/Magento/Command/System/Setup/ChangeVersionCommand.php b/src/N98/Magento/Command/System/Setup/ChangeVersionCommand.php index 58c081e22..0a5c9c134 100644 --- a/src/N98/Magento/Command/System/Setup/ChangeVersionCommand.php +++ b/src/N98/Magento/Command/System/Setup/ChangeVersionCommand.php @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int */ public function updateSetupResource($moduleName, $setupResource, $version, OutputInterface $output) { - $resourceModel = $this->_getResourceSingleton('core/resource', 'Mage_Core_Model_Resource_Resource'); + $resourceModel = $this->_getResourceSingleton('core/resource'); $resourceModel->setDbVersion($setupResource, $version); $resourceModel->setDataVersion($setupResource, $version); diff --git a/src/N98/Magento/Command/System/Setup/CompareVersionsCommand.php b/src/N98/Magento/Command/System/Setup/CompareVersionsCommand.php index c66f17d8f..4fda2aa9f 100644 --- a/src/N98/Magento/Command/System/Setup/CompareVersionsCommand.php +++ b/src/N98/Magento/Command/System/Setup/CompareVersionsCommand.php @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $time = microtime(true); $modules = Mage::getConfig()->getNode('modules'); - $resourceModel = $this->_getResourceSingleton('core/resource', 'Mage_Core_Model_Resource_Resource'); + $resourceModel = $this->_getResourceSingleton('core/resource'); $setups = Mage::getConfig()->getNode('global/resources')->children(); $ignoreDataUpdate = $input->getOption('ignore-data'); diff --git a/src/N98/Magento/Command/System/Setup/RemoveCommand.php b/src/N98/Magento/Command/System/Setup/RemoveCommand.php index 06f58489e..ebbf50e3e 100644 --- a/src/N98/Magento/Command/System/Setup/RemoveCommand.php +++ b/src/N98/Magento/Command/System/Setup/RemoveCommand.php @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int public function removeSetupResource($moduleName, $setupResource, OutputInterface $output) { /** @var Mage_Core_Model_Resource $model */ - $model = $this->_getModel('core/resource', 'Mage_Core_Model_Resource'); + $model = $this->_getModel('core/resource'); $writeAdapter = $model->getConnection('core_write'); if (!$writeAdapter) { throw new RuntimeException('Database not configured'); diff --git a/src/N98/Util/Console/Helper/MagentoHelper.php b/src/N98/Util/Console/Helper/MagentoHelper.php index 18d2e9300..387d6d85e 100644 --- a/src/N98/Util/Console/Helper/MagentoHelper.php +++ b/src/N98/Util/Console/Helper/MagentoHelper.php @@ -26,7 +26,7 @@ class MagentoHelper extends AbstractHelper /** * @var int */ - protected $_magentoMajorVersion = Application::MAGENTO_MAJOR_VERSION_1; + protected $_magentoMajorVersion = 1; /** * @var bool @@ -311,21 +311,8 @@ protected function _search($searchFolder) $files = iterator_to_array($finder, false); /* @var \SplFileInfo $file */ - $hasMageFile = false; - foreach ($files as $file) { - if ($file->getFilename() === 'Mage.php') { - $hasMageFile = true; - } - } - $this->_magentoRootFolder = $searchFolder; - // Magento 2 does not have a god class and thus if this file is not there it is version 2 - if ($hasMageFile === false) { - $this->_magentoMajorVersion = Application::MAGENTO_MAJOR_VERSION_2; - return true; // the rest of this does not matter since we are simply exiting with a notice - } - if (is_callable(['\Mage', 'getEdition'])) { $this->_magentoEnterprise = (Mage::getEdition() == 'Enterprise'); } else { diff --git a/tests/N98/Magento/Command/Cache/CleanCommandTest.php b/tests/N98/Magento/Command/Cache/CleanCommandTest.php index de1c4b3b3..92c1945c0 100644 --- a/tests/N98/Magento/Command/Cache/CleanCommandTest.php +++ b/tests/N98/Magento/Command/Cache/CleanCommandTest.php @@ -19,10 +19,6 @@ public function getApplication() { $application = parent::getApplication(); - if ($application::MAGENTO_MAJOR_VERSION_1 !== $application->getMagentoMajorVersion()) { - return $application; - } - // FIXME #613 make install command work with 1.9+ and cache initialization $version = Mage::getVersion(); $against = '1.9.0.0'; diff --git a/tests/N98/Magento/Command/Cache/DisableCommandTest.php b/tests/N98/Magento/Command/Cache/DisableCommandTest.php index 5e1200aed..e5cdca618 100644 --- a/tests/N98/Magento/Command/Cache/DisableCommandTest.php +++ b/tests/N98/Magento/Command/Cache/DisableCommandTest.php @@ -11,31 +11,27 @@ class DisableCommandTest extends TestCase public function testExecute() { $application = $this->getApplication(); - if ($application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) { - $application->add(new DisableCommand()); + $application->add(new DisableCommand()); - $command = $this->getApplication()->find('cache:disable'); - $commandTester = new CommandTester($command); - $commandTester->execute(['command' => $command->getName()]); + $command = $this->getApplication()->find('cache:disable'); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName()]); - self::assertMatchesRegularExpression('/Caches disabled/', $commandTester->getDisplay()); - } + self::assertMatchesRegularExpression('/Caches disabled/', $commandTester->getDisplay()); } public function testExecuteMultipleCaches() { $application = $this->getApplication(); - if ($application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) { - $application->add(new DisableCommand()); - - $command = $this->getApplication()->find('cache:disable'); - $commandTester = new CommandTester($command); - $commandTester->execute( - ['command' => $command->getName(), 'code' => 'eav,config'] - ); - - self::assertMatchesRegularExpression('/Cache config disabled/', $commandTester->getDisplay()); - self::assertMatchesRegularExpression('/Cache eav disabled/', $commandTester->getDisplay()); - } + $application->add(new DisableCommand()); + + $command = $this->getApplication()->find('cache:disable'); + $commandTester = new CommandTester($command); + $commandTester->execute( + ['command' => $command->getName(), 'code' => 'eav,config'] + ); + + self::assertMatchesRegularExpression('/Cache config disabled/', $commandTester->getDisplay()); + self::assertMatchesRegularExpression('/Cache eav disabled/', $commandTester->getDisplay()); } } diff --git a/tests/N98/Magento/Command/Cache/EnableCommandTest.php b/tests/N98/Magento/Command/Cache/EnableCommandTest.php index b50ef1656..0cb85aa45 100644 --- a/tests/N98/Magento/Command/Cache/EnableCommandTest.php +++ b/tests/N98/Magento/Command/Cache/EnableCommandTest.php @@ -11,31 +11,27 @@ class EnableCommandTest extends TestCase public function testExecute() { $application = $this->getApplication(); - if ($application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) { - $application->add(new EnableCommand()); - $command = $this->getApplication()->find('cache:enable'); + $application->add(new EnableCommand()); + $command = $this->getApplication()->find('cache:enable'); - $commandTester = new CommandTester($command); - $commandTester->execute(['command' => $command->getName()]); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName()]); - self::assertMatchesRegularExpression('/Caches enabled/', $commandTester->getDisplay()); - } + self::assertMatchesRegularExpression('/Caches enabled/', $commandTester->getDisplay()); } public function testExecuteMultipleCaches() { $application = $this->getApplication(); - if ($application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) { - $application->add(new DisableCommand()); - - $command = $this->getApplication()->find('cache:enable'); - $commandTester = new CommandTester($command); - $commandTester->execute( - ['command' => $command->getName(), 'code' => 'eav,config'] - ); - - self::assertMatchesRegularExpression('/Cache config enabled/', $commandTester->getDisplay()); - self::assertMatchesRegularExpression('/Cache eav enabled/', $commandTester->getDisplay()); - } + $application->add(new DisableCommand()); + + $command = $this->getApplication()->find('cache:enable'); + $commandTester = new CommandTester($command); + $commandTester->execute( + ['command' => $command->getName(), 'code' => 'eav,config'] + ); + + self::assertMatchesRegularExpression('/Cache config enabled/', $commandTester->getDisplay()); + self::assertMatchesRegularExpression('/Cache eav enabled/', $commandTester->getDisplay()); } } diff --git a/tests/N98/Magento/Command/Cache/FlushCommandTest.php b/tests/N98/Magento/Command/Cache/FlushCommandTest.php index 51b00e001..236c518c1 100644 --- a/tests/N98/Magento/Command/Cache/FlushCommandTest.php +++ b/tests/N98/Magento/Command/Cache/FlushCommandTest.php @@ -11,15 +11,12 @@ class FlushCommandTest extends TestCase public function testExecute() { $application = $this->getApplication(); - if ($application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) { - $application = $this->getApplication(); - $application->add(new FlushCommand()); - $command = $this->getApplication()->find('cache:flush'); + $application->add(new FlushCommand()); + $command = $this->getApplication()->find('cache:flush'); - $commandTester = new CommandTester($command); - $commandTester->execute(['command' => $command->getName()]); + $commandTester = new CommandTester($command); + $commandTester->execute(['command' => $command->getName()]); - self::assertMatchesRegularExpression('/Cache cleared/', $commandTester->getDisplay()); - } + self::assertMatchesRegularExpression('/Cache cleared/', $commandTester->getDisplay()); } } diff --git a/tests/N98/Magento/Command/Customer/DeleteCommandTest.php b/tests/N98/Magento/Command/Customer/DeleteCommandTest.php index 87b27c5ea..41e921e4e 100644 --- a/tests/N98/Magento/Command/Customer/DeleteCommandTest.php +++ b/tests/N98/Magento/Command/Customer/DeleteCommandTest.php @@ -22,29 +22,19 @@ class DeleteCommandTest extends TestCase protected $website; protected $application; - protected function getResourceClassName($mage1Code, $mage2Code) + protected function getResourceClassName($mage1Code) { - // Get correct model classes to mock - if ($this->application->getMagentoMajorVersion() == 2) { - return get_class(Mage::getResourceModel($mage2Code)); - } else { - return get_class(Mage::getResourceModel($mage1Code)); - } + return get_class(Mage::getResourceModel($mage1Code)); } - protected function getModelClassName($mage1Code, $mage2Code) + protected function getModelClassName($mage1Code) { - // Get correct model classes to mock - if ($this->application->getMagentoMajorVersion() == 2) { - return get_class(Mage::getModel($mage2Code)); - } else { - return get_class(Mage::getModel($mage1Code)); - } + return get_class(Mage::getModel($mage1Code)); } protected function getCustomerModel(array $methods) { - $className = $this->getModelClassName('customer/customer', 'Mage_Customer_Model_Customer'); + $className = $this->getModelClassName('customer/customer'); return $this->getMockBuilder($className) ->setMethods($methods) ->disableOriginalConstructor() @@ -53,11 +43,7 @@ protected function getCustomerModel(array $methods) protected function getCustomerCollection(array $methods) { - $className = $this->getResourceClassName( - 'customer/customer_collection', - 'Mage_Customer_Model_Resource_Customer_Collection' - ); - + $className = $this->getResourceClassName('customer/customer_collection'); return $this->getMockBuilder($className) ->setMethods($methods) ->disableOriginalConstructor() diff --git a/tests/N98/Magento/Command/System/Setup/RemoveCommandTest.php b/tests/N98/Magento/Command/System/Setup/RemoveCommandTest.php index 4962b74e7..3951ad62e 100644 --- a/tests/N98/Magento/Command/System/Setup/RemoveCommandTest.php +++ b/tests/N98/Magento/Command/System/Setup/RemoveCommandTest.php @@ -35,7 +35,7 @@ public function testRemoveModule() $command->expects(self::once()) ->method('_getModel') - ->with('core/resource', 'Mage_Core_Model_Resource') + ->with('core/resource') ->willReturn($coreResource); $application = $this->getApplication(); @@ -73,7 +73,7 @@ public function testRemoveBySetupName() $command->expects(self::once()) ->method('_getModel') - ->with('core/resource', 'Mage_Core_Model_Resource') + ->with('core/resource') ->willReturn($coreResource); $application = $this->getApplication(); @@ -120,7 +120,7 @@ public function testRemoveBySetupNameFailure() $command->expects(self::once()) ->method('_getModel') - ->with('core/resource', 'Mage_Core_Model_Resource') + ->with('core/resource') ->willReturn($coreResource); $application = $this->getApplication(); diff --git a/tests/N98/Magento/TestApplication.php b/tests/N98/Magento/TestApplication.php index 150ef2698..4387b86ad 100644 --- a/tests/N98/Magento/TestApplication.php +++ b/tests/N98/Magento/TestApplication.php @@ -171,9 +171,7 @@ public function getApplication() $application->init(); $application->initMagento(); - if ($application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) { - spl_autoload_unregister([Varien_Autoload::instance(), 'autoload']); - } + spl_autoload_unregister([Varien_Autoload::instance(), 'autoload']); $this->application = $application; } diff --git a/tests/N98/Util/Console/Helper/MagentoHelper.php b/tests/N98/Util/Console/Helper/MagentoHelper.php index 19f1b4398..b90bcef44 100644 --- a/tests/N98/Util/Console/Helper/MagentoHelper.php +++ b/tests/N98/Util/Console/Helper/MagentoHelper.php @@ -40,7 +40,6 @@ public function detectMagentoInStandardFolder() $helper->detect(vfsStream::url('root'), []); self::assertEquals(vfsStream::url('root'), $helper->getRootFolder()); - self::assertEquals(Application::MAGENTO_MAJOR_VERSION_1, $helper->getMajorVersion()); } /** @@ -62,7 +61,6 @@ public function detectMagentoInHtdocsSubfolder() ); self::assertEquals(vfsStream::url('root/htdocs'), $helper->getRootFolder()); - self::assertEquals(Application::MAGENTO_MAJOR_VERSION_1, $helper->getMajorVersion()); } /** @@ -104,29 +102,5 @@ public function detectMagentoInModmanInfrastructure() // Verify if this could be checked with more elegance self::assertEquals(vfsStream::url('root/../root/htdocs/magento_root'), $helper->getRootFolder()); - - self::assertEquals(Application::MAGENTO_MAJOR_VERSION_1, $helper->getMajorVersion()); - } - - /** - * @test - */ - public function detectMagento2InHtdocsSubfolder() - { - vfsStream::setup('root'); - vfsStream::create( - ['htdocs' => ['app' => ['autoload.php' => '', 'bootstrap.php' => '']]] - ); - - $helper = $this->getHelper(); - - // vfs cannot resolve relative path so we do 'root/htdocs' etc. - $helper->detect( - vfsStream::url('root'), - [vfsStream::url('root/www'), vfsStream::url('root/public'), vfsStream::url('root/htdocs')] - ); - - self::assertEquals(vfsStream::url('root/htdocs'), $helper->getRootFolder()); - self::assertEquals(Application::MAGENTO_MAJOR_VERSION_2, $helper->getMajorVersion()); } }