Skip to content

Commit 5b360cb

Browse files
committed
magento/magento2#: Replace deprecated addError, addSuccess, addException methods in Magento/Customer/Controller/Account/CreatePost.php
1 parent 60823ed commit 5b360cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+281
-393
lines changed

app/code/Magento/Customer/Controller/Account/Confirm.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
*
2525
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2626
*/
27-
class Confirm
28-
extends \Magento\Customer\Controller\AbstractAccount
29-
implements \Magento\Framework\App\Action\Action\ActionInterface
27+
class Confirm extends \Magento\Customer\Controller\AbstractAccount
3028
{
3129
/**
3230
* @var \Magento\Framework\App\Config\ScopeConfigInterface
@@ -153,9 +151,7 @@ public function execute()
153151
$customerId = $this->getRequest()->getParam('id', false);
154152
$key = $this->getRequest()->getParam('key', false);
155153
if (empty($customerId) || empty($key)) {
156-
$this->messageManager->addErrorMessage(__('Bad request.'));
157-
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
158-
return $resultRedirect->setUrl($this->_redirect->error($url));
154+
throw new \Exception(__('Bad request.'));
159155
}
160156

161157
// log in and send greeting email
@@ -167,13 +163,13 @@ public function execute()
167163
$metadata->setPath('/');
168164
$this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
169165
}
170-
$this->messageManager->addSuccessMessage($this->getSuccessMessage());
166+
$this->messageManager->addSuccess($this->getSuccessMessage());
171167
$resultRedirect->setUrl($this->getSuccessRedirect());
172168
return $resultRedirect;
173169
} catch (StateException $e) {
174-
$this->messageManager->addExceptionMessage($e, __('This confirmation key is invalid or has expired.'));
170+
$this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
175171
} catch (\Exception $e) {
176-
$this->messageManager->addExceptionMessage($e, __('There was an error confirming the account'));
172+
$this->messageManager->addException($e, __('There was an error confirming the account'));
177173
}
178174

179175
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);

app/code/Magento/Customer/Controller/Account/Confirmation.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
/**
3+
*
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
@@ -14,9 +15,6 @@
1415
use Magento\Customer\Api\AccountManagementInterface;
1516
use Magento\Framework\Exception\State\InvalidTransitionException;
1617

17-
/**
18-
* Class Confirmation
19-
*/
2018
class Confirmation extends \Magento\Customer\Controller\AbstractAccount
2119
{
2220
/**
@@ -93,11 +91,11 @@ public function execute()
9391
$email,
9492
$this->storeManager->getStore()->getWebsiteId()
9593
);
96-
$this->messageManager->addSuccessMessage(__('Please check your email for confirmation key.'));
94+
$this->messageManager->addSuccess(__('Please check your email for confirmation key.'));
9795
} catch (InvalidTransitionException $e) {
98-
$this->messageManager->addSuccessMessage(__('This email does not require confirmation.'));
96+
$this->messageManager->addSuccess(__('This email does not require confirmation.'));
9997
} catch (\Exception $e) {
100-
$this->messageManager->addExceptionMessage($e, __('Wrong email.'));
98+
$this->messageManager->addException($e, __('Wrong email.'));
10199
$resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]);
102100
return $resultRedirect;
103101
}

app/code/Magento/Customer/Controller/Account/CreatePost.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Customer\Controller\Account;
79

810
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
@@ -349,33 +351,34 @@ public function execute()
349351
$confirmation = $this->getRequest()->getParam('password_confirmation');
350352
$redirectUrl = $this->session->getBeforeAuthUrl();
351353
$this->checkPasswordConfirmation($password, $confirmation);
354+
355+
$extensionAttributes = $customer->getExtensionAttributes();
356+
$extensionAttributes->setIsSubscribed($this->getRequest()->getParam('is_subscribed', false));
357+
$customer->setExtensionAttributes($extensionAttributes);
358+
352359
$customer = $this->accountManagement
353360
->createAccount($customer, $password, $redirectUrl);
354361

355-
if ($this->getRequest()->getParam('is_subscribed', false)) {
356-
$extensionAttributes = $customer->getExtensionAttributes();
357-
$extensionAttributes->setIsSubscribed(true);
358-
$customer->setExtensionAttributes($extensionAttributes);
359-
$this->customerRepository->save($customer);
360-
}
361362
$this->_eventManager->dispatch(
362363
'customer_register_success',
363364
['account_controller' => $this, 'customer' => $customer]
364365
);
365366
$confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId());
366367
if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
367-
$this->messageManager->addComplexSuccessMessage(
368-
'confirmAccountSuccessMessage',
369-
[
370-
'url' => $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()),
371-
]
368+
$email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail());
369+
// @codingStandardsIgnoreStart
370+
$this->messageManager->addSuccess(
371+
__(
372+
'You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.',
373+
$email
374+
)
372375
);
373-
376+
// @codingStandardsIgnoreEnd
374377
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
375378
$resultRedirect->setUrl($this->_redirect->success($url));
376379
} else {
377380
$this->session->setCustomerDataAsLoggedIn($customer);
378-
$this->messageManager->addSuccessMessage($this->getSuccessMessage());
381+
$this->messageManager->addSuccess($this->getSuccessMessage());
379382
$requestedRedirect = $this->accountRedirect->getRedirectCookie();
380383
if (!$this->scopeConfig->getValue('customer/startup/redirect_dashboard') && $requestedRedirect) {
381384
$resultRedirect->setUrl($this->_redirect->success($requestedRedirect));
@@ -392,21 +395,23 @@ public function execute()
392395

393396
return $resultRedirect;
394397
} catch (StateException $e) {
395-
$this->messageManager->addComplexErrorMessage(
396-
'customerAlreadyExistsErrorMessage',
397-
[
398-
'url' => $this->urlModel->getUrl('customer/account/forgotpassword'),
399-
]
398+
$url = $this->urlModel->getUrl('customer/account/forgotpassword');
399+
// @codingStandardsIgnoreStart
400+
$message = __(
401+
'There is already an account with this email address. If you are sure that it is your email address, <a href="%1">click here</a> to get your password and access your account.',
402+
$url
400403
);
404+
// @codingStandardsIgnoreEnd
405+
$this->messageManager->addError($message);
401406
} catch (InputException $e) {
402-
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
407+
$this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
403408
foreach ($e->getErrors() as $error) {
404-
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage()));
409+
$this->messageManager->addError($this->escaper->escapeHtml($error->getMessage()));
405410
}
406411
} catch (LocalizedException $e) {
407-
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
412+
$this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
408413
} catch (\Exception $e) {
409-
$this->messageManager->addExceptionMessage($e, __('We can\'t save the customer.'));
414+
$this->messageManager->addException($e, __('We can\'t save the customer.'));
410415
}
411416

412417
$this->session->setCustomerFormData($this->getRequest()->getPostValue());

app/code/Magento/Customer/Controller/Account/EditPost.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function execute()
216216
$isPasswordChanged
217217
);
218218
$this->dispatchSuccessEvent($customerCandidateDataObject);
219-
$this->messageManager->addSuccessMessage(__('You saved the account information.'));
219+
$this->messageManager->addSuccess(__('You saved the account information.'));
220220
return $resultRedirect->setPath('customer/account');
221221
} catch (InvalidEmailOrPasswordException $e) {
222222
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
@@ -227,17 +227,17 @@ public function execute()
227227
);
228228
$this->session->logout();
229229
$this->session->start();
230-
$this->messageManager->addErrorMessage($message);
230+
$this->messageManager->addError($message);
231231
return $resultRedirect->setPath('customer/account/login');
232232
} catch (InputException $e) {
233233
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
234234
foreach ($e->getErrors() as $error) {
235235
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage()));
236236
}
237237
} catch (\Magento\Framework\Exception\LocalizedException $e) {
238-
$this->messageManager->addErrorMessage($e->getMessage());
238+
$this->messageManager->addError($e->getMessage());
239239
} catch (\Exception $e) {
240-
$this->messageManager->addExceptionMessage($e, __('We can\'t save the customer.'));
240+
$this->messageManager->addException($e, __('We can\'t save the customer.'));
241241
}
242242

243243
$this->session->setCustomerFormData($this->getRequest()->getPostValue());
@@ -345,11 +345,9 @@ private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerIn
345345
$this->getRequest()->getPost('current_password')
346346
);
347347
} catch (InvalidEmailOrPasswordException $e) {
348-
// @codingStandardsIgnoreStart
349348
throw new InvalidEmailOrPasswordException(
350349
__("The password doesn't match this account. Verify the password and try again.")
351350
);
352-
// @codingStandardsIgnoreEnd
353351
}
354352
}
355353
}

app/code/Magento/Customer/Controller/Account/LoginPost.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Magento\Framework\Phrase;
2727

2828
/**
29-
* Class LoginPost
3029
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3130
*/
3231
class LoginPost extends AbstractAccount implements CsrfAwareActionInterface, HttpPostActionInterface
@@ -218,17 +217,17 @@ public function execute()
218217
$message = $e->getMessage();
219218
} catch (\Exception $e) {
220219
// PA DSS violation: throwing or logging an exception here can disclose customer password
221-
$this->messageManager->addErrorMessage(
220+
$this->messageManager->addError(
222221
__('An unspecified error occurred. Please contact us for assistance.')
223222
);
224223
} finally {
225224
if (isset($message)) {
226-
$this->messageManager->addErrorMessage($message);
225+
$this->messageManager->addError($message);
227226
$this->session->setUsername($login['username']);
228227
}
229228
}
230229
} else {
231-
$this->messageManager->addErrorMessage(__('A login and a password are required.'));
230+
$this->messageManager->addError(__('A login and a password are required.'));
232231
}
233232
}
234233

app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public function execute()
7373
$passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation');
7474

7575
if ($password !== $passwordConfirmation) {
76-
$this->messageManager->addErrorMessage(__("New Password and Confirm New Password values didn't match."));
76+
$this->messageManager->addError(__("New Password and Confirm New Password values didn't match."));
7777
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);
7878

7979
return $resultRedirect;
8080
}
8181
if (iconv_strlen($password) <= 0) {
82-
$this->messageManager->addErrorMessage(__('Please enter a new password.'));
82+
$this->messageManager->addError(__('Please enter a new password.'));
8383
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);
8484

8585
return $resultRedirect;
@@ -92,17 +92,17 @@ public function execute()
9292
$password
9393
);
9494
$this->session->unsRpToken();
95-
$this->messageManager->addSuccessMessage(__('You updated your password.'));
95+
$this->messageManager->addSuccess(__('You updated your password.'));
9696
$resultRedirect->setPath('*/*/login');
9797

9898
return $resultRedirect;
9999
} catch (InputException $e) {
100-
$this->messageManager->addErrorMessage($e->getMessage());
100+
$this->messageManager->addError($e->getMessage());
101101
foreach ($e->getErrors() as $error) {
102-
$this->messageManager->addErrorMessage($error->getMessage());
102+
$this->messageManager->addError($error->getMessage());
103103
}
104104
} catch (\Exception $exception) {
105-
$this->messageManager->addErrorMessage(__('Something went wrong while saving the new password.'));
105+
$this->messageManager->addError(__('Something went wrong while saving the new password.'));
106106
}
107107
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);
108108

app/code/Magento/Customer/Controller/Address/Delete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function execute()
2727
$address = $this->_addressRepository->getById($addressId);
2828
if ($address->getCustomerId() === $this->_getSession()->getCustomerId()) {
2929
$this->_addressRepository->deleteById($addressId);
30-
$this->messageManager->addSuccessMessage(__('You deleted the address.'));
30+
$this->messageManager->addSuccess(__('You deleted the address.'));
3131
} else {
32-
$this->messageManager->addComplexErrorMessage('unableDeleteAddressMessage');
32+
$this->messageManager->addError(__('We can\'t delete the address right now.'));
3333
}
3434
} catch (\Exception $other) {
3535
$this->messageManager->addException($other, __('We can\'t delete the address right now.'));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ public function execute()
139139
if ($customerId = $this->getRequest()->getParam('customer_id')) {
140140
try {
141141
$this->tokenService->revokeCustomerAccessToken($customerId);
142-
$this->messageManager->addSuccessMessage(__('You have revoked the customer\'s tokens.'));
142+
$this->messageManager->addSuccess(__('You have revoked the customer\'s tokens.'));
143143
$resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]);
144144
} catch (\Exception $e) {
145-
$this->messageManager->addErrorMessage($e->getMessage());
145+
$this->messageManager->addError($e->getMessage());
146146
$resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]);
147147
}
148148
} else {
149-
$this->messageManager->addErrorMessage(__('We can\'t find a customer to revoke.'));
149+
$this->messageManager->addError(__('We can\'t find a customer to revoke.'));
150150
$resultRedirect->setPath('customer/index/index');
151151
}
152152
return $resultRedirect;

app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
/**
3+
*
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
@@ -8,9 +9,6 @@
89
use Magento\Framework\App\Action\HttpPostActionInterface;
910
use Magento\Framework\Exception\NoSuchEntityException;
1011

11-
/**
12-
* Class Delete
13-
*/
1412
class Delete extends \Magento\Customer\Controller\Adminhtml\Group implements HttpPostActionInterface
1513
{
1614
/**
@@ -26,12 +24,12 @@ public function execute()
2624
if ($id) {
2725
try {
2826
$this->groupRepository->deleteById($id);
29-
$this->messageManager->addSuccessMessage(__('You deleted the customer group.'));
27+
$this->messageManager->addSuccess(__('You deleted the customer group.'));
3028
} catch (NoSuchEntityException $e) {
31-
$this->messageManager->addErrorMessage(__('The customer group no longer exists.'));
29+
$this->messageManager->addError(__('The customer group no longer exists.'));
3230
return $resultRedirect->setPath('customer/*/');
3331
} catch (\Exception $e) {
34-
$this->messageManager->addErrorMessage($e->getMessage());
32+
$this->messageManager->addError($e->getMessage());
3533
return $resultRedirect->setPath('customer/group/edit', ['id' => $id]);
3634
}
3735
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function execute()
9393

9494
$this->groupRepository->save($customerGroup);
9595

96-
$this->messageManager->addSuccessMessage(__('You saved the customer group.'));
96+
$this->messageManager->addSuccess(__('You saved the customer group.'));
9797
$resultRedirect->setPath('customer/group');
9898
} catch (\Exception $e) {
9999
$this->messageManager->addError($e->getMessage());

0 commit comments

Comments
 (0)