Skip to content

Commit 1ce4662

Browse files
committed
lynx-232: Revert changes using registry, use repository instead
1 parent a94cd1d commit 1ce4662

File tree

3 files changed

+25
-99
lines changed

3 files changed

+25
-99
lines changed

app/code/Magento/Customer/Model/AccountManagement/Authenticate.php

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
namespace Magento\Customer\Model\AccountManagement;
2020

2121
use Magento\Customer\Api\Data\CustomerInterface;
22-
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
2322
use Magento\Customer\Model\AccountConfirmation;
2423
use Magento\Customer\Model\AuthenticationInterface;
25-
use Magento\Customer\Model\Customer;
26-
use Magento\Customer\Model\CustomerRegistry;
27-
use Magento\Framework\Api\DataObjectHelper;
24+
use Magento\Customer\Model\CustomerFactory;
25+
use Magento\Customer\Model\ResourceModel\CustomerRepository;
2826
use Magento\Framework\Event\ManagerInterface;
2927
use Magento\Framework\Exception\EmailNotConfirmedException;
3028
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
@@ -40,19 +38,14 @@
4038
class Authenticate
4139
{
4240
/**
43-
* @var CustomerRegistry
41+
* @var CustomerRepository
4442
*/
45-
private CustomerRegistry $customerRegistry;
43+
private CustomerRepository $customerRepository;
4644

4745
/**
48-
* @var DataObjectHelper
46+
* @var CustomerFactory
4947
*/
50-
private DataObjectHelper $dataObjectHelper;
51-
52-
/**
53-
* @var CustomerInterfaceFactory
54-
*/
55-
private CustomerInterfaceFactory $customerFactory;
48+
private CustomerFactory $customerFactory;
5649

5750
/**
5851
* @var AuthenticationInterface
@@ -70,23 +63,20 @@ class Authenticate
7063
private ManagerInterface $eventManager;
7164

7265
/**
73-
* @param CustomerRegistry $customerRegistry
74-
* @param DataObjectHelper $dataObjectHelper
75-
* @param CustomerInterfaceFactory $customerFactory
66+
* @param CustomerRepository $customerRepository
67+
* @param CustomerFactory $customerFactory
7668
* @param AuthenticationInterface $authentication
7769
* @param AccountConfirmation $accountConfirmation
7870
* @param ManagerInterface $eventManager
7971
*/
8072
public function __construct(
81-
CustomerRegistry $customerRegistry,
82-
DataObjectHelper $dataObjectHelper,
83-
CustomerInterfaceFactory $customerFactory,
73+
CustomerRepository $customerRepository,
74+
CustomerFactory $customerFactory,
8475
AuthenticationInterface $authentication,
8576
AccountConfirmation $accountConfirmation,
8677
ManagerInterface $eventManager
8778
) {
88-
$this->customerRegistry = $customerRegistry;
89-
$this->dataObjectHelper = $dataObjectHelper;
79+
$this->customerRepository = $customerRepository;
9080
$this->customerFactory = $customerFactory;
9181
$this->authentication = $authentication;
9282
$this->accountConfirmation = $accountConfirmation;
@@ -104,11 +94,10 @@ public function __construct(
10494
public function execute(string $email, string $password): CustomerInterface
10595
{
10696
try {
107-
$customerModel = $this->customerRegistry->retrieveByEmail($email);
97+
$customer = $this->customerRepository->get($email);
10898
} catch (NoSuchEntityException $exception) {
10999
throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
110100
}
111-
$customer = $this->getCustomerDataObject($customerModel);
112101

113102
$customerId = $customer->getId();
114103
if ($this->authentication->isLocked($customerId)) {
@@ -125,6 +114,7 @@ public function execute(string $email, string $password): CustomerInterface
125114
throw new EmailNotConfirmedException(__('This account isn\'t confirmed. Verify and try again.'));
126115
}
127116

117+
$customerModel = $this->customerFactory->create()->updateData($customer);
128118
$this->eventManager->dispatch(
129119
'customer_customer_authenticated',
130120
['model' => $customerModel, 'password' => $password]
@@ -135,24 +125,6 @@ public function execute(string $email, string $password): CustomerInterface
135125
return $customer;
136126
}
137127

138-
/**
139-
* Convert custom model to DTO
140-
*
141-
* @param Customer $customerModel
142-
* @return CustomerInterface
143-
*/
144-
private function getCustomerDataObject(Customer $customerModel): CustomerInterface
145-
{
146-
$customerDataObject = $this->customerFactory->create();
147-
$this->dataObjectHelper->populateWithArray(
148-
$customerDataObject,
149-
$customerModel->getData(),
150-
CustomerInterface::class
151-
);
152-
$customerDataObject->setId($customerModel->getId());
153-
return $customerDataObject;
154-
}
155-
156128
/**
157129
* Check if accounts confirmation is required in config
158130
*

app/code/Magento/Customer/Model/Session.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ class Session extends \Magento\Framework\Session\SessionManager
107107
*/
108108
private $accountConfirmation;
109109

110-
/**
111-
* @var CustomerRegistry
112-
*/
113-
private $customerRegistry;
114-
115110
/**
116111
* Session constructor.
117112
*
@@ -137,7 +132,6 @@ class Session extends \Magento\Framework\Session\SessionManager
137132
* @param GroupManagementInterface $groupManagement
138133
* @param \Magento\Framework\App\Response\Http $response
139134
* @param AccountConfirmation $accountConfirmation
140-
* @param CustomerRegistry $customerRegistry
141135
* @throws \Magento\Framework\Exception\SessionException
142136
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
143137
*/
@@ -163,8 +157,7 @@ public function __construct(
163157
CustomerRepositoryInterface $customerRepository,
164158
GroupManagementInterface $groupManagement,
165159
\Magento\Framework\App\Response\Http $response,
166-
AccountConfirmation $accountConfirmation = null,
167-
CustomerRegistry $customerRegistry = null
160+
AccountConfirmation $accountConfirmation = null
168161
) {
169162
$this->_coreUrl = $coreUrl;
170163
$this->_customerUrl = $customerUrl;
@@ -180,8 +173,6 @@ public function __construct(
180173
$this->response = $response;
181174
$this->accountConfirmation = $accountConfirmation ?: ObjectManager::getInstance()
182175
->get(AccountConfirmation::class);
183-
$this->customerRegistry = $customerRegistry ?: ObjectManager::getInstance()
184-
->get(CustomerRegistry::class);
185176
parent::__construct(
186177
$request,
187178
$sidResolver,
@@ -440,7 +431,7 @@ public function checkCustomerId($customerId)
440431
}
441432

442433
try {
443-
$this->customerRegistry->retrieve($customerId);
434+
$this->customerRepository->getById($customerId);
444435
$this->_isCustomerIdChecked = $customerId;
445436
return true;
446437
} catch (\Exception $e) {

app/code/Magento/CustomerGraphQl/Model/Context/AddUserInfoToContext.php

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
use Magento\Authorization\Model\UserContextInterface;
1111
use Magento\Customer\Api\Data\CustomerInterface;
12-
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
13-
use Magento\Customer\Model\Customer;
14-
use Magento\Customer\Model\CustomerRegistry;
12+
use Magento\Customer\Model\ResourceModel\CustomerRepository;
1513
use Magento\Customer\Model\Session;
16-
use Magento\Framework\Api\DataObjectHelper;
1714
use Magento\GraphQl\Model\Query\ContextParametersInterface;
1815
use Magento\GraphQl\Model\Query\UserContextParametersProcessorInterface;
1916

@@ -25,47 +22,31 @@ class AddUserInfoToContext implements UserContextParametersProcessorInterface
2522
/**
2623
* @var UserContextInterface
2724
*/
28-
private UserContextInterface $userContext;
25+
private $userContext;
2926

3027
/**
3128
* @var Session
3229
*/
33-
private Session $session;
30+
private $session;
3431

3532
/**
36-
* @var CustomerRegistry
33+
* @var CustomerRepository
3734
*/
38-
private CustomerRegistry $customerRegistry;
39-
40-
/**
41-
* @var DataObjectHelper
42-
*/
43-
private DataObjectHelper $dataObjectHelper;
44-
45-
/**
46-
* @var CustomerInterfaceFactory
47-
*/
48-
private CustomerInterfaceFactory $customerFactory;
35+
private CustomerRepository $customerRepository;
4936

5037
/**
5138
* @param UserContextInterface $userContext
5239
* @param Session $session
53-
* @param CustomerRegistry $customerRegistry
54-
* @param DataObjectHelper $dataObjectHelper
55-
* @param CustomerInterfaceFactory $customerFactory
40+
* @param CustomerRepository $customerRepository
5641
*/
5742
public function __construct(
5843
UserContextInterface $userContext,
5944
Session $session,
60-
CustomerRegistry $customerRegistry,
61-
DataObjectHelper $dataObjectHelper,
62-
CustomerInterfaceFactory $customerFactory
45+
CustomerRepository $customerRepository
6346
) {
6447
$this->userContext = $userContext;
6548
$this->session = $session;
66-
$this->customerRegistry = $customerRegistry;
67-
$this->dataObjectHelper = $dataObjectHelper;
68-
$this->customerFactory = $customerFactory;
49+
$this->customerRepository = $customerRepository;
6950
}
7051

7152
/**
@@ -97,31 +78,13 @@ public function execute(ContextParametersInterface $contextParameters): ContextP
9778
$contextParameters->addExtensionAttribute('is_customer', $isCustomer);
9879

9980
if ($isCustomer) {
100-
$customer = $this->customerRegistry->retrieve($currentUserId);
101-
$this->session->setCustomerData($this->getCustomerDataObject($customer));
81+
$customer = $this->customerRepository->getById($currentUserId);
82+
$this->session->setCustomerData($customer);
10283
$this->session->setCustomerGroupId($customer->getGroupId());
10384
}
10485
return $contextParameters;
10586
}
10687

107-
/**
108-
* Convert custom model to DTO
109-
*
110-
* @param Customer $customerModel
111-
* @return CustomerInterface
112-
*/
113-
private function getCustomerDataObject(Customer $customerModel): CustomerInterface
114-
{
115-
$customerDataObject = $this->customerFactory->create();
116-
$this->dataObjectHelper->populateWithArray(
117-
$customerDataObject,
118-
$customerModel->getData(),
119-
CustomerInterface::class
120-
);
121-
$customerDataObject->setId($customerModel->getId());
122-
return $customerDataObject;
123-
}
124-
12588
/**
12689
* Get logged in customer data
12790
*

0 commit comments

Comments
 (0)