Skip to content

Commit

Permalink
Remove Magento2 related code
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Oct 9, 2023
1 parent 7d09436 commit 12f48b3
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 358 deletions.
80 changes: 1 addition & 79 deletions src/N98/Magento/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,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
*/
Expand Down Expand Up @@ -96,16 +86,6 @@ class Application extends BaseApplication
*/
protected $_magentoEnterprise = false;

/**
* @var int
*/
protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_1;

/**
* @var EntryPoint
*/
protected $_magento2EntryPoint = null;

/**
* @var bool
*/
Expand Down Expand Up @@ -265,7 +245,6 @@ public function detectMagento(InputInterface $input = null, OutputInterface $out
$this->_magentoDetected = $magentoHelper->detect($folder, $subFolders);
$this->_magentoRootFolder = $magentoHelper->getRootFolder();
$this->_magentoEnterprise = $magentoHelper->isEnterpriseEdition();
$this->_magentoMajorVersion = $magentoHelper->getMajorVersion();
$this->_magerunStopFileFound = $magentoHelper->isMagerunStopFileFound();
$this->_magerunStopFileFolder = $magentoHelper->getMagerunStopFileFolder();
$this->_magerunUseDeveloperMode = ($input->getParameterOption('--developer-mode'));
Expand Down Expand Up @@ -460,12 +439,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;
}
Expand Down Expand Up @@ -507,14 +481,6 @@ public function setMagentoRootFolder($magentoRootFolder)
$this->_magentoRootFolder = $magentoRootFolder;
}

/**
* @return int
*/
public function getMagentoMajorVersion()
{
return $this->_magentoMajorVersion;
}

/**
* @return ClassLoader
*/
Expand Down Expand Up @@ -786,50 +752,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 = <<<MAGENTOHINT
You are running a Magento $version.x instance. This version of n98-magerun is not compatible
with Magento $version.x. Please use n98-magerun$version (version $version) for this shop.
A current version of the software can be downloaded on github.
<info>Download with curl
------------------</info>
<comment>curl -O https://files.magerun.net/n98-magerun$file.phar</comment>
<info>Download with wget
------------------</info>
<comment>wget https://files.magerun.net/n98-magerun$file.phar</comment>
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
*/
Expand Down
84 changes: 15 additions & 69 deletions src/N98/Magento/Command/AbstractMagentoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,11 @@
*/
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
*/
protected $_magentoRootFolder = null;

/**
* @var int
*/
protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_1;

/**
* @var bool
*/
Expand Down Expand Up @@ -181,7 +166,6 @@ public function detectMagento(OutputInterface $output, $silent = true)

$this->_magentoEnterprise = $this->getApplication()->isMagentoEnterprise();
$this->_magentoRootFolder = $this->getApplication()->getMagentoRootFolder();
$this->_magentoMajorVersion = $this->getApplication()->getMagentoMajorVersion();

if (!$silent) {
$editionString = ($this->_magentoEnterprise ? ' (Enterprise Edition) ' : '');
Expand Down Expand Up @@ -213,9 +197,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');
}

Expand Down Expand Up @@ -369,83 +350,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
* @param string $class class code
* @return \Mage_Core_Model_Abstract
*/
protected function _getModel($mage1code, $mage2class)
protected function _getModel($class)
{
if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) {
return Mage::getModel($mage2class);
} else {
return Mage::getModel($mage1code);
}
return Mage::getModel($class);
}

/**
* Magento 1 / 2 switches
*
* @param string $mage1code Magento 1 class code
* @param string $mage2class Magento 2 class name
* @param string $class class code
* @return \Mage_Core_Helper_Abstract
*/
protected function _getHelper($mage1code, $mage2class)
protected function _getHelper($class)
{
if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) {
return Mage::helper($mage2class);
} else {
return Mage::helper($mage1code);
}
return Mage::helper($class);
}

/**
* Magento 1 / 2 switches
*
* @param string $mage1code Magento 1 class code
* @param string $mage2class Magento 2 class name
* @param string $class class code
* @return \Mage_Core_Model_Abstract
*/
protected function _getSingleton($mage1code, $mage2class)
protected function _getSingleton($class)
{
if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) {
return Mage::getModel($mage2class);
} else {
return Mage::getModel($mage1code);
}
return Mage::getModel($class);
}

/**
* Magento 1 / 2 switches
*
* @param string $mage1code Magento 1 class code
* @param string $mage2class Magento 2 class name
* @param string $class class code
* @return \Mage_Core_Model_Abstract
*/
protected function _getResourceModel($mage1code, $mage2class)
protected function _getResourceModel($class)
{
if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) {
return Mage::getResourceModel($mage2class);
} else {
return Mage::getResourceModel($mage1code);
}
return Mage::getResourceModel($class);
}

/**
* Magento 1 / 2 switches
*
* @param string $mage1code Magento 1 class code
* @param string $mage2class Magento 2 class name
* @param string $class class code
* @return \Mage_Core_Model_Abstract
*/
protected function _getResourceSingleton($mage1code, $mage2class)
protected function _getResourceSingleton($class)
{
if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_2) {
return Mage::getResourceSingleton($mage2class);
} else {
return Mage::getResourceSingleton($mage1code);
}
return Mage::getResourceSingleton($class);
}

/**
Expand Down
17 changes: 4 additions & 13 deletions src/N98/Magento/Command/Admin/User/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,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('<info>The role <comment>Development</comment> was automatically created.</info>');
Expand All @@ -78,14 +74,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('<info>User <comment>' . $username . '</comment> successfully created</info>');
}
Expand Down
14 changes: 1 addition & 13 deletions src/N98/Magento/Command/Cache/AbstractCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,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();
}

/**
Expand Down Expand Up @@ -93,12 +89,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;
}
}
9 changes: 2 additions & 7 deletions src/N98/Magento/Command/Config/AbstractConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,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();
}

/**
Expand Down
35 changes: 16 additions & 19 deletions src/N98/Magento/Command/Developer/Ide/PhpStorm/MetaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,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(
'<info>Generated definitions for <comment>' . $group . '</comment> group</info>'
);
}
if (!$input->getOption('stdout') && count($classMaps[$group]) > 0) {
$output->writeln(
'<info>Generated definitions for <comment>' . $group . '</comment> group</info>'
);
}
}

$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;
}

Expand Down
Loading

0 comments on commit 12f48b3

Please sign in to comment.