From a2f91abda4e9dd284480a713953b098a2e13b6a2 Mon Sep 17 00:00:00 2001 From: leosw Date: Sun, 12 Apr 2026 15:13:26 +0200 Subject: [PATCH] Gestion des photos orphelines --- public/views/d.admin.html | 1 + public/views/d.admin.orphans.html | 60 +++++++++++++++++++++++++++++++ src/Controllers/d.admin.php | 44 +++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 public/views/d.admin.orphans.html diff --git a/public/views/d.admin.html b/public/views/d.admin.html index 52e2141..43455c9 100755 --- a/public/views/d.admin.html +++ b/public/views/d.admin.html @@ -16,6 +16,7 @@ Mettre à jour Met à jour le logiciel depuis le dépôt GIT.

Sauvegarde SQL Archive des médiasGénère un dump SQL et une archive de fichiers téléchargeable.

+ Photos orphelines Traiter les photos devenues orphelines.

rankIsHigher("moderator")) { ?> diff --git a/public/views/d.admin.orphans.html b/public/views/d.admin.orphans.html new file mode 100644 index 0000000..a070c6f --- /dev/null +++ b/public/views/d.admin.orphans.html @@ -0,0 +1,60 @@ + + + + + + + + + + + + +
+

+
+ +

Fichiers orphelins (présents sur disque mais pas en base)

+ +

Aucun fichier orphelin

+ + + + +

Entrées SQL orphelines (en base mais fichier manquant)

+ +

Aucune entrée SQL orpheline

+ + + + +
+ + + + + diff --git a/src/Controllers/d.admin.php b/src/Controllers/d.admin.php index a2aa077..cd57bf2 100755 --- a/src/Controllers/d.admin.php +++ b/src/Controllers/d.admin.php @@ -1,5 +1,7 @@ splitted_url[1]) && $user->rankIsHigher("moderator")) { $notfound = 1; } break; + case 'orphan-photos': + if ($user->rankIsHigher("administrator")) { + $head['title'] = "Suppressions des photos orphelines"; + + $folder = $config['medias_folder'] . 'comment_photos/'; + $con = Kabano\sql_connect(); + + // Suppression fichier orphelin + if (isset($_GET['delete_file'])) { + $file = basename($_GET['delete_file']); + $path = $folder . $file; + + if (file_exists($path)) { + unlink($path); + } + } + // Suppression entrée SQL orpheline + if (isset($_GET['delete_db'])) { + $file = $_GET['delete_db']; + + pg_prepare($con, "delete_orphan", "DELETE FROM content_comment_photos WHERE url = $1"); + pg_execute($con, "delete_orphan", [$file]); + } + + $files = array_diff(scandir($folder), ['.', '..']); + + $sql = "SELECT id, url FROM content_comment_photos"; + $result = pg_query($con, $sql); + $dbEntries = pg_fetch_all($result) ?: []; + $dbFiles = array_column($dbEntries, 'url'); + + $orphans_files = array_diff($files, $dbFiles); + $orphans_db = array_diff($dbFiles, $files); + + pg_close($con); + + include ($config['views_folder']."d.admin.orphans.html"); + } + else { + $notfound = 1; + } + break; default: $notfound = 1; break;