PHP library for Purging old data from database
<?php
namespace App\Module;
use Ambientia\DataCleaner\QueryProviderInterface;
use DateTime;
use Doctrine\Persistence\ManagerRegistry;
use Traversable;
class DataCleanerQueryProvider implements QueryProviderInterface
{
private $doctrine;
public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}
public function getItems(): Traversable
{
$qb = $this->doctrine->getManager()
->getRepository(Entity::class)
->createQueryBuilder('m');
$qb->setParameter('date', new DateTime('-3 months'));
$qb->andWhere($$qb->expr()->lte('m.ended', ':date'));
foreach ($qb->getQuery()->iterate() as $item) {
yield current($item);
}
}
}
* * * * * ambientia:data-cleaner
Run docker docker-composer up -d
Bash to container docker/bash.sh
Run php cs fixer ./vendor/bin/php-cs-fixer fix
Run tests with phpunit ./vendor/bin/phpunit
Run phan ./vendor/bin/phan