# The life of the data: retention, purge, a person's export and erasure
What mmo.core gives a project for ISO/IEC 27001 A.8.10, A.5.33 and A.5.34 (GDPR articles 15 and 17). Both helpers are
configured by the project and do nothing by default; both commands are a simulation unless `--apply` is given, and
write their report.
| class | what it does |
|---|---|
| `MMO\core\helpers\Retention` | how long the documents of a collection are kept, and the purge of those past it |
| `MMO\core\helpers\PersonalData` | the documents of a person and those that refer to her: found, exported, erased |
| `MMO\core\controllers\DataLifecycleShellController` | the commands `retention`, `gdpr-export`, `gdpr-erase` |
List the controller in the routes of the application's command line
(`'=routes' => [..., \MMO\core\controllers\DataLifecycleShellController::class, ...]`). Its `repository` is the
application's `repository` unless configured; `--database=` reads another database of the same server (a
MongoRepository), a copy to try a command on.
## Retention durations and the purge
```json
"MMO\\core\\helpers\\Retention": {
"collections": {
"logQuerys": {"days": 1095},
"mailLogs": {"days": 365, "field": "ctime"},
"declarations": {"days": 3650, "field": "closed", "filter": {"status": "ARCHIVE"}}
},
"reportFolder": "{root}/db/retention"
}
```
- `days`: how long a document is kept, a whole number of days; `field`: the date it counts from (`ctime` by default);
`filter`: what may be purged among them (the archived ones only...).
- **Nothing is declared by default**: no document is purged before the project decides its durations.
- `php admin.php retention` counts, collection by collection, what is past its duration, and writes the report of what
would go: a simulation, nothing is deleted.
- `php admin.php retention --apply` deletes them through the entities (`removePermanently()`, then `\MMO\commit()`), a
page at a time: the journal records each deletion. A document another one still refers to is kept
(`Entity::removePermanently` refuses it) and listed under `refused`.
- A journal (a `LogQuery` collection: a hash chain when `logChain` is on) 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 -- a deletion line by line would break it. It counts from `ctime`, every kind of line alike (the writes
and the READ lines of `sante` data); its lines are counted, not listed.
- Each run writes `{reportFolder}/retention-[-simulation].json` (mode 600): the cutoff of each collection and the
`_id` of every document deleted, or to delete. What was deleted can be checked afterwards; my.oviepro's data guard
declares it (`data-guard compare --expect=retention`).
- Once decided, it is a cron job: `cron-add "0 3 * * 0" php admin.php retention --apply`.
## A person's data
```json
"MMO\\core\\helpers\\PersonalData": {
"follow": ["contrats"],
"erase": {"contrats": "anonymize", "notes": "delete"},
"depth": 3
}
```
A person is named by her document, `/`. What refers to her is found through the schemas: every stored
property, of any collection, whose entity is hers (`Contrat::$salarie` for a `Salarie`). The documents found in a
collection of `follow` are followed in turn (a contract's accidents), `depth` levels at most.
- `php admin.php gdpr-export salaries/ [--out=]` (read only): her document and those that refer to her, as
their entities export them (a reference as its uid, a date as ISO 8601). The export is logged (`GDPR EXPORT`). It
holds personal and health data: hand it over by a channel that protects it.
- `php admin.php gdpr-erase salaries/`: what erasing her does, document by document, and the properties it blanks
-- a simulation, nothing changes.
- `php admin.php gdpr-erase salaries/ --apply`: done, through the entities (the journal records each change), and
the report written (`{reportFolder}/gdpr-erase-.json`).
What erasing does:
- **her own document** keeps its id and its references, and loses every value classified `personnel` or `sante`
(mmo.core's `#[Classification]`): each property gets its schema's `default`, else null when it may be, `''` for a
string, `[]` for an array or an object. What refers to her still does, and holds no more of her. A property that is a
reference to another entity is kept: what it points to has its own level.
- **a document that refers to her** gets what `erase` says of its collection: `keep` (the default: listed only -- a
record the law keeps, an accident declared to the social security), `anonymize` (the same as her own document), or
`delete` (kept, and said so, when another document still refers to it).
## Limits
- The journal (`LogQuery`) keeps the values it recorded before the erasure: it is the trace of what was done, and is
purged by its own retention. Its entries of the erasure hold the blanked values only.
- A copy elsewhere (a backup, a developer's copy) is not erased: it expires with the backups, and a developer works on
an anonymised copy (mmo.mongodb's `Anonymize.md`).
- A value that names the person in a free text of another document (a witness's statement) is not found: only
references are followed.