Gestion des photos orphelines
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
<!-- Administrator tools -->
|
<!-- Administrator tools -->
|
||||||
<a href="<?=$config['rel_root_folder']?>admin/git-pull" class="button"><i class="fas fa-sync-alt"></i> Mettre à jour</a> <small>Met à jour le logiciel depuis le dépôt GIT.</small><br><br>
|
<a href="<?=$config['rel_root_folder']?>admin/git-pull" class="button"><i class="fas fa-sync-alt"></i> Mettre à jour</a> <small>Met à jour le logiciel depuis le dépôt GIT.</small><br><br>
|
||||||
<a href="<?=$config['rel_root_folder']?>admin/sql-backup" class="button"><i class="fas fa-file-export"></i> Sauvegarde SQL</a><a href="<?=$config['rel_root_folder']?>admin/files-backup" class="button"><i class="fas fa-file-export"></i> Archive des médias</a><small>Génère un dump SQL et une archive de fichiers téléchargeable.</small><br><br>
|
<a href="<?=$config['rel_root_folder']?>admin/sql-backup" class="button"><i class="fas fa-file-export"></i> Sauvegarde SQL</a><a href="<?=$config['rel_root_folder']?>admin/files-backup" class="button"><i class="fas fa-file-export"></i> Archive des médias</a><small>Génère un dump SQL et une archive de fichiers téléchargeable.</small><br><br>
|
||||||
|
<a href="<?=$config['rel_root_folder']?>admin/orphan-photos" class="button"><i class="fas fa-unlink"></i> Photos orphelines</a> <small>Traiter les photos devenues orphelines.</small><br><br>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php if($user->rankIsHigher("moderator")) { ?>
|
<?php if($user->rankIsHigher("moderator")) { ?>
|
||||||
<!-- Moderator tools -->
|
<!-- Moderator tools -->
|
||||||
|
|||||||
60
public/views/d.admin.orphans.html
Normal file
60
public/views/d.admin.orphans.html
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<!-- Page: admin git pull -->
|
||||||
|
<html lang="fr">
|
||||||
|
|
||||||
|
<?php include('blocks/d.head.html'); ?>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<?php include('blocks/d.nav.html'); ?>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section ul {
|
||||||
|
margin: 20px 0;
|
||||||
|
padding-left: 22px; /* comme le style natif */
|
||||||
|
}
|
||||||
|
|
||||||
|
section li {
|
||||||
|
margin: 6px 0;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h1><?=$head['title']?></h1>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h2>Fichiers orphelins (présents sur disque mais pas en base)</h2>
|
||||||
|
<?php if (empty($orphans_files)): ?>
|
||||||
|
<p>Aucun fichier orphelin</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($orphans_files as $file): ?>
|
||||||
|
<li>
|
||||||
|
<a href="<?=$config['rel_root_folder'].'medias/comment_photos/'.$file?>" target="_blank"><?= htmlspecialchars($file) ?></a>
|
||||||
|
<a href="?delete_file=<?= urlencode($file) ?>" onclick="return confirm('Supprimer ce fichier ?')"><i class="fas fa-trash"></i>Supprimer</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<h2>Entrées SQL orphelines (en base mais fichier manquant)</h2>
|
||||||
|
<?php if (empty($orphans_db)): ?>
|
||||||
|
<p>Aucune entrée SQL orpheline</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($orphans_db as $file): ?>
|
||||||
|
<li>
|
||||||
|
<?= htmlspecialchars($file) ?>
|
||||||
|
<a href="?delete_db=<?= urlencode($file) ?>" onclick="return confirm('Supprimer cette entrée SQL ?')"><i class="fas fa-trash-alt"></i>Supprimer</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<?php include('blocks/d.footer.html'); ?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once($config['includes_folder']."database.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contrôleur des pages d'administration (logs, sauvegardes, stats).
|
* Contrôleur des pages d'administration (logs, sauvegardes, stats).
|
||||||
*/
|
*/
|
||||||
@@ -284,6 +286,48 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
|
|||||||
$notfound = 1;
|
$notfound = 1;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
$notfound = 1;
|
$notfound = 1;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user