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

[Forwardport] Replacing Usage of Deprecated Methods for Message Manager #17140

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function _validateProducts()
}

if ($error) {
$this->messageManager->addError($error);
$this->messageManager->addErrorMessage($error);
}

return !$error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
);

Expand All @@ -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.')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*/');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/*/');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*/');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Catalog/Controller/Product/Compare/Clear.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Catalog/Controller/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
26 changes: 14 additions & 12 deletions app/code/Magento/User/Controller/Adminhtml/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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.'));
}
}

Expand Down
Loading