Skip to content

Commit

Permalink
Fix #128 erase already erased entities result in duplicated entries
Browse files Browse the repository at this point in the history
thomas-kl1 committed Aug 13, 2022
1 parent 970caf8 commit c8ae934
Showing 12 changed files with 148 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
use Magento\Framework\Data\Collection;
use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface;

final class FilterModifier implements ModifierInterface
final class IdleFilterModifier implements ModifierInterface
{
public function apply(Collection $collection, Filter $filter): void
{
52 changes: 52 additions & 0 deletions Model/Entity/SourceProvider/NotErasedFilterModifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Model\Entity\SourceProvider;

use Magento\Framework\Api\Filter;
use Magento\Framework\Data\Collection;
use Magento\Framework\Data\Collection\AbstractDb;
use function sprintf;

final class NotErasedFilterModifier implements ModifierInterface
{
private const DEFAULT_PRIMARY_FIELD = 'entity_id';

private const DEFAULT_MAIN_TABLE_ALIAS = 'main_table';

private const JOIN_ON = '%s.%s=ogee.entity_id AND ogee.entity_type="%s"';

private string $entityType;

private string $entityPrimaryField;

private string $mainTableAlias;

public function __construct(
string $entityType,
string $entityPrimaryField = self::DEFAULT_PRIMARY_FIELD,
string $mainTableAlias = self::DEFAULT_MAIN_TABLE_ALIAS
) {
$this->entityType = $entityType;
$this->entityPrimaryField = $entityPrimaryField;
$this->mainTableAlias = $mainTableAlias;
}

public function apply(Collection $collection, Filter $filter): void
{
if ($collection instanceof AbstractDb) {
$connection = $collection->getConnection();
$select = $collection->getSelect();
$select->joinLeft(
['ogee' => $connection->getTableName('opengento_gdpr_erase_entity')],
sprintf(self::JOIN_ON, $this->mainTableAlias, $this->entityPrimaryField, $this->entityType),
['']
);
$select->where('ogee.erase_id IS NULL');
}
}
}
11 changes: 2 additions & 9 deletions Model/EraseEntityManagement.php
Original file line number Diff line number Diff line change
@@ -33,9 +33,6 @@ final class EraseEntityManagement implements EraseEntityManagementInterface

private ScopeConfigInterface $scopeConfig;

/**
* @var DateTime
*/
private DateTime $localeDate;

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

try {
if ($eraser->execute($entity->getEntityId())) {
return $this->success($entity);
}

return $this->fail($entity);
return $eraser->execute($entity->getEntityId()) ? $this->success($entity) : $this->fail($entity);
} catch (Exception $e) {
$this->fail($entity, $e->getMessage());
throw new LocalizedException(new Phrase('Impossible to process the erasure: %1', [$e->getMessage()]));
@@ -127,7 +120,7 @@ private function retrieveScheduledAt(): string
);
}

public function resolveErasureDelay(): int
private function resolveErasureDelay(): int
{
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);
}
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
use Opengento\Gdpr\Model\Config;
use Opengento\Gdpr\Model\Entity\SourceProvider\ModifierInterface;

final class GuestModifier implements ModifierInterface
final class GuestFilterModifier implements ModifierInterface
{
private Config $config;

4 changes: 4 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="erase_id"/>
</constraint>
<!--<constraint xsi:type="unique" referenceId="OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID_ENTITY_TYPE">
<column name="entity_id"/>
<column name="entity_type"/>
</constraint>-->
<index referenceId="OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID" indexType="btree">
<column name="entity_id"/>
</index>
60 changes: 60 additions & 0 deletions etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"opengento_gdpr_erase_entity": {
"column": {
"erase_id": true,
"entity_id": true,
"entity_type": true,
"scheduled_at": true,
"state": true,
"status": true,
"message": true,
"erased_at": true
},
"index": {
"OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID": true,
"OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_TYPE": true
},
"constraint": {
"PRIMARY": true,
"OPENGENTO_GDPR_ERASE_ENTITY_ENTITY_ID_ENTITY_TYPE": true
}
},
"opengento_gdpr_export_entity": {
"column": {
"export_id": true,
"entity_id": true,
"entity_type": true,
"file_name": true,
"file_path": true,
"created_at": true,
"exported_at": true,
"expired_at": true
},
"index": {
"OPENGENTO_GDPR_EXPORT_ENTITY_ENTITY_ID": true,
"OPENGENTO_GDPR_EXPORT_ENTITY_ENTITY_TYPE": true
},
"constraint": {
"PRIMARY": true
}
},
"opengento_gdpr_action_entity": {
"column": {
"action_id": true,
"type": true,
"performed_from": true,
"performed_by": true,
"performed_at": true,
"state": true,
"message": true,
"parameters": true
},
"index": {
"OPENGENTO_GDPR_ACTION_ENTITY_TYPE": true,
"OPENGENTO_GDPR_ACTION_ENTITY_STATE": true
},
"constraint": {
"PRIMARY": true
}
}
}
21 changes: 17 additions & 4 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -765,10 +765,17 @@
<argument name="eraseComponents" xsi:type="object">Opengento\Gdpr\Model\Config\Source\Customer\EraseComponents</argument>
</arguments>
</virtualType>
<virtualType name="Opengento\Gdpr\Model\Customer\SourceProvider\NotErasedFilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\NotErasedFilterModifier">
<arguments>
<argument name="entityType" xsi:type="string">customer</argument>
<argument name="mainTableAlias" xsi:type="string">e</argument>
</arguments>
</virtualType>
<virtualType name="Opengento\Gdpr\Model\Customer\SourceProvider\ModifierComposite" type="Opengento\Gdpr\Model\Entity\SourceProvider\ModifierComposite">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="filter" xsi:type="object">Opengento\Gdpr\Model\Customer\SourceProvider\FilterModifier</item>
<item name="idleFilter" xsi:type="object">Opengento\Gdpr\Model\Customer\SourceProvider\IdleFilterModifier</item>
<item name="notErasedFilter" xsi:type="object">Opengento\Gdpr\Model\Customer\SourceProvider\NotErasedFilterModifier</item>
</argument>
</arguments>
</virtualType>
@@ -821,17 +828,23 @@
<argument name="eraseComponents" xsi:type="object">Opengento\Gdpr\Model\Config\Source\Order\EraseComponents</argument>
</arguments>
</virtualType>
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\FilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\FilterModifier">
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\UpdatedAtFilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\FilterModifier">
<arguments>
<argument name="filterIdentifier" xsi:type="string">created_at</argument>
<argument name="fieldToFilter" xsi:type="const">Magento\Sales\Api\Data\OrderInterface::UPDATED_AT</argument>
</arguments>
</virtualType>
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\NotErasedFilterModifier" type="Opengento\Gdpr\Model\Entity\SourceProvider\NotErasedFilterModifier">
<arguments>
<argument name="entityType" xsi:type="string">order</argument>
</arguments>
</virtualType>
<virtualType name="Opengento\Gdpr\Model\Order\SourceProvider\ModifierComposite" type="Opengento\Gdpr\Model\Entity\SourceProvider\ModifierComposite">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="guest" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\GuestModifier</item>
<item name="filter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\FilterModifier</item>
<item name="guestFilter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\GuestFilterModifier</item>
<item name="updatedAtFilter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\UpdatedAtFilterModifier</item>
<item name="notErasedFilter" xsi:type="object">Opengento\Gdpr\Model\Order\SourceProvider\NotErasedFilterModifier</item>
</argument>
</arguments>
</virtualType>
2 changes: 1 addition & 1 deletion view/base/layout/customer_privacy_export_personal_data.xml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
</head>
<body>
<referenceContainer name="main">
<block class="Magento\Framework\View\Element\Template" name="main.content.customer.privacy.export.personal.data" template="Opengento_Gdpr::export/result.phtml" cacheable="false"/>
<block name="main.content.customer.privacy.export.personal.data" template="Opengento_Gdpr::export/result.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<block class="Magento\Framework\View\Element\RendererList" name="opengento.gdpr.customer.privacy.export.renderers">
<block class="Magento\Framework\View\Element\Template" name="opengento.gdpr.customer.privacy.export.renderers.default" as="default"/>
<block name="opengento.gdpr.customer.privacy.export.renderers.default" as="default"/>
</block>
</layout>
2 changes: 1 addition & 1 deletion view/frontend/layout/customer_privacy_erase.xml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
</arguments>
</referenceBlock>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="customer-account-privacy-erase" template="Opengento_Gdpr::account/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
<block name="customer-account-privacy-erase" template="Opengento_Gdpr::account/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
<arguments>
<argument name="settingsDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\SettingsDataProvider</argument>
<argument name="eraseActionUrl" xsi:type="url" path="customer/privacy/erasepost"/>
6 changes: 3 additions & 3 deletions view/frontend/layout/customer_privacy_settings.xml
Original file line number Diff line number Diff line change
@@ -12,19 +12,19 @@
</head>
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="customer-account-privacy-settings" template="Opengento_Gdpr::account/settings.phtml" ifconfig="gdpr/general/enabled" cacheable="false">
<block name="customer-account-privacy-settings" template="Opengento_Gdpr::account/settings.phtml" ifconfig="gdpr/general/enabled" cacheable="false">
<arguments>
<argument name="settingsDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\SettingsDataProvider</argument>
</arguments>
<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">
<block name="customer-account-privacy-export" as="export" template="Opengento_Gdpr::account/privacy/export.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
<arguments>
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\ExportDataProvider</argument>
<argument name="exportCustomerDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\ExportCustomerDataProvider</argument>
<argument name="exportActionUrl" xsi:type="url" path="customer/privacy/export"/>
<argument name="downloadActionUrl" xsi:type="url" path="customer/privacy/download"/>
</arguments>
</block>
<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">
<block name="customer-account-privacy-erasure" as="erasure" template="Opengento_Gdpr::account/privacy/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
<arguments>
<argument name="eraseDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\EraseDataProvider</argument>
<argument name="eraseCustomerDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\EraseCustomerDataProvider</argument>
10 changes: 5 additions & 5 deletions view/frontend/layout/sales_guest_view.xml
Original file line number Diff line number Diff line change
@@ -8,19 +8,19 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="sales.order.info.buttons">
<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">
<block name="sales.order.info.buttons.export" as="buttons.export" template="Opengento_Gdpr::order/info/buttons/export.phtml" ifconfig="gdpr/export/enabled" cacheable="false">
<arguments>
<argument name="actionUrl" xsi:type="url" path="customer/guest/export"/>
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Guest\ExportDataProvider</argument>
</arguments>
</block>
<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">
<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">
<arguments>
<argument name="actionUrl" xsi:type="url" path="customer/guest/download"/>
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Guest\ExportDataProvider</argument>
</arguments>
</block>
<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">
<block name="sales.order.info.buttons.erase" as="buttons.erase" template="Opengento_Gdpr::order/info/buttons/erase.phtml" ifconfig="gdpr/erasure/enabled" cacheable="false">
<arguments>
<argument name="eraseActionUrl" xsi:type="url" path="customer/guest/erase"/>
<argument name="undoActionUrl" xsi:type="url" path="customer/guest/undoerase"/>
@@ -29,12 +29,12 @@
</block>
</referenceBlock>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="sales.order.info.export" template="Opengento_Gdpr::order/info/export.phtml" ifconfig="gdpr/export/enabled">
<block name="sales.order.info.export" template="Opengento_Gdpr::order/info/export.phtml" ifconfig="gdpr/export/enabled">
<arguments>
<argument name="exportDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\ExportDataProvider</argument>
</arguments>
</block>
<block class="Magento\Framework\View\Element\Template" name="sales.order.info.erase" template="Opengento_Gdpr::order/info/erase.phtml" ifconfig="gdpr/erasure/enabled">
<block name="sales.order.info.erase" template="Opengento_Gdpr::order/info/erase.phtml" ifconfig="gdpr/erasure/enabled">
<arguments>
<argument name="eraseDataProvider" xsi:type="object">Opengento\Gdpr\ViewModel\Customer\Privacy\EraseDataProvider</argument>
</arguments>

0 comments on commit c8ae934

Please sign in to comment.