|
| 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 | +} |
0 commit comments