MMOframework
Pourquoi l'IA Playground Bibliothèques Développeurs Agence
FR EN
Créer un projet en direct
Index

Retention

MMO\core\helpers · 1 symbole · générée le 30 Nov 2026

class

Retention

Retention.php:28

How long the documents of a collection are kept (ISO/IEC 27001 A.8.10, A.5.33), and the purge of those past it.

class MMO\core\helpers\Retention use MMO\core\classes\tSingleton
Espace de noms
MMO\core\helpers
Utilise les traits
tSingleton
Nothing is declared by default: no document is purged before the project decides its durations. Each collection declares `days` (how long a document is kept), the date it counts from (`field`, `ctime` by default) and a `filter` narrowing what is purged (only the archived ones, for instance). The purge is a simulation by default ([`purge`](https://mmoframework.fr/documentation/mmo.core/php/helpers/Retention.md#retention-purge)): it counts and lists, it deletes nothing. Applied, it deletes through the entities (`removePermanently()` then `\MMO\commit()`): the journal records each deletion as any other. Either way it writes a report, with the `_id` of every document deleted (or to delete), into [`$reportFolder`](https://mmoframework.fr/documentation/mmo.core/php/helpers/Retention.md#retention-reportfolder): what was deleted can be checked, and the data guard of a reprise (my.oviepro's `data-guard compare --expect=retention`) declares it. A journal (a `LogQuery` collection: a hash chain) is purged by its repository's `purgeLogs()` when it has one (MongoRepository): its oldest lines only, the purge sealed, so that `log-verify` still finds the chain whole; it counts from `ctime`, every kind of line alike (writes and READs of `sante` data).
// configs/config.json "MMO\\core\\helpers\\Retention": {"collections": {"logQuerys": {"days": 1095}, "mailLogs": {"days": 365}}} $report = Retention::Shared()->purge(\MMO\get('repository')); // the simulation: what would go $report = Retention::Shared()->purge(\MMO\get('repository'), false); // the purge

Index

batch
collections
reportFolder
declaration($collection)
Instantiate($config) static(Re)create the shared instance immediately, configured with $config merged into the class's existing config.
IsShared() static
purge($repository, $dryRun, $only, $now)The documents of each collection declared past their duration: counted and listed (a simulation, the default), or deleted.
Shared() staticGet the shared instance, creating (and configuring) it on first call.
Unshare($serialize) staticRemove the shared instance, so the next Shared() call creates a fresh one.
writeReport($report, $kind)

Propriétés3

batch

int $batch = 200
Type
int

collections

array $collections = []
Type
array

reportFolder

string $reportFolder = '{root}/db/retention'
Type
string

Méthodes7

declaration($collection)

Retention.php:43
function declaration(string $collection): array
$collectionstring
retournearrayint, field: string, filter: array<string, mixed>, label: string} its declaration, checked
lèvefor a duration that is not a number of days

Instantiate($config)

statictSingleton.php:66

(Re)create the shared instance immediately, configured with $config merged into the class's existing config.

static function Instantiate(array $config = []): staticUnlike a plain [`Shared()`](https://mmoframework.fr/documentation/mmo.core/php/helpers/Retention.md#retention-shared) call (which lazily builds the instance from whatever config was already loaded), this lets you supply/override config right before the instance is built.
$config = []arrayconfig values merged in before the instance is constructed
retournestaticthe newly (re)created shared instance
MyService::Instantiate(['greeting' => 'yo'])->greeting; // 'yo'

IsShared()

statictSingleton.php:54
static function IsShared(): bool
retournebooltrue if the shared instance has already been created (a call to Shared() would not need to construct a new one)
MyService::IsShared(); // false until the first MyService::Shared() call

purge($repository, $dryRun, $only, $now)

Retention.php:61

The documents of each collection declared past their duration: counted and listed (a simulation, the default), or deleted.

function purge( MMO\core\interfaces\iRepository $repository, bool $dryRun = true, ?array $only = null, ?DateTimeInterface $now = null ): array
$repositoryiRepository
$dryRun = truebooltrue (the default): delete nothing
$only = nullnull | arraythese collections only (of those declared)
$now = nullnull | DateTimeInterfacethe date the durations count back from (now)
retournearraystring, dryRun: bool, collections: array<string, array{days: int, field: string, before: string, count: int, deleted: int, ids: list<string>, refused: array<string, string>}>, documents: int, report: string|null} refused: the documents a purge kept, another one referring to them (by id, why)

Shared()

statictSingleton.php:22

Get the shared instance, creating (and configuring) it on first call.

static function Shared(): static
retournestatic
MyService::Shared()->greeting; // 'hello'

Unshare($serialize)

statictSingleton.php:40

Remove the shared instance, so the next Shared() call creates a fresh one.

static function Unshare(bool $serialize = true): bool
Voir
serialize) and kept as the class's config, so the next instance created picks up where this one left off; if false, the instance is simply discarded and the next one starts from the class's original config
$serialize = trueboolif true (the default) and an instance currently exists, it is serialized first (via
retournebooltrue if an instance actually existed and was removed
MyService::Unshare(); // true if MyService::Shared() had already been called; the next call rebuilds it