ambientia / data-cleaner
Purges old data from database
Installs: 1 247
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: 7.4.*
- doctrine/orm: ^2.8
- symfony/serializer-pack: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- phan/phan: ^2.2
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-20 20:36:51 UTC
README
PHP library for Purging old data from database
Creating provider
<?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);
}
}
}
Add cron
* * * * * ambientia:data-cleaner
developing
Run docker docker-composer up -d
Bash to container docker/bash.sh
Running code fixer
Run php cs fixer ./vendor/bin/php-cs-fixer fix
Running the tests
Run tests with phpunit ./vendor/bin/phpunit
Running analyzer
Run phan ./vendor/bin/phan