a4sex / auto-clean-entity
Abstract Doctrine Entity Cleaner
This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.
Installs: 153
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/a4sex/auto-clean-entity
Requires
- php: >=8.2.0
- a4sex/base-utilites: ^0.1.0
- symfony/uid: ^6.3
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-03-31 15:04:17 UTC
README
Create Cleaner for specific doctrine Entity
Entity MUST contain the id primary field and some date_time field
<?php
namespace App\Services\Cleaner;
use A4Sex\Services\AbstractCleaner; 
use App\Repository\MessageRepository;
class MessageCleaner extends AbstractCleaner
{  
    public $autocleanEnable = true;
    public $cleanDaysPeriod = 7;
    public $cleanDateField = 'date';
    // OR/AND Add batch cleaner params
    public function __construct(
        DialogRepository $repository
    ) {
        $this->repository = $repository;
    }
}
Some settings
    public $autocleanEnable = false; // default - disabled
    public $autocleanEvery = 10; // conditionally, each (divisible) - 10 - every tenth
    public $cleanDaysPeriod = 15; // more than a few days old
    public $cleanItemsCount = 100; // select no more items
    public $cleanDateField = 'updated'; // `db` datetime field 
Use auto cleaning
    // ...
    public function __construct(
        MessageCleaner $cleaner
    ) {
        $this->cleaner = $cleaner;
    }
    public function someFunction()
    {
        // ...
        $id = $this->user->getId(); // Some random/pseudorandom/regular number
        $this->cleaner->autoclean($id, 'updated');
        // OR
        $this->cleaner->autoclean($id); // 'updated' is default
        // or set const `$cleanDateField`
        // $id - required
        // if $id = 10 and `$autocleanEvery` = 10 - then cleanup will be called every time
        // if $id not divisible by 10 and `$autocleanEvery` = 10 - cleanup will not be called
    }
    // ...   
Batch Cleaner
Some settings
    public bool $batchCleanVerbose = false; // verbose output
    public int $cleanBatchPart = 1000; // count deleted items on iteration
    public int $batchItemsCount = 10000; // count all selected items
    public int $batchLoopDelay = 0; // delay between iterations
    // ...
    public function someFunction()
    {
        // ...
        $this->cleaner->batchclean('updated');
        // OR
        $this->cleaner->batchclean(); // 'updated' is default
        // or set const `$cleanDateField`
    }
    // ...