mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
cleanup modal: list stale files to remove; storage restructure: documents/ → {objet}/
This commit is contained in:
@@ -50,8 +50,8 @@ class MediaController
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. Visibility gate for thesis files (both legacy theses/ and new documents/ paths)
|
||||
if (preg_match('#^(theses|documents)/#', $requestedPath)) {
|
||||
// 3. Visibility gate for thesis files (legacy theses/ and documents/, new tfe/these/frart/ paths)
|
||||
if (preg_match('#^(theses|documents|tfe|these|frart)/#', $requestedPath)) {
|
||||
require_once APP_ROOT . '/src/Database.php';
|
||||
require_once APP_ROOT . '/src/ErrorHandler.php';
|
||||
try {
|
||||
|
||||
@@ -188,10 +188,11 @@ class ThesisCreateController
|
||||
}
|
||||
|
||||
// ── 5. File uploads (outside transaction — filesystem ops) ────────────
|
||||
$tf = $this->buildThesisFolder($data['annee'], $allAuthorsStr, $data['titre']);
|
||||
$objet = $data['objet'] ?? 'tfe';
|
||||
$tf = $this->buildThesisFolder($data['annee'], $allAuthorsStr, $data['titre'], $objet);
|
||||
$folderName = $this->ensureUniqueFolder($tf['folderPath']);
|
||||
// Rebuild path with potentially modified folder name
|
||||
$folderPath = 'documents/' . $data['annee'] . '/' . $folderName . '/';
|
||||
$folderPath = $objet . '/' . $data['annee'] . '/' . $folderName . '/';
|
||||
$filePrefix = $folderName;
|
||||
|
||||
if (!empty($post['filepond_mode'])) {
|
||||
|
||||
@@ -313,8 +313,10 @@ class ThesisEditController
|
||||
$year = intval($post['année'] ?? date('Y'));
|
||||
$title = trim($post['titre'] ?? '');
|
||||
$authors = trim($post['auteurice'] ?? '');
|
||||
$thesis = $this->db->getThesis($thesisId);
|
||||
$objet = $thesis['objet'] ?? 'tfe';
|
||||
|
||||
$tf = $this->buildThesisFolder($year, $authors, $title);
|
||||
$tf = $this->buildThesisFolder($year, $authors, $title, $objet);
|
||||
$folderPath = $tf['folderPath'];
|
||||
$filePrefix = $tf['filePrefix'];
|
||||
|
||||
@@ -322,11 +324,12 @@ class ThesisEditController
|
||||
$existingFiles = $this->db->getThesisFiles($thesisId);
|
||||
foreach ($existingFiles as $f) {
|
||||
$fp = $f['file_path'] ?? '';
|
||||
if (str_starts_with($fp, 'documents/') || str_starts_with($fp, 'theses/')) {
|
||||
if (preg_match('#^(theses|documents|tfe|these|frart)/#', $fp)) {
|
||||
$parts = explode('/', $fp);
|
||||
if (count($parts) >= 3) {
|
||||
$parentDir = $parts[0];
|
||||
$folderName = $parts[2];
|
||||
$folderPath = 'documents/' . $year . '/' . $folderName . '/';
|
||||
$folderPath = $parentDir . '/' . $year . '/' . $folderName . '/';
|
||||
$filePrefix = $folderName;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Shared file-upload logic used by ThesisCreateController and
|
||||
* ThesisEditController. All on-disk files are stored under:
|
||||
*
|
||||
* documents/{YYYY}/{YYYY}_{AUTHORS}_{TITLE_SLUG}/
|
||||
* {objet}/{YYYY}/{YYYY}_{AUTHORS}_{TITLE_SLUG}/
|
||||
*
|
||||
* Filenames follow:
|
||||
*
|
||||
@@ -88,7 +88,7 @@ trait ThesisFileHandler
|
||||
*
|
||||
* @param int $thesisId
|
||||
* @param array|null $upload Single-file $_FILES entry.
|
||||
* @param string $folderPath Relative path from STORAGE_ROOT to the thesis folder (e.g. "documents/2025/2025_SMITH_Mon_Titre/").
|
||||
* @param string $folderPath Relative path from STORAGE_ROOT to the thesis folder (e.g. "tfe/2025/2025_SMITH_Mon_Titre/").
|
||||
* @param string $filePrefix The prefix shared by all files in this folder (e.g. "2025_SMITH_Mon_Titre").
|
||||
*/
|
||||
protected function handleCoverUpload(int $thesisId, ?array $upload, string $folderPath, string $filePrefix): void
|
||||
@@ -802,19 +802,19 @@ trait ThesisFileHandler
|
||||
/**
|
||||
* Build the folder path and file prefix for a thesis.
|
||||
*
|
||||
* Folder: documents/{YYYY}/{YYYY}_{AUTHORS}_{TITLE_SLUG}/
|
||||
* Folder: {objet}/{YYYY}/{YYYY}_{AUTHORS}_{TITLE_SLUG}/
|
||||
* Prefix: {YYYY}_{AUTHORS}_{TITLE_SLUG}
|
||||
*
|
||||
* @return array{folderPath: string, filePrefix: string, folderName: string}
|
||||
*/
|
||||
protected function buildThesisFolder(int $year, string $authorsStr, string $title): array
|
||||
protected function buildThesisFolder(int $year, string $authorsStr, string $title, string $objet = 'tfe'): array
|
||||
{
|
||||
$authorSlug = $this->generateAuthorSlug($authorsStr);
|
||||
$titleSlug = $this->generateTitleSlug($title);
|
||||
|
||||
$folderName = $year . '_' . $authorSlug . '_' . $titleSlug;
|
||||
$filePrefix = $folderName;
|
||||
$folderPath = 'documents/' . $year . '/' . $folderName . '/';
|
||||
$folderPath = $objet . '/' . $year . '/' . $folderName . '/';
|
||||
|
||||
return [
|
||||
'folderPath' => $folderPath,
|
||||
|
||||
@@ -2335,9 +2335,15 @@ class Database
|
||||
|
||||
// Clean up thesis files from disk
|
||||
$files = $this->getThesisFiles($thesisId);
|
||||
$storageRoot = defined('STORAGE_ROOT') ? STORAGE_ROOT : '/var/www/xamxam/storage';
|
||||
foreach ($files as $file) {
|
||||
if (!empty($file['file_path']) && file_exists($file['file_path'])) {
|
||||
@unlink($file['file_path']);
|
||||
$fp = $file['file_path'] ?? '';
|
||||
if ($fp === '' || str_starts_with($fp, 'http://') || str_starts_with($fp, 'https://') || str_starts_with($fp, 'peertube_ids:')) {
|
||||
continue;
|
||||
}
|
||||
$abs = $storageRoot . '/' . $fp;
|
||||
if (file_exists($abs)) {
|
||||
@unlink($abs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user