freedomsex/auto-clean-entity

This package is abandoned and no longer maintained. The author suggests using the a4sex/auto-clean-entity package instead.

Abstract Doctrine Entity Cleaner

2.1.10 2022-11-01 23:29 UTC

This package is auto-updated.

Last update: 2023-04-04 17:48: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 FreedomSex\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`
    }
    // ...