Skip to content

Commit 6de4937

Browse files
authored
ENGCOM-5723: magento/magento2#: Replace deprecated methods in back-end controllers of Magento/Customer #24285
2 parents e8fa066 + 35723b3 commit 6de4937

File tree

16 files changed

+91
-64
lines changed

16 files changed

+91
-64
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ protected function _addSessionErrorMessages($messages)
311311
protected function actUponMultipleCustomers(callable $singleAction, $customerIds)
312312
{
313313
if (!is_array($customerIds)) {
314-
$this->messageManager->addError(__('Please select customer(s).'));
314+
$this->messageManager->addErrorMessage(__('Please select customer(s).'));
315315
return 0;
316316
}
317317
$customersUpdated = 0;
@@ -320,7 +320,7 @@ protected function actUponMultipleCustomers(callable $singleAction, $customerIds
320320
$singleAction($customerId);
321321
$customersUpdated++;
322322
} catch (\Exception $exception) {
323-
$this->messageManager->addError($exception->getMessage());
323+
$this->messageManager->addErrorMessage($exception->getMessage());
324324
}
325325
}
326326
return $customersUpdated;

app/code/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function massAction(AbstractCollection $collection)
6060
}
6161

6262
if ($customersUpdated) {
63-
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated));
63+
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated));
6464
}
6565
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
6666
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

app/code/Magento/Customer/Controller/Adminhtml/Index/MassDelete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function massAction(AbstractCollection $collection)
5858
}
5959

6060
if ($customersDeleted) {
61-
$this->messageManager->addSuccess(__('A total of %1 record(s) were deleted.', $customersDeleted));
61+
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were deleted.', $customersDeleted));
6262
}
6363
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
6464
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

app/code/Magento/Customer/Controller/Adminhtml/Index/MassSubscribe.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Customer\Controller\Adminhtml\Index;
77

88
use Magento\Backend\App\Action\Context;
9+
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
910
use Magento\Ui\Component\MassAction\Filter;
1011
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
1112
use Magento\Customer\Api\CustomerRepositoryInterface;
@@ -16,7 +17,7 @@
1617
/**
1718
* Class MassSubscribe
1819
*/
19-
class MassSubscribe extends AbstractMassAction
20+
class MassSubscribe extends AbstractMassAction implements HttpPostActionInterface
2021
{
2122
/**
2223
* @var CustomerRepositoryInterface
@@ -64,7 +65,7 @@ protected function massAction(AbstractCollection $collection)
6465
}
6566

6667
if ($customersUpdated) {
67-
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated));
68+
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated));
6869
}
6970
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
7071
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

app/code/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribe.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Customer\Controller\Adminhtml\Index;
77

88
use Magento\Customer\Api\CustomerRepositoryInterface;
9+
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
910
use Magento\Framework\Controller\ResultFactory;
1011
use Magento\Backend\App\Action\Context;
1112
use Magento\Newsletter\Model\SubscriberFactory;
@@ -16,7 +17,7 @@
1617
/**
1718
* Class MassUnsubscribe
1819
*/
19-
class MassUnsubscribe extends AbstractMassAction
20+
class MassUnsubscribe extends AbstractMassAction implements HttpPostActionInterface
2021
{
2122
/**
2223
* @var CustomerRepositoryInterface
@@ -64,7 +65,7 @@ protected function massAction(AbstractCollection $collection)
6465
}
6566

6667
if ($customersUpdated) {
67-
$this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated));
68+
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) were updated.', $customersUpdated));
6869
}
6970
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
7071
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

app/code/Magento/Customer/Controller/Adminhtml/Index/ResetPassword.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function execute()
4444
\Magento\Customer\Model\AccountManagement::EMAIL_REMINDER,
4545
$customer->getWebsiteId()
4646
);
47-
$this->messageManager->addSuccess(__('The customer will receive an email with a link to reset password.'));
47+
$this->messageManager->addSuccessMessage(
48+
__('The customer will receive an email with a link to reset password.')
49+
);
4850
} catch (NoSuchEntityException $exception) {
4951
$resultRedirect->setPath('customer/index');
5052
return $resultRedirect;
@@ -57,7 +59,7 @@ public function execute()
5759
} catch (SecurityViolationException $exception) {
5860
$this->messageManager->addErrorMessage($exception->getMessage());
5961
} catch (\Exception $exception) {
60-
$this->messageManager->addException(
62+
$this->messageManager->addExceptionMessage(
6163
$exception,
6264
__('Something went wrong while resetting customer password.')
6365
);

app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public function execute()
354354
$this->_getSession()->unsCustomerFormData();
355355
// Done Saving customer, finish save action
356356
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
357-
$this->messageManager->addSuccess(__('You saved the customer.'));
357+
$this->messageManager->addSuccessMessage(__('You saved the customer.'));
358358
$returnToEdit = (bool)$this->getRequest()->getParam('back', false);
359359
} catch (\Magento\Framework\Validator\Exception $exception) {
360360
$messages = $exception->getMessages();
@@ -378,7 +378,10 @@ public function execute()
378378
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
379379
$returnToEdit = true;
380380
} catch (\Exception $exception) {
381-
$this->messageManager->addException($exception, __('Something went wrong while saving the customer.'));
381+
$this->messageManager->addExceptionMessage(
382+
$exception,
383+
__('Something went wrong while saving the customer.')
384+
);
382385
$this->_getSession()->setCustomerFormData($this->retrieveFormattedFormData());
383386
$returnToEdit = true;
384387
}

app/code/Magento/Customer/Controller/Adminhtml/Locks/Unlock.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
namespace Magento\Customer\Controller\Adminhtml\Locks;
88

99
use Magento\Customer\Model\AuthenticationInterface;
10+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
1011
use Magento\Framework\Controller\ResultFactory;
1112
use Magento\Backend\App\Action;
1213

1314
/**
1415
* Unlock Customer Controller
1516
*/
16-
class Unlock extends \Magento\Backend\App\Action
17+
class Unlock extends \Magento\Backend\App\Action implements HttpGetActionInterface
1718
{
1819
/**
1920
* Authorization level of a basic admin session
@@ -55,10 +56,10 @@ public function execute()
5556
// unlock customer
5657
if ($customerId) {
5758
$this->authentication->unlock($customerId);
58-
$this->getMessageManager()->addSuccess(__('Customer has been unlocked successfully.'));
59+
$this->getMessageManager()->addSuccessMessage(__('Customer has been unlocked successfully.'));
5960
}
6061
} catch (\Exception $e) {
61-
$this->messageManager->addError($e->getMessage());
62+
$this->messageManager->addErrorMessage($e->getMessage());
6263
}
6364

6465
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassAssignGroupTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function testExecute()
170170
->willReturnMap([[10, $customerMock], [11, $customerMock], [12, $customerMock]]);
171171

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

176176
$this->resultRedirectMock->expects($this->any())

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassDeleteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function testExecute()
155155
->willReturnMap([[10, true], [11, true], [12, true]]);
156156

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

161161
$this->resultRedirectMock->expects($this->any())

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassSubscribeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testExecute()
171171
->willReturnMap([[10, true], [11, true], [12, true]]);
172172

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

177177
$this->resultRedirectMock->expects($this->any())

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/MassUnsubscribeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testExecute()
171171
->willReturnMap([[10, true], [11, true], [12, true]]);
172172

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

177177
$this->resultRedirectMock->expects($this->any())

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function setUp()
141141
$this->messageManager = $this->getMockBuilder(
142142
\Magento\Framework\Message\Manager::class
143143
)->disableOriginalConstructor()->setMethods(
144-
['addSuccess', 'addMessage', 'addException', 'addErrorMessage']
144+
['addSuccessMessage', 'addMessage', 'addExceptionMessage', 'addErrorMessage']
145145
)->getMock();
146146

147147
$this->resultRedirectFactoryMock = $this->getMockBuilder(
@@ -442,7 +442,7 @@ public function testResetPasswordActionException()
442442
$this->messageManager->expects(
443443
$this->once()
444444
)->method(
445-
'addException'
445+
'addExceptionMessage'
446446
)->with(
447447
$this->equalTo($exception),
448448
$this->equalTo('Something went wrong while resetting customer password.')
@@ -502,7 +502,7 @@ public function testResetPasswordActionSendEmail()
502502
$this->messageManager->expects(
503503
$this->once()
504504
)->method(
505-
'addSuccess'
505+
'addSuccessMessage'
506506
)->with(
507507
$this->equalTo('The customer will receive an email with a link to reset password.')
508508
);

0 commit comments

Comments
 (0)