# Deleting data: polls and accounts

Why: the data processing agreement (Art. 28 GDPR) requires that data is deleted when the contract ends, and a customer who deletes a poll expects its participants' data to go. Until 27 Nov 2026 deleting a poll only hid it; everything stayed in the database for good.

## A poll that is deleted

1. **Deleting** (`DELETE /api/poll/{id}`, deleting the owner's account, or cancelling a poll being created: `POST /api/poll/details/{id}` with type 0, since 28 Nov 2026) sets `polls.type = 0` and `polls.deleted_at`. The poll is hidden, its link still opens. The first deletion moment stays: deleting again does not start the 30 days over. Polls deleted before the column existed got their `updated_at` as `deleted_at` (migration `2026_11_27_090000`), as did the polls cancelled between that migration and this fix (`2026_11_28_120000`).
2. **After 30 days** the nightly job `php artisan polls:anonymize-deleted` (03:50, after the database backup at 00:10) anonymises it: `App\Services\PollAnonymizer`, one poll per transaction, `polls.anonymized_at` marks it done. The first run takes every poll that is already overdue. `--dry-run` only counts, `--days=` changes the deadline.

| What | Anonymisation |
|---|---|
| Participants (name, comment, guests), their answers (`preferences`, `preference_answers`), their entries in your own fields (`participant_values`) | rows deleted |
| Invitations (e-mail addresses), comments (name, text) | rows deleted |
| Bring list (`tasks`, `resources`), options (`choices`: text, place), own fields (`participant_attributes`) | rows deleted |
| `poll_user_archive`, `poll_statistics` (holds the admin's e-mail) | rows deleted |
| `mail_logs` of the poll | the plain address is cleared (it is anyway after 30 days), the hash stays until the 90-day prune |
| The poll row | stays, emptied: title `[gelöscht]`, description, organiser name, `key` (admin links stop working), images, `choice_config`, reminder settings cleared, `closed = 1`. `options` is reduced to the flag `initialised` |
| Kept on the poll row | `id`, `user_id`, `type = 0`, `created_at`, `updated_at`, `deleted_at`, `created_ui`, `created_from` (the place the poll was started from), `design_id` |

**Why the poll row stays:** the key figures count it. `Metrics\DailyMetrics` tells "deleted after use" from "cancelled" by `options.initialised`, so that flag is kept; every other figure (participants, big polls, real admins) only looks at polls of type 1 to 4 and never sees a deleted one. A test (`AnonymizeDeletedPollsTest`) checks that the figures of a day do not change.

**Not undoable.** Setting `type` back or clearing `deleted_at` rescues a poll only before the job has run; after `anonymized_at` is set the content is gone (a database backup is the only way). A poll restored by hand before that must get `deleted_at = NULL`.

## What this does not cover (say so in the privacy statement / the agreement)

- **Database backups** (`backup:database`, rotated by `backup:cleanup`): they still hold the data until they rotate out.
- **Log files** (`storage/logs`) can contain names and addresses of requests; they are rotated.
- **Address book** (`contacts`) belongs to the user, not to the poll; it goes with the account.
- **Uploaded images** belong to the user's library and go with the account. An anonymised poll only loses the reference.
- **The link of a deleted poll** still loads (`getPoll` does not look at `type`). After the job it shows an empty poll titled `[gelöscht]`.

## An account that is deleted

`POST /api/user/delete` (an admin deletes any account, everyone their own): see `UserController::destroy`. At that moment:

- the user's own data is **deleted**: contacts, designs, tasks, answers and participations, comments, invitations, images and logos (files too), the billing profile (issued invoices keep their own copy of the recipient: statutory retention);
- the user row **stays**, emptied: `email` becomes `removed_<id>` (the backend tab and the login recognise a deleted account by it), **`name` becomes `[gelöscht]`** (`User::DELETED_NAME`) and **the password hash is replaced by the hash of a random string** nobody knows, so no login is possible. Both columns are `NOT NULL`, hence a placeholder and a random hash and not NULL. `roles` and `active` become 0;
- the account's polls are marked deleted (`polls.deleted_at`) and follow the 30-day path above. Polls that were deleted earlier keep their own moment.

Still on the user row: `customer_id` (the payment provider's customer number), `locale`, `login_count`, `last_login_at`, `origin`, `created_at`. None of them names the person; `customer_id` links to the payment provider, whose own retention applies. Mention it in the privacy statement.
