Add clean_bpp.php page
This commit is contained in:
174
clean_bdd.php
Normal file
174
clean_bdd.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title><?php gettext('Clean photos in Sqlite base'); ?></title>
|
||||
|
||||
<link rel="stylesheet" href="css/sls.css" />
|
||||
<link rel='stylesheet' href='css/lc_lightbox.min.css' />
|
||||
<link rel='stylesheet' href='css/open_close_fx.css' />
|
||||
<link rel='stylesheet' href='css/minimal.css' />
|
||||
|
||||
<?php include 'functions.php';
|
||||
session_start();
|
||||
if($_SESSION['Active'] == false){ /* Redirects user to login.php if not logged in */
|
||||
header("location:admin/login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$domain = 'sentier';
|
||||
localize($domain);
|
||||
?>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
|
||||
$base = 'db_photo.sqlite3';
|
||||
|
||||
// Taille des vignettes
|
||||
$th_w = 300;
|
||||
$th_h = 300;
|
||||
// Chemins
|
||||
$img_path = "photos/img/";
|
||||
$thumb_path = "photos/thumb/";
|
||||
|
||||
//$dir = (new AdvancedFilesystemIterator('photos/img/'))->match('/heic|HEIC|jpg|jpeg|JPG|JPEG|webp|WEBP$/');
|
||||
|
||||
//echo '<h3>' . count($dir) . gettext(' images found in folder') . ' <i>photos/img/</i> ...</h3>';
|
||||
|
||||
//_pr($dir);
|
||||
|
||||
|
||||
/*
|
||||
foreach($dir as $file){
|
||||
|
||||
//$file->getFilename()
|
||||
//$file->getpathName()
|
||||
|
||||
$file = $file->getpathName();
|
||||
|
||||
$x = in_bdd($file);
|
||||
|
||||
if ($x == false) { //false
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$originals = array_map('basename', glob('photos/img/*.{jpg,jpeg,JPG,JPEG,heic,HEIC,webp,WEBP}', GLOB_BRACE));
|
||||
$thumbs = array_map('basename', glob('photos/thumb/*.{jpg,jpeg,JPG,JPEG,heic,HEIC,webp,WEBP}', GLOB_BRACE));
|
||||
|
||||
$missing_thumbs = array_diff($originals, $thumbs);
|
||||
$a = count($missing_thumbs);
|
||||
echo '<h3>' . gettext('Missing thumbs: ') . $a . '</h3>';
|
||||
if ($a > 0) {
|
||||
echo '<h4>' . gettext('Create missing thumbs...') . '</h4>';
|
||||
|
||||
foreach($missing_thumbs as $img){
|
||||
$file = $img_path . $img;
|
||||
create_thumb($th_w, $th_h, $file);
|
||||
echo gettext('Thumb for ') . $img . gettext(' was successfully created!') . '<br>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$missing_originals = array_diff($thumbs, $originals);
|
||||
$b = count($missing_originals);
|
||||
echo '<h3>' . gettext('Extra thumbs: ') . $b . '</h3>';
|
||||
if ($b > 0) {
|
||||
echo '<h4>' . gettext('Delete extra thumbs...') . '</h4>';
|
||||
|
||||
foreach($missing_originals as $thumb){
|
||||
$file = $thumb_path . $thumb;
|
||||
if (unlink($file)) {
|
||||
echo $thumb . gettext(' was deleted successfully!') . '<br>';
|
||||
} else {
|
||||
echo gettext('There was a error deleting the file ') . $thumb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_pr($missing_thumbs);
|
||||
_pr($missing_originals);
|
||||
|
||||
echo '<h3>' . gettext('Compare folder img and daatabase...') . '</h3>';
|
||||
|
||||
try {
|
||||
$conn = new PDO("sqlite:db_photo.sqlite3");
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$query = "SELECT filename FROM photos";
|
||||
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->execute();// (1,3...) 1=1ere valeur 3=valeur
|
||||
|
||||
$result = $stmt->fetchAll(PDO::FETCH_CLASS);
|
||||
$rowcount = count($result);
|
||||
|
||||
//$conn = null;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
//_pr($result);
|
||||
$bdd = array();
|
||||
|
||||
foreach($result as $file) {
|
||||
//$img = $file->filename;
|
||||
$bdd[] = $file->filename;
|
||||
}
|
||||
|
||||
$base = array_map('basename', $bdd);
|
||||
$missing_originals = array_diff($base, $originals);
|
||||
$c = count($missing_originals);
|
||||
echo '<h3>' . gettext('Extra images in database: ') . $c . '</h3>';
|
||||
if ($c > 0) {
|
||||
echo '<h4>' . gettext('Delete extra images in database...') . '</h4>';
|
||||
|
||||
//foreach($missing_originals as $img){
|
||||
foreach($missing_originals as $key => $img){
|
||||
echo $key;
|
||||
$query2 = "DELETE FROM photos WHERE id=:id";
|
||||
|
||||
$stmt=$conn->prepare($query2);
|
||||
$stmt->bindParam(':id',$key,PDO::PARAM_INT, 5);
|
||||
|
||||
if($stmt->execute()){
|
||||
echo "Successfully deleted record ";
|
||||
} else {
|
||||
print_r($sql->errorInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_pr($bdd);
|
||||
|
||||
//_pr($base);
|
||||
|
||||
_pr($missing_originals);
|
||||
|
||||
/*
|
||||
foreach($fileList as $filename){
|
||||
echo $filename;
|
||||
}
|
||||
*/
|
||||
//_pr($fileList);
|
||||
?>
|
||||
|
||||
|
||||
<p><em><small>© 2013-<?php echo date('Y'); ?> sur-le-sentier.fr</small></em></p>
|
||||
|
||||
<script src='js/lc_lightbox.min.js' type='text/javascript'></script>
|
||||
<script src='js/alloy_finger.min.js' type='text/javascript'></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user