mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
feat: fix file deletion on save + trash policy + documents/ prefix + relink browser
1. note_intention: Delete old file only when a genuinely new upload arrives
(32-char hex file_id), not when the FilePond pool preserves an existing
file by sending its DB integer ID. Previously the DB integer ID
triggered $hasNewNote=true, which deleted the existing note_intention
from disk+DB, then handleFilePondSingleFile couldn't re-process it
because the regex requires a hex pattern. Same fix applied to cover.
2. All file deletions now use deleteThesisFileToTrash() which renames
files to tmp/_trash/ instead of unlinking. The trash preserves
original filenames prefixed with DB id for traceability. Skips
website URLs and PeerTube refs (no disk file).
3. Storage prefix changed from theses/ to documents/ to reflect that
the folder holds all document types (determined by file_type in DB).
MediaController visibility gate supports both prefixes for backward
compat with existing files.
4. File browser + relink feature for orphaned files:
- /admin/fragments/file-browser.php — HTMX tree browser for
storage/documents/ and storage/theses/
- /admin/actions/filepond/relink.php — POST endpoint that inserts
a thesis_files row pointing to existing on-disk file
- Per-pool "📂 Relier" buttons (edit mode only)
- JS: XamxamOpenFileBrowser / XamxamRelinkFile with FilePond integration
- CSS: .relink-modal dialog + .file-browser tree styles
This commit is contained in:
@@ -38,7 +38,15 @@ switch ($action) {
|
||||
$validObjet = ['tfe', 'thèse', 'frart'];
|
||||
$selected = is_array($objetRaw) ? array_intersect($objetRaw, $validObjet) : [];
|
||||
$objetRestriction = !empty($selected) ? implode(',', $selected) : 'tfe';
|
||||
$link = $shareLink->create(1, $expiresAt, $objetRestriction, $name);
|
||||
$lockedYearRaw = $_POST['locked_year'] ?? null;
|
||||
$lockedYear = null;
|
||||
if ($lockedYearRaw !== null && $lockedYearRaw !== '') {
|
||||
$lockedYear = filter_var($lockedYearRaw, FILTER_VALIDATE_INT);
|
||||
if ($lockedYear === false || $lockedYear < 2000 || $lockedYear > ((int)date('Y') + 3)) {
|
||||
$lockedYear = null;
|
||||
}
|
||||
}
|
||||
$link = $shareLink->create(1, $expiresAt, $objetRestriction, $name, $lockedYear);
|
||||
$logger->logLinkCreate(
|
||||
$link['slug'] ?? '',
|
||||
true, // Always has password
|
||||
@@ -86,7 +94,13 @@ switch ($action) {
|
||||
if ($id > 0) {
|
||||
$name = isset($_POST['name']) ? trim($_POST['name']) : null;
|
||||
$expiresRaw = isset($_POST['expires_at']) ? trim($_POST['expires_at']) : null;
|
||||
$shareLink->update($id, $name, $expiresRaw);
|
||||
// locked_year: null=not sent (keep), ""=clear, otherwise year string
|
||||
$lockedYearRaw = $_POST['locked_year'] ?? null;
|
||||
$lockedYear = null; // default: not sent → don't change
|
||||
if ($lockedYearRaw !== null) {
|
||||
$lockedYear = $lockedYearRaw; // pass through: "" for clear, "2026" for set
|
||||
}
|
||||
$shareLink->update($id, $name, $expiresRaw, $lockedYear);
|
||||
App::redirect('/admin/acces.php', success: 'Lien mis à jour.');
|
||||
} else {
|
||||
App::redirect('/admin/acces.php', error: 'Lien introuvable.');
|
||||
|
||||
Reference in New Issue
Block a user