refactor: extract edit.php POST handler to actions/edit.php

edit.php was a 530-line file mixing form display, POST handling, file
uploads, and reference-data loading. This refactor splits it along the
same action-file pattern already used by formulaire.php, tag.php, and
page.php.

Changes:
- public/admin/actions/edit.php (new): standalone POST handler; auth
  guard, CSRF check, transaction, redirect with session flash messages
- public/admin/edit.php: display-only; reads edit_success/edit_error
  flash keys from session; form action points to actions/edit.php via
  a hidden thesis_id field instead of a query-string self-post
- src/Database.php: four new methods to remove all raw PDO from both
  files:
    - updateThesis(int, array): void  — UPDATE theses core fields
    - setThesisAuthors(int, array): void  — delete-then-reinsert authors
    - getThesisLanguageIds(int): array — SELECT language_id for form
    - getThesisFormatIds(int): array   — SELECT format_id for form
This commit is contained in:
Pontoporeia
2026-03-28 18:08:23 +01:00
parent f20aab5f66
commit 4f5ff5a22c
6 changed files with 253 additions and 154 deletions

View File

@@ -423,10 +423,11 @@ Goal: rename the tables and column to the canonical M2M pattern (`tags`, `thesis
### C — Code organisation / maintainability
- [ ] **`edit.php` does too much** — 530 lines combining form display, POST handling, file upload,
and all reference-data loading in one file. Extract the POST handler to
`public/admin/actions/edit.php` (matching the pattern already used by `formulaire.php`,
`tag.php`, `page.php`, etc.).
- [x] **`edit.php` does too much** — POST handler extracted to `public/admin/actions/edit.php`;
`edit.php` is now display-only (loads data, renders form, reads flash messages from session).
Added `Database::updateThesis()`, `Database::setThesisAuthors()`,
`Database::getThesisLanguageIds()`, `Database::getThesisFormatIds()` to remove all raw PDO
from both files. Matches the pattern of `formulaire.php`, `tag.php`, `page.php`.
- [x] **`formulaire.php` duplicates banner-upload logic verbatim from `edit.php`** — extracted to
`Database::handleBannerUpload(int $thesisId, ?array $uploadedFile): ?string`; both action