Skip to content

Commit c8ae934

Browse files
committed
Fix #128 erase already erased entities result in duplicated entries
1 parent 970caf8 commit c8ae934

12 files changed

+148
-26
lines changed

Model/Customer/SourceProvider/FilterModifier.php Model/Customer/SourceProvider/IdleFilterModifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Data\Collection;
1212
use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface;
1313

14-
final class FilterModifier implements ModifierInterface
14+
final class IdleFilterModifier implements ModifierInterface
1515
{
1616
public function apply(Collection $collection, Filter $filter): void
1717
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Opengento\Gdpr\Model\Entity\SourceProvider;
9+
10+
use Magento\Framework\Api\Filter;
11+
use Magento\Framework\Data\Collection;
12+
use Magento\Framework\Data\Collection\AbstractDb;
13+
use function sprintf;
14+
15+
final class NotErasedFilterModifier implements ModifierInterface
16+
{
17+
private const DEFAULT_PRIMARY_FIELD = 'entity_id';
18+
19+
private const DEFAULT_MAIN_TABLE_ALIAS = 'main_table';
20+
21+
private const JOIN_ON = '%s.%s=ogee.entity_id AND ogee.entity_type="%s"';
22+
23+
private string $entityType;
24+
25+
private string $entityPrimaryField;
26+
27+
private string $mainTableAlias;
28+
29+
public function __construct(
30+
string $entityType,
31+
string $entityPrimaryField = self::DEFAULT_PRIMARY_FIELD,
32+
string $mainTableAlias = self::DEFAULT_MAIN_TABLE_ALIAS
33+
) {
34+
$this->entityType = $entityType;
35+
$this->entityPrimaryField = $entityPrimaryField;
36+
$this->mainTableAlias = $mainTableAlias;
37+
}
38+
39+
public function apply(Collection $collection, Filter $filter): void
40+
{
41+
if ($collection instanceof AbstractDb) {
42+
$connection = $collection->getConnection();
43+
$select = $collection->getSelect();
44+
$select->joinLeft(
45+
['ogee' => $connection->getTableName('opengento_gdpr_erase_entity')],
46+
sprintf(self::JOIN_ON, $this->mainTableAlias, $this->entityPrimaryField, $this->entityType),
47+
['']
48+
);
49+
$select->where('ogee.erase_id IS NULL');
50+
}
51+
}
52+
}

Model/EraseEntityManagement.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ final class EraseEntityManagement implements EraseEntityManagementInterface
3333

3434
private ScopeConfigInterface $scopeConfig;
3535

36-
/**
37-
* @var DateTime
38-
*/
3936
private DateTime $localeDate;
4037

4138
public function __construct(
@@ -78,11 +75,7 @@ public function process(EraseEntityInterface $entity): EraseEntityInterface
7875
$eraser = $this->processorFactory->get($entity->getEntityType());
7976

8077
try {
81-
if ($eraser->execute($entity->getEntityId())) {
82-
return $this->success($entity);
83-
}
84-
85-
return $this->fail($entity);
78+
return $eraser->execute($entity->getEntityId()) ? $this->success($entity) : $this->fail($entity);
8679
} catch (Exception $e) {
8780
$this->fail($entity, $e->getMessage());
8881
throw new LocalizedException(new Phrase('Impossible to process the erasure: %1', [$e->getMessage()]));
@@ -127,7 +120,7 @@ private function retrieveScheduledAt(): string
127120
);
128121
}
129122

130-
public function resolveErasureDelay(): int
123+
private function resolveErasureDelay(): int
131124
{
132125
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);
133126
}

Model/Order/SourceProvider/GuestModifier.php Model/Order/SourceProvider/GuestFilterModifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Opengento\Gdpr\Model\Config;
1515
use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface;
1616

17-
final class GuestModifier implements ModifierInterface
17+
final class GuestFilterModifier implements ModifierInterface
1818
{
1919
private Config $config;
2020

etc/db_schema.xml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<constraint xsi:type="primary" referenceId="PRIMARY">
1919
<column name="erase_id"/>
2020
</constraint>
21+
<!--<constraint xsi:type="unique" referenceId="OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID_ENTITY_TYPE">
22+
<column name="entity_id"/>
23+
<column name="entity_type"/>
24+
</constraint>-->
2125
<index referenceId="OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID" indexType="btree">
2226
<column name="entity_id"/>
2327
</index>

etc/db_schema_whitelist.json

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"opengento_gdpr_erase_entity": {
3+
"column": {
4+
"erase_id": true,
5+
"entity_id": true,
6+
"entity_type": true,
7+
"scheduled_at": true,
8+
"state": true,
9+
"status": true,
10+
"message": true,
11+
"erased_at": true
12+
},
13+
"index": {
14+
"OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID": true,
15+
"OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_TYPE": true
16+
},
17+
"constraint": {
18+
"PRIMARY": true,
19+
"OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID_ENTITY_TYPE": true
20+
}
21+
},
22+
"opengento_gdpr_export_entity": {
23+
"column": {
24+
"export_id": true,
25+
"entity_id": true,
26+
"entity_type": true,
27+
"file_name": true,
28+
"file_path": true,
29+
"created_at": true,
30+
"exported_at": true,
31+
"expired_at": true
32+
},
33+
"index": {
34+
"OPENGENTO_GDPR_EXPORT_ENTITY_ENTITY_ID": true,
35+
"OPENGENTO_GDPR_EXPORT_ENTITY_ENTITY_TYPE": true
36+
},
37+
"constraint": {
38+
"PRIMARY": true
39+
}
40+
},
41+
"opengento_gdpr_action_entity": {
42+
"column": {
43+
"action_id": true,
44+
"type": true,
45+
"performed_from": true,
46+
"performed_by": true,
47+
"performed_at": true,
48+
"state": true,
49+
"message": true,
50+
"parameters": true
51+
},
52+
"index": {
53+
"OPENGENTO_GDPR_ACTION_ENTITY_TYPE": true,
54+
"OPENGENTO_GDPR_ACTION_ENTITY_STATE": true
55+
},
56+
"constraint": {
57+
"PRIMARY": true
58+
}
59+
}
60+
}

etc/di.xml

+17-4
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,17 @@
765765
<argument name="eraseComponents" xsi:type="object">Opengento\Gdpr\Model\Config\Source\Customer\EraseComponents</argument>
766766
</arguments>
767767
</virtualType>
768+
<virtualType name="Opengento\Gdpr\Model\Customer\SourceProvider\NotErasedFilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\NotErasedFilterModifier">
769+
<arguments>
770+
<argument name="entityType" xsi:type="string">customer</argument>
771+
<argument name="mainTableAlias" xsi:type="string">e</argument>
772+
</arguments>
773+
</virtualType>
768774
<virtualType name="Opengento\Gdpr\Model\Customer\SourceProvider\ModifierComposite" type="Opengento\Gdpr\Model\Entity\SourceProvider\ModifierComposite">
769775
<arguments>
770776
<argument name="modifiers" xsi:type="array">
771-
<item name="filter" xsi:type="object">Opengento\Gdpr\Model\Customer\SourceProvider\FilterModifier</item>
777+
<item name="idleFilter" xsi:type="object">Opengento\Gdpr\Model\Customer\SourceProvider\IdleFilterModifier</item>
778+
<item name="notErasedFilter" xsi:type="object">Opengento\Gdpr\Model\Customer\SourceProvider\NotErasedFilterModifier</item>
772779
</argument>
773780
</arguments>
774781
</virtualType>
@@ -821,17 +828,23 @@
821828
<argument name="eraseComponents" xsi:type="object">Opengento\Gdpr\Model\Config\Source\Order\EraseComponents</argument>
822829
</arguments>
823830
</virtualType>
824-
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\FilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\FilterModifier">
831+
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\UpdatedAtFilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\FilterModifier">
825832
<arguments>
826833
<argument name="filterIdentifier" xsi:type="string">created_at</argument>
827834
<argument name="fieldToFilter" xsi:type="const">Magento\Sales\Api\Data\OrderInterface::UPDATED_AT</argument>
828835
</arguments>
829836
</virtualType>
837+
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\NotErasedFilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\NotErasedFilterModifier">
838+
<arguments>
839+
<argument name="entityType" xsi:type="string">order</argument>
840+
</arguments>
841+
</virtualType>
830842
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\ModifierComposite" type="Opengento\Gdpr\Model\Entity\SourceProvider\ModifierComposite">
831843
<arguments>
832844
<argument name="modifiers" xsi:type="array">
833-
<item name="guest" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\GuestModifier</item>
834-
<item name="filter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\FilterModifier</item>
845+
<item name="guestFilter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\GuestFilterModifier</item>
846+
<item name="updatedAtFilter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\UpdatedAtFilterModifier</item>
847+
<item name="notErasedFilter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\NotErasedFilterModifier</item>
835848
</argument>
836849
</arguments>
837850
</virtualType>

view/base/layout/customer_privacy_export_personal_data.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</head>
1515
<body>
1616
<referenceContainer name="main">
17-
<block class="Magento\Framework\View\Element\Template" name="main.content.customer.privacy.export.personal.data" template="Opengento_Gdpr::export/result.phtml" cacheable="false"/>
17+
<block name="main.content.customer.privacy.export.personal.data" template="Opengento_Gdpr::export/result.phtml" cacheable="false"/>
1818
</referenceContainer>
1919
</body>
2020
</page>

view/base/layout/customer_privacy_export_personal_data_renderers.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
99
<block class="Magento\Framework\View\Element\RendererList" name="opengento.gdpr.customer.privacy.export.renderers">
10-
<block class="Magento\Framework\View\Element\Template" name="opengento.gdpr.customer.privacy.export.renderers.default" as="default"/>
10+
<block name="opengento.gdpr.customer.privacy.export.renderers.default" as="default"/>
1111
</block>
1212
</layout>

view/frontend/layout/customer_privacy_erase.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</arguments>
1818
</referenceBlock>
1919
<referenceContainer name="content">
20-
<block class="Magento\Framework\View\Element\Template" name="customer-account-privacy-erase" template="Opengento_Gdpr::account/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
20+
<block name="customer-account-privacy-erase" template="Opengento_Gdpr::account/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
2121
<arguments>
2222
<argument name="settingsDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\SettingsDataProvider</argument>
2323
<argument name="eraseActionUrl" xsi:type="url" path="customer/privacy/erasepost"/>

view/frontend/layout/customer_privacy_settings.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
</head>
1313
<body>
1414
<referenceContainer name="content">
15-
<block class="Magento\Framework\View\Element\Template" name="customer-account-privacy-settings" template="Opengento_Gdpr::account/settings.phtml" ifconfig="gdpr/general/enabled" cacheable="false">
15+
<block name="customer-account-privacy-settings" template="Opengento_Gdpr::account/settings.phtml" ifconfig="gdpr/general/enabled" cacheable="false">
1616
<arguments>
1717
<argument name="settingsDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\SettingsDataProvider</argument>
1818
</arguments>
19-
<block class="Magento\Framework\View\Element\Template" name="customer-account-privacy-export" as="export" template="Opengento_Gdpr::account/privacy/export.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
19+
<block name="customer-account-privacy-export" as="export" template="Opengento_Gdpr::account/privacy/export.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
2020
<arguments>
2121
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\ExportDataProvider</argument>
2222
<argument name="exportCustomerDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\ExportCustomerDataProvider</argument>
2323
<argument name="exportActionUrl" xsi:type="url" path="customer/privacy/export"/>
2424
<argument name="downloadActionUrl" xsi:type="url" path="customer/privacy/download"/>
2525
</arguments>
2626
</block>
27-
<block class="Magento\Framework\View\Element\Template" name="customer-account-privacy-erasure" as="erasure" template="Opengento_Gdpr::account/privacy/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
27+
<block name="customer-account-privacy-erasure" as="erasure" template="Opengento_Gdpr::account/privacy/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
2828
<arguments>
2929
<argument name="eraseDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\EraseDataProvider</argument>
3030
<argument name="eraseCustomerDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\EraseCustomerDataProvider</argument>

view/frontend/layout/sales_guest_view.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceBlock name="sales.order.info.buttons">
11-
<block class="Magento\Framework\View\Element\Template" name="sales.order.info.buttons.export" as="buttons.export" template="Opengento_Gdpr::order/info/buttons/export.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
11+
<block name="sales.order.info.buttons.export" as="buttons.export" template="Opengento_Gdpr::order/info/buttons/export.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
1212
<arguments>
1313
<argument name="actionUrl" xsi:type="url" path="customer/guest/export"/>
1414
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Guest\ExportDataProvider</argument>
1515
</arguments>
1616
</block>
17-
<block class="Magento\Framework\View\Element\Template" name="sales.order.info.buttons.export.download" as="buttons.export.download" template="Opengento_Gdpr::order/info/buttons/download.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
17+
<block name="sales.order.info.buttons.export.download" as="buttons.export.download" template="Opengento_Gdpr::order/info/buttons/download.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
1818
<arguments>
1919
<argument name="actionUrl" xsi:type="url" path="customer/guest/download"/>
2020
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Guest\ExportDataProvider</argument>
2121
</arguments>
2222
</block>
23-
<block class="Magento\Framework\View\Element\Template" name="sales.order.info.buttons.erase" as="buttons.erase" template="Opengento_Gdpr::order/info/buttons/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
23+
<block name="sales.order.info.buttons.erase" as="buttons.erase" template="Opengento_Gdpr::order/info/buttons/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
2424
<arguments>
2525
<argument name="eraseActionUrl" xsi:type="url" path="customer/guest/erase"/>
2626
<argument name="undoActionUrl" xsi:type="url" path="customer/guest/undoerase"/>
@@ -29,12 +29,12 @@
2929
</block>
3030
</referenceBlock>
3131
<referenceContainer name="content">
32-
<block class="Magento\Framework\View\Element\Template" name="sales.order.info.export" template="Opengento_Gdpr::order/info/export.phtml" ifconfig="gdpr/export/enabled">
32+
<block name="sales.order.info.export" template="Opengento_Gdpr::order/info/export.phtml" ifconfig="gdpr/export/enabled">
3333
<arguments>
3434
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\ExportDataProvider</argument>
3535
</arguments>
3636
</block>
37-
<block class="Magento\Framework\View\Element\Template" name="sales.order.info.erase" template="Opengento_Gdpr::order/info/erase.phtml" ifconfig="gdpr/erasure/enabled">
37+
<block name="sales.order.info.erase" template="Opengento_Gdpr::order/info/erase.phtml" ifconfig="gdpr/erasure/enabled">
3838
<arguments>
3939
<argument name="eraseDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\EraseDataProvider</argument>
4040
</arguments>

0 commit comments

Comments
 (0)