diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php index 8f570e35989cb..0a54475b15f9c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php @@ -44,12 +44,12 @@ public function execute() $this->_eventManager->dispatch('catalog_controller_category_delete', ['category' => $category]); $this->_auth->getAuthStorage()->setDeletedPath($category->getPath()); $this->categoryRepository->delete($category); - $this->messageManager->addSuccess(__('You deleted the category.')); + $this->messageManager->addSuccessMessage(__('You deleted the category.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); return $resultRedirect->setPath('catalog/*/edit', ['_current' => true]); } catch (\Exception $e) { - $this->messageManager->addError(__('Something went wrong while trying to delete the category.')); + $this->messageManager->addErrorMessage(__('Something went wrong while trying to delete the category.')); return $resultRedirect->setPath('catalog/*/edit', ['_current' => true]); } } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute.php index 775097c5eba1d..ca7652ebb43b5 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute.php @@ -54,7 +54,7 @@ protected function _validateProducts() } if ($error) { - $this->messageManager->addError($error); + $this->messageManager->addErrorMessage($error); } return !$error; diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php index 82496446aef9f..0fbf9054ef1bd 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php @@ -192,7 +192,7 @@ public function execute() $this->_eventManager->dispatch('catalog_product_to_website_change', ['products' => $productIds]); } - $this->messageManager->addSuccess( + $this->messageManager->addSuccessMessage( __('A total of %1 record(s) were updated.', count($this->attributeHelper->getProductIds())) ); @@ -205,9 +205,9 @@ public function execute() $this->_productPriceIndexerProcessor->reindexList($this->attributeHelper->getProductIds()); } } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { - $this->messageManager->addException( + $this->messageManager->addExceptionMessage( $e, __('Something went wrong while updating the product(s) attributes.') ); diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php index bb18436be6102..a873f08d082d7 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Validate.php @@ -68,7 +68,7 @@ public function execute() $response->setError(true); $response->setMessage($e->getMessage()); } catch (\Exception $e) { - $this->messageManager->addException( + $this->messageManager->addExceptionMessage( $e, __('Something went wrong while updating the product(s) attributes.') ); diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php index cc5a658a9296d..bef6aee0e2afd 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php @@ -21,23 +21,23 @@ public function execute() // entity type check $model->load($id); if ($model->getEntityTypeId() != $this->_entityTypeId) { - $this->messageManager->addError(__('We can\'t delete the attribute.')); + $this->messageManager->addErrorMessage(__('We can\'t delete the attribute.')); return $resultRedirect->setPath('catalog/*/'); } try { $model->delete(); - $this->messageManager->addSuccess(__('You deleted the product attribute.')); + $this->messageManager->addSuccessMessage(__('You deleted the product attribute.')); return $resultRedirect->setPath('catalog/*/'); } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); return $resultRedirect->setPath( 'catalog/*/edit', ['attribute_id' => $this->getRequest()->getParam('attribute_id')] ); } } - $this->messageManager->addError(__('We can\'t find an attribute to delete.')); + $this->messageManager->addErrorMessage(__('We can\'t find an attribute to delete.')); return $resultRedirect->setPath('catalog/*/'); } } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php index fd97aaa50389e..a99cbdbade181 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php @@ -25,14 +25,14 @@ public function execute() $model->load($id); if (!$model->getId()) { - $this->messageManager->addError(__('This attribute no longer exists.')); + $this->messageManager->addErrorMessage(__('This attribute no longer exists.')); $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('catalog/*/'); } // entity type check if ($model->getEntityTypeId() != $this->_entityTypeId) { - $this->messageManager->addError(__('This attribute cannot be edited.')); + $this->messageManager->addErrorMessage(__('This attribute cannot be edited.')); $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('catalog/*/'); } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php index b61be2b95b960..db452113ada06 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -92,9 +92,7 @@ public function execute() $attributeSet->setEntityTypeId($this->_entityTypeId)->load($setName, 'attribute_set_name'); if ($attributeSet->getId()) { $setName = $this->_objectManager->get(\Magento\Framework\Escaper::class)->escapeHtml($setName); - $this->messageManager->addError( - __('A "%1" attribute set name already exists. Create a new name and try again.', $setName) - ); + $this->messageManager->addErrorMessage(__('An attribute set named \'%1\' already exists.', $setName)); $layout = $this->layoutFactory->create(); $layout->initMessages(); diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php index 7e8b03a66f603..63e52eead064c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php @@ -43,11 +43,11 @@ public function execute() $product = $this->productBuilder->build($this->getRequest()); try { $newProduct = $this->productCopier->copy($product); - $this->messageManager->addSuccess(__('You duplicated the product.')); + $this->messageManager->addSuccessMessage(__('You duplicated the product.')); $resultRedirect->setPath('catalog/*/edit', ['_current' => true, 'id' => $newProduct->getId()]); } catch (\Exception $e) { $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); $resultRedirect->setPath('catalog/*/edit', ['_current' => true]); } return $resultRedirect; diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php index 838bce7272250..1b9316a95ad59 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php @@ -52,12 +52,12 @@ public function execute() if (($productId && !$product->getEntityId())) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); - $this->messageManager->addError(__('This product doesn\'t exist.')); + $this->messageManager->addErrorMessage(__('This product doesn\'t exist.')); return $resultRedirect->setPath('catalog/*/'); } elseif ($productId === 0) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); - $this->messageManager->addError(__('Invalid product id. Should be numeric value greater than 0')); + $this->messageManager->addErrorMessage(__('Invalid product id. Should be numeric value greater than 0')); return $resultRedirect->setPath('catalog/*/'); } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Group/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Group/Save.php index 4909e22775e55..8a5f375f2b706 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Group/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Group/Save.php @@ -29,12 +29,12 @@ public function execute() ); if ($model->itemExists()) { - $this->messageManager->addError(__('A group with the same name already exists.')); + $this->messageManager->addErrorMessage(__('A group with the same name already exists.')); } else { try { $model->save(); } catch (\Exception $e) { - $this->messageManager->addError(__('Something went wrong while saving this group.')); + $this->messageManager->addErrorMessage(__('Something went wrong while saving this group.')); } } } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index 2402fb213cda0..f32c6edd57394 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -64,9 +64,12 @@ public function execute() $this->productRepository->delete($product); $productDeleted++; } - $this->messageManager->addSuccess( - __('A total of %1 record(s) have been deleted.', $productDeleted) - ); + + if ($productDeleted) { + $this->messageManager->addSuccessMessage( + __('A total of %1 record(s) have been deleted.', $productDeleted) + ); + } return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index'); } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php index b49a4dabe223c..f2695311732f0 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php @@ -36,10 +36,10 @@ public function execute() $resultRedirect = $this->resultRedirectFactory->create(); try { $this->attributeSetRepository->deleteById($setId); - $this->messageManager->addSuccess(__('The attribute set has been removed.')); + $this->messageManager->addSuccessMessage(__('The attribute set has been removed.')); $resultRedirect->setPath('catalog/*/'); } catch (\Exception $e) { - $this->messageManager->addError(__('We can\'t delete this set right now.')); + $this->messageManager->addErrorMessage(__('We can\'t delete this set right now.')); $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*'))); } return $resultRedirect; diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php index 00a836309e58e..578150fbf5d34 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php @@ -100,15 +100,15 @@ public function execute() $model->initFromSkeleton($this->getRequest()->getParam('skeleton_set')); } $model->save(); - $this->messageManager->addSuccess(__('You saved the attribute set.')); + $this->messageManager->addSuccessMessage(__('You saved the attribute set.')); } catch (\Magento\Framework\Exception\AlreadyExistsException $e) { $this->messageManager->addErrorMessage($e->getMessage()); $hasError = true; } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); $hasError = true; } catch (\Exception $e) { - $this->messageManager->addException($e, __('Something went wrong while saving the attribute set.')); + $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the attribute set.')); $hasError = true; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php index 63f46fd32e6f7..e131bfe38c546 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Validate.php @@ -137,7 +137,7 @@ public function execute() $response->setError(true); $response->setMessages([$e->getMessage()]); } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); $layout = $this->layoutFactory->create(); $layout->initMessages(); $response->setError(true); diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php b/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php index 30470d13f002d..568fbf1d05677 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php @@ -30,12 +30,12 @@ public function execute() try { $items->clear(); - $this->messageManager->addSuccess(__('You cleared the comparison list.')); + $this->messageManager->addSuccessMessage(__('You cleared the comparison list.')); $this->_objectManager->get(\Magento\Catalog\Helper\Product\Compare::class)->calculate(); } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); + $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { - $this->messageManager->addException($e, __('Something went wrong clearing the comparison list.')); + $this->messageManager->addExceptionMessage($e, __('Something went wrong clearing the comparison list.')); } /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php b/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php index fadb94761a236..2acbe5ce4d582 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Remove.php @@ -44,7 +44,7 @@ public function execute() $item->delete(); $productName = $this->_objectManager->get(\Magento\Framework\Escaper::class) ->escapeHtml($product->getName()); - $this->messageManager->addSuccess( + $this->messageManager->addSuccessMessage( __('You removed product %1 from the comparison list.', $productName) ); $this->_eventManager->dispatch( diff --git a/app/code/Magento/Catalog/Controller/Product/View.php b/app/code/Magento/Catalog/Controller/Product/View.php index 4c577eb897589..ed437361fddd3 100644 --- a/app/code/Magento/Catalog/Controller/Product/View.php +++ b/app/code/Magento/Catalog/Controller/Product/View.php @@ -78,13 +78,16 @@ public function execute() if ($this->getRequest()->isPost() && $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) { $product = $this->_initProduct(); + if (!$product) { return $this->noProductRedirect(); } + if ($specifyOptions) { $notice = $product->getTypeInstance()->getSpecifyOptionMessage(); - $this->messageManager->addNotice($notice); + $this->messageManager->addNoticeMessage($notice); } + if ($this->getRequest()->isAjax()) { $this->getResponse()->representJson( $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([ diff --git a/app/code/Magento/User/Controller/Adminhtml/Auth.php b/app/code/Magento/User/Controller/Adminhtml/Auth.php index 173fdcc764f6f..ea539b64a5cc3 100644 --- a/app/code/Magento/User/Controller/Adminhtml/Auth.php +++ b/app/code/Magento/User/Controller/Adminhtml/Auth.php @@ -7,28 +7,32 @@ namespace Magento\User\Controller\Adminhtml; use Magento\Framework\Encryption\Helper\Security; +use Magento\Backend\App\AbstractAction; +use Magento\Backend\App\Action\Context; +use Magento\User\Model\UserFactory; +use Magento\Framework\Exception\LocalizedException; /** * \Magento\User Auth controller */ -abstract class Auth extends \Magento\Backend\App\AbstractAction +abstract class Auth extends AbstractAction { /** * User model factory * - * @var \Magento\User\Model\UserFactory + * @var UserFactory */ protected $_userFactory; /** * Construct * - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\User\Model\UserFactory $userFactory + * @param Context $context + * @param UserFactory $userFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\User\Model\UserFactory $userFactory + Context $context, + UserFactory $userFactory ) { parent::__construct($context); $this->_userFactory = $userFactory; @@ -40,7 +44,7 @@ public function __construct( * @param int $userId * @param string $resetPasswordToken * @return void - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _validateResetPasswordLinkToken($userId, $resetPasswordToken) { @@ -50,22 +54,20 @@ protected function _validateResetPasswordLinkToken($userId, $resetPasswordToken) $resetPasswordToken ) || empty($resetPasswordToken) || empty($userId) || $userId < 0 ) { - throw new \Magento\Framework\Exception\LocalizedException( - __('The password reset token is incorrect. Verify the token and try again.') - ); + throw new LocalizedException(__('Please correct the password reset token.')); } /** @var $user \Magento\User\Model\User */ $user = $this->_userFactory->create()->load($userId); if (!$user->getId()) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('Please specify the correct account and try again.') ); } $userToken = $user->getRpToken(); if (!Security::compareStrings($userToken, $resetPasswordToken) || $user->isResetPasswordLinkTokenExpired()) { - throw new \Magento\Framework\Exception\LocalizedException(__('Your password reset link has expired.')); + throw new LocalizedException(__('Your password reset link has expired.')); } } diff --git a/app/code/Magento/User/Controller/Adminhtml/Auth/Forgotpassword.php b/app/code/Magento/User/Controller/Adminhtml/Auth/Forgotpassword.php index cd4c3d6950685..c0e78fae2c2c6 100644 --- a/app/code/Magento/User/Controller/Adminhtml/Auth/Forgotpassword.php +++ b/app/code/Magento/User/Controller/Adminhtml/Auth/Forgotpassword.php @@ -7,8 +7,17 @@ namespace Magento\User\Controller\Adminhtml\Auth; use Magento\Security\Model\SecurityManager; +use Magento\Framework\App\ObjectManager; +use Magento\Backend\App\Action\Context; +use Magento\User\Model\UserFactory; +use Magento\User\Model\ResourceModel\User\CollectionFactory; +use Magento\Framework\Validator\EmailAddress; +use Magento\Security\Model\PasswordResetRequestEvent; +use Magento\Framework\Exception\SecurityViolationException; +use Magento\User\Controller\Adminhtml\Auth; +use Magento\Backend\Helper\Data; -class Forgotpassword extends \Magento\User\Controller\Adminhtml\Auth +class Forgotpassword extends Auth { /** * @var SecurityManager @@ -16,17 +25,36 @@ class Forgotpassword extends \Magento\User\Controller\Adminhtml\Auth protected $securityManager; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\User\Model\UserFactory $userFactory - * @param \Magento\Security\Model\SecurityManager $securityManager + * User model factory + * + * @var CollectionFactory + */ + private $userCollectionFactory; + + /** + * @var Data + */ + private $backendDataHelper; + + /** + * @param Context $context + * @param UserFactory $userFactory + * @param SecurityManager $securityManager + * @param CollectionFactory $userCollectionFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\User\Model\UserFactory $userFactory, - \Magento\Security\Model\SecurityManager $securityManager + Context $context, + UserFactory $userFactory, + SecurityManager $securityManager, + CollectionFactory $userCollectionFactory = null, + Data $backendDataHelper = null ) { parent::__construct($context, $userFactory); $this->securityManager = $securityManager; + $this->userCollectionFactory = $userCollectionFactory ?: + ObjectManager::getInstance()->get(CollectionFactory::class); + $this->backendDataHelper = $backendDataHelper ?: + ObjectManager::getInstance()->get(Data::class); } /** @@ -44,18 +72,18 @@ public function execute() $resultRedirect = $this->resultRedirectFactory->create(); if (!empty($email) && !empty($params)) { // Validate received data to be an email address - if (\Zend_Validate::is($email, \Magento\Framework\Validator\EmailAddress::class)) { + if (\Zend_Validate::is($email, EmailAddress::class)) { try { $this->securityManager->performSecurityCheck( - \Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, + PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, $email ); - } catch (\Magento\Framework\Exception\SecurityViolationException $exception) { + } catch (SecurityViolationException $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); return $resultRedirect->setPath('admin'); } - $collection = $this->_objectManager->get(\Magento\User\Model\ResourceModel\User\Collection::class); /** @var $collection \Magento\User\Model\ResourceModel\User\Collection */ + $collection = $this->userCollectionFactory->create(); $collection->addFieldToFilter('email', $email); $collection->load(false); @@ -65,9 +93,7 @@ public function execute() /** @var \Magento\User\Model\User $user */ $user = $this->_userFactory->create()->load($item->getId()); if ($user->getId()) { - $newPassResetToken = $this->_objectManager->get( - \Magento\User\Helper\Data::class - )->generateResetPasswordLinkToken(); + $newPassResetToken = $this->backendDataHelper->generateResetPasswordLinkToken(); $user->changeResetPasswordLinkToken($newPassResetToken); $user->save(); $user->sendPasswordResetConfirmationEmail(); @@ -86,7 +112,7 @@ public function execute() $this->messageManager->addSuccess(__('We\'ll email you a link to reset your password.')); // @codingStandardsIgnoreEnd $this->getResponse()->setRedirect( - $this->_objectManager->get(\Magento\Backend\Helper\Data::class)->getHomePageUrl() + $this->backendDataHelper->getHomePageUrl() ); return; } else { diff --git a/app/code/Magento/User/Controller/Adminhtml/Auth/ResetPasswordPost.php b/app/code/Magento/User/Controller/Adminhtml/Auth/ResetPasswordPost.php index 2c6be98439919..c2e29534b1251 100644 --- a/app/code/Magento/User/Controller/Adminhtml/Auth/ResetPasswordPost.php +++ b/app/code/Magento/User/Controller/Adminhtml/Auth/ResetPasswordPost.php @@ -6,8 +6,32 @@ */ namespace Magento\User\Controller\Adminhtml\Auth; -class ResetPasswordPost extends \Magento\User\Controller\Adminhtml\Auth +use Magento\User\Controller\Adminhtml\Auth; +use Magento\Backend\App\Action\Context; +use Magento\Framework\App\ObjectManager; +use Magento\Backend\Helper\Data; +use Magento\User\Model\UserFactory; + +class ResetPasswordPost extends Auth { + /** + * @var Data + */ + private $backendDataHelper; + + /** + * @param Context $context + * @param UserFactory $userFactory + * @param Data $backendDataHelper + */ + public function __construct( + Context $context, + UserFactory $userFactory, + Data $backendDataHelper = null + ) { + parent::__construct($context, $userFactory); + $this->backendDataHelper = $backendDataHelper ?: ObjectManager::getInstance()->get(Data::class); + } /** * Reset forgotten password * @@ -27,7 +51,7 @@ public function execute() } catch (\Exception $exception) { $this->messageManager->addError(__('Your password reset link has expired.')); $this->getResponse()->setRedirect( - $this->_objectManager->get(\Magento\Backend\Helper\Data::class)->getHomePageUrl() + $this->backendDataHelper->getHomePageUrl() ); return; } @@ -53,7 +77,7 @@ public function execute() $user->save(); $this->messageManager->addSuccess(__('You updated your password.')); $this->getResponse()->setRedirect( - $this->_objectManager->get(\Magento\Backend\Helper\Data::class)->getHomePageUrl() + $this->backendDataHelper->getHomePageUrl() ); } } catch (\Magento\Framework\Validator\Exception $exception) {