Skip to content

magento/magento2#: Replace deprecated methods in back-end controllers of Magento/Customer #24285

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

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
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Controller/Adminhtml/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ protected function _addSessionErrorMessages($messages)
protected function actUponMultipleCustomers(callable $singleAction, $customerIds)
{
if (!is_array($customerIds)) {
$this->messageManager->addError(__('Please select customer(s).'));
$this->messageManager->addErrorMessage(__('Please select customer(s).'));
return 0;
}
$customersUpdated = 0;
Expand All @@ -320,7 +320,7 @@ protected function actUponMultipleCustomers(callable $singleAction, $customerIds
$singleAction($customerId);
$customersUpdated++;
} catch (\Exception $exception) {
$this->messageManager->addError($exception->getMessage());
$this->messageManager->addErrorMessage($exception->getMessage());
}
}
return $customersUpdated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function massAction(AbstractCollection $collection)
}

if ($customersUpdated) {
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated));
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function massAction(AbstractCollection $collection)
}

if ($customersDeleted) {
$this->messageManager->addSuccess(__('A total of %1 record(s) were deleted.', $customersDeleted));
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were deleted.', $customersDeleted));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Customer\Controller\Adminhtml\Index;

use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
use Magento\Customer\Api\CustomerRepositoryInterface;
Expand All @@ -16,7 +17,7 @@
/**
* Class MassSubscribe
*/
class MassSubscribe extends AbstractMassAction
class MassSubscribe extends AbstractMassAction implements HttpPostActionInterface
{
/**
* @var CustomerRepositoryInterface
Expand Down Expand Up @@ -64,7 +65,7 @@ protected function massAction(AbstractCollection $collection)
}

if ($customersUpdated) {
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated));
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Customer\Controller\Adminhtml\Index;

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action\Context;
use Magento\Newsletter\Model\SubscriberFactory;
Expand All @@ -16,7 +17,7 @@
/**
* Class MassUnsubscribe
*/
class MassUnsubscribe extends AbstractMassAction
class MassUnsubscribe extends AbstractMassAction implements HttpPostActionInterface
{
/**
* @var CustomerRepositoryInterface
Expand Down Expand Up @@ -64,7 +65,7 @@ protected function massAction(AbstractCollection $collection)
}

if ($customersUpdated) {
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated));
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function execute()
\Magento\Customer\Model\AccountManagement::EMAIL_REMINDER,
$customer->getWebsiteId()
);
$this->messageManager->addSuccess(__('The customer will receive an email with a link to reset password.'));
$this->messageManager->addSuccessMessage(
__('The customer will receive an email with a link to reset password.')
);
} catch (NoSuchEntityException $exception) {
$resultRedirect->setPath('customer/index');
return $resultRedirect;
Expand All @@ -57,7 +59,7 @@ public function execute()
} catch (SecurityViolationException $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
} catch (\Exception $exception) {
$this->messageManager->addException(
$this->messageManager->addExceptionMessage(
$exception,
__('Something went wrong while resetting customer password.')
);
Expand Down
7 changes: 5 additions & 2 deletions app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function execute()
$this->_getSession()->unsCustomerFormData();
// Done Saving customer, finish save action
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
$this->messageManager->addSuccess(__('You saved the customer.'));
$this->messageManager->addSuccessMessage(__('You saved the customer.'));
$returnToEdit = (bool)$this->getRequest()->getParam('back', false);
} catch (\Magento\Framework\Validator\Exception $exception) {
$messages = $exception->getMessages();
Expand All @@ -378,7 +378,10 @@ public function execute()
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
$returnToEdit = true;
} catch (\Exception $exception) {
$this->messageManager->addException($exception, __('Something went wrong while saving the customer.'));
$this->messageManager->addExceptionMessage(
$exception,
__('Something went wrong while saving the customer.')
);
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
$returnToEdit = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
namespace Magento\Customer\Controller\Adminhtml\Locks;

use Magento\Customer\Model\AuthenticationInterface;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action;

/**
* Unlock Customer Controller
*/
class Unlock extends \Magento\Backend\App\Action
class Unlock extends \Magento\Backend\App\Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
Expand Down Expand Up @@ -55,10 +56,10 @@ public function execute()
// unlock customer
if ($customerId) {
$this->authentication->unlock($customerId);
$this->getMessageManager()->addSuccess(__('Customer has been unlocked successfully.'));
$this->getMessageManager()->addSuccessMessage(__('Customer has been unlocked successfully.'));
}
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
}

/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function testExecute()
->willReturnMap([[10, $customerMock], [11, $customerMock], [12, $customerMock]]);

$this->messageManagerMock->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('A total of %1 record(s) were updated.', count($customersIds)));

$this->resultRedirectMock->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testExecute()
->willReturnMap([[10, true], [11, true], [12, true]]);

$this->messageManagerMock->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('A total of %1 record(s) were deleted.', count($customersIds)));

$this->resultRedirectMock->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function testExecute()
->willReturnMap([[10, true], [11, true], [12, true]]);

$this->messageManagerMock->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('A total of %1 record(s) were updated.', count($customersIds)));

$this->resultRedirectMock->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function testExecute()
->willReturnMap([[10, true], [11, true], [12, true]]);

$this->messageManagerMock->expects($this->once())
->method('addSuccess')
->method('addSuccessMessage')
->with(__('A total of %1 record(s) were updated.', count($customersIds)));

$this->resultRedirectMock->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function setUp()
$this->messageManager = $this->getMockBuilder(
\Magento\Framework\Message\Manager::class
)->disableOriginalConstructor()->setMethods(
['addSuccess', 'addMessage', 'addException', 'addErrorMessage']
['addSuccessMessage', 'addMessage', 'addExceptionMessage', 'addErrorMessage']
)->getMock();

$this->resultRedirectFactoryMock = $this->getMockBuilder(
Expand Down Expand Up @@ -442,7 +442,7 @@ public function testResetPasswordActionException()
$this->messageManager->expects(
$this->once()
)->method(
'addException'
'addExceptionMessage'
)->with(
$this->equalTo($exception),
$this->equalTo('Something went wrong while resetting customer password.')
Expand Down Expand Up @@ -502,7 +502,7 @@ public function testResetPasswordActionSendEmail()
$this->messageManager->expects(
$this->once()
)->method(
'addSuccess'
'addSuccessMessage'
)->with(
$this->equalTo('The customer will receive an email with a link to reset password.')
);
Expand Down
Loading