Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Magento 2 code #1462

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 2 additions & 66 deletions src/N98/Magento/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 = <<<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
79 changes: 16 additions & 63 deletions src/N98/Magento/Command/AbstractMagentoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand All @@ -56,7 +47,7 @@ abstract class AbstractMagentoCommand extends Command
/**
* @var int
*/
protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_1;
protected $_magentoMajorVersion = 1;

/**
* @var bool
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ abstract class AbstractAdminUserCommand extends AbstractMagentoCommand
*/
protected function getUserModel()
{
return $this->_getModel('admin/user', 'Mage_User_Model_User');
return $this->_getModel('admin/user');
}

/**
* @return \Mage_Core_Model_Abstract
*/
protected function getRoleModel()
{
return $this->_getModel('admin/roles', 'Mage_User_Model_Role');
return $this->_getModel('admin/roles');
}

/**
* @return \Mage_Core_Model_Abstract
*/
protected function getRulesModel()
{
return $this->_getModel('admin/rules', 'Mage_User_Model_Rules');
return $this->_getModel('admin/rules');
}
}
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 @@ -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('<info>The role <comment>Development</comment> was automatically created.</info>');
Expand All @@ -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('<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 @@ -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();
}

/**
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/N98/Magento/Command/Cms/Block/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function configure()
*/
protected function _getBlockModel()
{
return $this->_getModel('cms/block', '\Mage_Cms_Model_Block');
return $this->_getModel('cms/block');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/Command/Cms/Block/ToggleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function configure()
*/
protected function _getBlockModel()
{
return $this->_getModel('cms/block', '\Mage_Cms_Model_Block');
return $this->_getModel('cms/block');
}

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

/**
* @return \Mage_Core_Model_Abstract
*/
protected function _getConfigDataModel()
{
return $this->_getModel('core/config_data', 'Mage_Core_Model_Config_Data');
return $this->_getModel('core/config_data');
}

/**
Expand Down Expand Up @@ -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');
}
}
Loading
Loading