Skip to content

Commit aa44a28

Browse files
committed
Merge branch 'master' into magento2.4.x
2 parents 3a5cb2b + 20a6034 commit aa44a28

File tree

27 files changed

+523
-229
lines changed

27 files changed

+523
-229
lines changed

Controller/AbstractPrivacy.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,55 @@
77

88
namespace Opengento\Gdpr\Controller;
99

10-
use Magento\Customer\Controller\AccountInterface;
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\App\Response\Http;
13+
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\Framework\Exception\NotFoundException;
15+
use Magento\Framework\Message\ManagerInterface;
16+
use Opengento\Gdpr\Model\Config;
1117

12-
abstract class AbstractPrivacy extends AbstractAction implements AccountInterface
18+
/**
19+
* This class is introduced to handle customer authentication verification.
20+
* We can't use the default AccountInterface or AccountPlugin
21+
* as they requires the action to inherit the default Magento AbstractAction
22+
* which is deprecated and which suffer of performance issues
23+
*/
24+
abstract class AbstractPrivacy extends AbstractAction
1325
{
26+
/**
27+
* @var Session
28+
*/
29+
protected $customerSession;
30+
31+
/**
32+
* @var Http
33+
*/
34+
private $response;
35+
36+
public function __construct(
37+
RequestInterface $request,
38+
ResultFactory $resultFactory,
39+
ManagerInterface $messageManager,
40+
Config $config,
41+
Session $customerSession,
42+
Http $response
43+
) {
44+
$this->customerSession = $customerSession;
45+
$this->response = $response;
46+
parent::__construct($request, $resultFactory, $messageManager, $config);
47+
}
48+
49+
public function execute()
50+
{
51+
return $this->customerSession->authenticate() ? $this->defaultAction() : $this->response;
52+
}
53+
54+
/**
55+
* @throws NotFoundException
56+
*/
57+
private function defaultAction()
58+
{
59+
return $this->isAllowed() ? $this->executeAction() : $this->forwardNoRoute();
60+
}
1461
}

Controller/Privacy/Download.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\Action\HttpGetActionInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
1414
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\App\Response\Http;
1516
use Magento\Framework\App\Response\Http\FileFactory;
1617
use Magento\Framework\Controller\Result\Redirect;
1718
use Magento\Framework\Controller\ResultFactory;
@@ -35,24 +36,19 @@ class Download extends AbstractPrivacy implements HttpGetActionInterface
3536
*/
3637
private $exportRepository;
3738

38-
/**
39-
* @var Session
40-
*/
41-
private $customerSession;
42-
4339
public function __construct(
4440
RequestInterface $request,
4541
ResultFactory $resultFactory,
4642
ManagerInterface $messageManager,
4743
Config $config,
44+
Http $response,
45+
Session $customerSession,
4846
FileFactory $fileFactory,
49-
ExportEntityRepositoryInterface $exportRepository,
50-
Session $customerSession
47+
ExportEntityRepositoryInterface $exportRepository
5148
) {
5249
$this->fileFactory = $fileFactory;
5350
$this->exportRepository = $exportRepository;
54-
$this->customerSession = $customerSession;
55-
parent::__construct($request, $resultFactory, $messageManager, $config);
51+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
5652
}
5753

5854
protected function isAllowed(): bool

Controller/Privacy/Erase.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Model\Session;
1111
use Magento\Framework\App\Action\HttpGetActionInterface;
1212
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\App\Response\Http;
1314
use Magento\Framework\Controller\Result\Redirect;
1415
use Magento\Framework\Controller\ResultFactory;
1516
use Magento\Framework\Message\ManagerInterface;
@@ -20,11 +21,6 @@
2021

2122
class Erase extends AbstractPrivacy implements HttpGetActionInterface
2223
{
23-
/**
24-
* @var Session
25-
*/
26-
private $session;
27-
2824
/**
2925
* @var EraseEntityCheckerInterface
3026
*/
@@ -35,12 +31,12 @@ public function __construct(
3531
ResultFactory $resultFactory,
3632
ManagerInterface $messageManager,
3733
Config $config,
38-
Session $session,
34+
Session $customerSession,
35+
Http $response,
3936
EraseEntityCheckerInterface $eraseCustomerChecker
4037
) {
41-
$this->session = $session;
4238
$this->eraseCustomerChecker = $eraseCustomerChecker;
43-
parent::__construct($request, $resultFactory, $messageManager, $config);
39+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
4440
}
4541

4642
protected function isAllowed(): bool
@@ -50,7 +46,7 @@ protected function isAllowed(): bool
5046

5147
protected function executeAction()
5248
{
53-
if ($this->eraseCustomerChecker->exists((int) $this->session->getCustomerId(), 'customer')) {
49+
if ($this->eraseCustomerChecker->exists((int) $this->customerSession->getCustomerId(), 'customer')) {
5450
$this->messageManager->addErrorMessage(new Phrase('Your account is already being removed.'));
5551
/** @var Redirect $resultRedirect */
5652
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

Controller/Privacy/ErasePost.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Customer\Model\Session;
1313
use Magento\Framework\App\Action\HttpPostActionInterface;
1414
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\App\Response\Http;
1516
use Magento\Framework\Controller\Result\Redirect;
1617
use Magento\Framework\Controller\ResultFactory;
1718
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
@@ -33,11 +34,6 @@ class ErasePost extends AbstractPrivacy implements HttpPostActionInterface
3334
*/
3435
private $authentication;
3536

36-
/**
37-
* @var Session
38-
*/
39-
private $customerSession;
40-
4137
/**
4238
* @var ActionInterface
4339
*/
@@ -53,16 +49,16 @@ public function __construct(
5349
ResultFactory $resultFactory,
5450
ManagerInterface $messageManager,
5551
Config $config,
56-
AuthenticationInterface $authentication,
5752
Session $customerSession,
53+
Http $response,
54+
AuthenticationInterface $authentication,
5855
ActionInterface $action,
5956
ContextBuilder $actionContextBuilder
6057
) {
6158
$this->authentication = $authentication;
62-
$this->customerSession = $customerSession;
6359
$this->action = $action;
6460
$this->actionContextBuilder = $actionContextBuilder;
65-
parent::__construct($request, $resultFactory, $messageManager, $config);
61+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
6662
}
6763

6864
protected function isAllowed(): bool

Controller/Privacy/Export.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Model\Session;
1212
use Magento\Framework\App\Action\HttpGetActionInterface;
1313
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\App\Response\Http;
1415
use Magento\Framework\Controller\Result\Redirect;
1516
use Magento\Framework\Controller\ResultFactory;
1617
use Magento\Framework\Exception\AlreadyExistsException;
@@ -35,24 +36,19 @@ class Export extends AbstractPrivacy implements HttpGetActionInterface
3536
*/
3637
private $actionContextBuilder;
3738

38-
/**
39-
* @var Session
40-
*/
41-
private $customerSession;
42-
4339
public function __construct(
4440
RequestInterface $request,
4541
ResultFactory $resultFactory,
4642
ManagerInterface $messageManager,
4743
Config $config,
44+
Session $customerSession,
45+
Http $response,
4846
ActionInterface $action,
49-
ContextBuilder $actionContextBuilder,
50-
Session $customerSession
47+
ContextBuilder $actionContextBuilder
5148
) {
5249
$this->action = $action;
5350
$this->actionContextBuilder = $actionContextBuilder;
54-
$this->customerSession = $customerSession;
55-
parent::__construct($request, $resultFactory, $messageManager, $config);
51+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
5652
}
5753

5854
protected function isAllowed(): bool

Controller/Privacy/UndoErase.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Model\Session;
1212
use Magento\Framework\App\Action\HttpPostActionInterface;
1313
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\App\Response\Http;
1415
use Magento\Framework\Controller\Result\Redirect;
1516
use Magento\Framework\Controller\ResultFactory;
1617
use Magento\Framework\Exception\LocalizedException;
@@ -24,11 +25,6 @@
2425

2526
class UndoErase extends AbstractPrivacy implements HttpPostActionInterface
2627
{
27-
/**
28-
* @var Session
29-
*/
30-
private $customerSession;
31-
3228
/**
3329
* @var ActionInterface
3430
*/
@@ -45,13 +41,13 @@ public function __construct(
4541
ManagerInterface $messageManager,
4642
Config $config,
4743
Session $customerSession,
44+
Http $response,
4845
ActionInterface $action,
4946
ContextBuilder $actionContextBuilder
5047
) {
51-
$this->customerSession = $customerSession;
5248
$this->action = $action;
5349
$this->actionContextBuilder = $actionContextBuilder;
54-
parent::__construct($request, $resultFactory, $messageManager, $config);
50+
parent::__construct($request, $resultFactory, $messageManager, $config, $customerSession, $response);
5551
}
5652

5753
protected function isAllowed(): bool

Model/Customer/Anonymize/Processor/CustomerDataProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function anonymizeCustomer(int $customerId): void
131131
$secureData = $this->customerRegistry->retrieveSecureData($customerId);
132132
$dateTime = (new DateTime())->setTimestamp(PHP_INT_MAX);
133133
$secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT));
134-
$secureData->setPasswordHash(sha1(uniqid(mt_rand(), true)));
134+
$secureData->setPasswordHash(sha1(uniqid((string) mt_rand(), true)));
135135

136136
$this->customerRepository->save(
137137
$this->anonymizer->anonymize($this->customerRepository->getById($customerId))

Model/Customer/SourceProvider/FilterModifier.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,38 @@
99

1010
use Magento\Framework\Api\Filter;
1111
use Magento\Framework\Data\Collection;
12-
use Magento\Framework\Exception\LocalizedException;
1312
use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface;
1413

1514
final class FilterModifier implements ModifierInterface
1615
{
17-
/**
18-
* @inheritdoc
19-
* @throws LocalizedException
20-
*/
2116
public function apply(Collection $collection, Filter $filter): void
2217
{
2318
if ($collection instanceof Collection\AbstractDb && $filter->getField() === 'created_at') {
2419
$connection = $collection->getConnection();
2520

2621
$visitorSelect = $connection->select()
27-
->from($connection->getTableName('customer_visitor'))
28-
->columns(['customer_id' => 'customer_id', 'last_visit_at' => 'MAX(last_visit_at)'])
22+
->from(
23+
$connection->getTableName('customer_visitor'),
24+
['customer_id' => 'customer_id', 'last_visit_at' => 'MAX(last_visit_at)']
25+
)
2926
->group(['customer_id']);
3027

3128
$collection->getSelect()->joinLeft(
3229
['cv' => $visitorSelect],
33-
'main_table.entity_id=cl.customer_id',
30+
'e.entity_id=cv.customer_id',
3431
null
3532
);
3633
$collection->getSelect()->joinLeft(
3734
['cl' => $connection->getTableName('customer_log')],
38-
'main_table.entity_id=cl.customer_id',
35+
'e.entity_id=cl.customer_id',
3936
null
4037
);
41-
$collection->getSelect()->columns(
42-
[
43-
'last_visit_at' => 'IFNULL(' .
44-
'cv.last_visit_at,'.
45-
'GREATEST(IFNULL(cl.last_login_at, e.created_at), IFNULL(cl.last_logout_at, e.updated_at))' .
46-
')',
47-
]
38+
$collection->getSelect()->where(
39+
$connection->prepareSqlCondition(
40+
'IFNULL(cv.last_visit_at, GREATEST(IFNULL(cl.last_login_at, e.created_at), IFNULL(cl.last_logout_at, e.updated_at)))',
41+
[$filter->getConditionType() => $filter->getValue()]
42+
)
4843
);
49-
$collection->addFieldToFilter('last_visit_at', [$filter->getConditionType() => $filter->getValue()]);
5044
}
5145
}
5246
}

Model/ExportEntityManagement.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Exception;
1212
use Magento\Framework\App\Config\ScopeConfigInterface;
1313
use Magento\Framework\Exception\AlreadyExistsException;
14-
use Magento\Framework\Exception\NoSuchEntityException;
1514
use Magento\Framework\Phrase;
1615
use Magento\Framework\Stdlib\DateTime as DateTimeFormat;
1716
use Magento\Store\Model\ScopeInterface;

Observer/DeleteExport.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
use Magento\Framework\Api\FilterBuilder;
1313
use Magento\Framework\Api\SearchCriteriaBuilder;
1414
use Magento\Framework\Api\SearchResultsInterface;
15+
use Magento\Framework\DataObject;
1516
use Magento\Framework\Event\Observer;
1617
use Magento\Framework\Event\ObserverInterface;
1718
use Magento\Framework\Exception\LocalizedException;
18-
use Magento\Framework\Model\AbstractModel;
1919
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
2020
use Opengento\Gdpr\Api\Data\ExportEntitySearchResultsInterface;
2121
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
@@ -65,27 +65,29 @@ public function __construct(
6565

6666
public function execute(Observer $observer): void
6767
{
68-
/** @var AbstractModel $entity */
68+
/** @var DataObject $entity */
6969
$entity = $observer->getData('data_object');
7070

71-
try {
72-
foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) {
73-
$this->exportRepository->delete($exportEntity);
71+
if ($entity instanceof DataObject) {
72+
try {
73+
foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) {
74+
$this->exportRepository->delete($exportEntity);
75+
}
76+
} catch (LocalizedException $e) {
77+
$this->logger->error($e->getLogMessage(), $e->getTrace());
78+
} catch (Exception $e) {
79+
$this->logger->error($e->getMessage(), $e->getTrace());
7480
}
75-
} catch (LocalizedException $e) {
76-
$this->logger->error($e->getLogMessage(), $e->getTrace());
77-
} catch (Exception $e) {
78-
$this->logger->error($e->getMessage(), $e->getTrace());
7981
}
8082
}
8183

8284
/**
83-
* @param AbstractModel $entity
85+
* @param DataObject $entity
8486
* @return ExportEntitySearchResultsInterface
8587
* @throws LocalizedException
8688
* @throws Exception
8789
*/
88-
private function fetchExportEntities(AbstractModel $entity): SearchResultsInterface
90+
private function fetchExportEntities(DataObject $entity): SearchResultsInterface
8991
{
9092
$entityTypes = $this->entityTypeResolver->resolve($entity);
9193

0 commit comments

Comments
 (0)