Skip to content

Commit

Permalink
Merge branch 'master' into magento2.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Jul 20, 2018
2 parents 94317d7 + a52be7e commit e03ac19
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions Cron/Erasure.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace Opengento\Gdpr\Cron;

use Magento\Framework\Api\Filter;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\Exception\LocalizedException;
Expand Down Expand Up @@ -54,36 +52,28 @@ class Erasure
*/
private $searchCriteriaBuilder;

/**
* @var \Magento\Framework\Api\FilterBuilder
*/
private $filterBuilder;

/**
* @param \Psr\Log\LoggerInterface $logger
* @param \Opengento\Gdpr\Model\Config $config
* @param \Magento\Framework\Registry $registry
* @param \Opengento\Gdpr\Api\EraseCustomerManagementInterface $eraseCustomerManagement
* @param \Opengento\Gdpr\Api\EraseCustomerRepositoryInterface $eraseCustomerRepository
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
*/
public function __construct(
LoggerInterface $logger,
Config $config,
Registry $registry,
EraseCustomerManagementInterface $eraseCustomerManagement,
EraseCustomerRepositoryInterface $eraseCustomerRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
FilterBuilder $filterBuilder
SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->logger = $logger;
$this->config = $config;
$this->registry = $registry;
$this->eraseCustomerManagement = $eraseCustomerManagement;
$this->eraseCustomerRepository = $eraseCustomerRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->filterBuilder = $filterBuilder;
}

/**
Expand Down Expand Up @@ -117,16 +107,17 @@ public function execute()
*/
private function retrieveEraseCustomerList(): SearchResultsInterface
{
$this->searchCriteriaBuilder->addFilters([
$this->createFilter(EraseCustomerInterface::SCHEDULED_AT, new \DateTime(), 'lteq'),
$this->createFilter(EraseCustomerInterface::STATE, EraseCustomerInterface::STATE_PENDING),
$this->createFilter(EraseCustomerInterface::STATUS, EraseCustomerInterface::STATUS_READY),
]);
$this->searchCriteriaBuilder->addFilters([
$this->createFilter(EraseCustomerInterface::SCHEDULED_AT, new \DateTime(), 'lteq'),
$this->createFilter(EraseCustomerInterface::STATE, EraseCustomerInterface::STATE_PROCESSING),
$this->createFilter(EraseCustomerInterface::STATUS, EraseCustomerInterface::STATUS_FAILED),
]);
$this->searchCriteriaBuilder->addFilter(EraseCustomerInterface::SCHEDULED_AT, new \DateTime(), 'lteq');
$this->searchCriteriaBuilder->addFilter(
EraseCustomerInterface::STATE,
EraseCustomerInterface::STATE_COMPLETE,
'neq'
);
$this->searchCriteriaBuilder->addFilter(
EraseCustomerInterface::STATUS,
[EraseCustomerInterface::STATUS_READY, EraseCustomerInterface::STATUS_FAILED],
'in'
);

try {
$eraseCustomerList = $this->eraseCustomerRepository->getList($this->searchCriteriaBuilder->create());
Expand All @@ -136,21 +127,4 @@ private function retrieveEraseCustomerList(): SearchResultsInterface

return $eraseCustomerList;
}

/**
* Create a new search criteria filter
*
* @param string $field
* @param array|string $value
* @param string $conditionType
* @return \Magento\Framework\Api\Filter
*/
private function createFilter(string $field, $value, string $conditionType = 'eq'): Filter
{
$this->filterBuilder->setField($field);
$this->filterBuilder->setValue($value);
$this->filterBuilder->setConditionType($conditionType);

return $this->filterBuilder->create();
}
}

0 comments on commit e03ac19

Please sign in to comment.