Browse Source

Fixes for delete-stray tool and cli.php

config
discomrade 1 month ago
parent
commit
31b97dd61d
  1. 27
      tools/delete-stray-images.php
  2. 2
      tools/inc/cli.php

27
tools/delete-stray-images.php

@ -18,17 +18,22 @@ foreach ($boards as $board) {
openBoard($board['uri']);
$query = query(sprintf("SELECT `file`, `thumb` FROM ``posts_%s`` WHERE `file` IS NOT NULL", $board['uri']));
$query = query(sprintf("SELECT `files` FROM ``posts_%s`` WHERE `files` IS NOT NULL", $board['uri']));
$valid_src = array();
$valid_thumb = array();
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$valid_src[] = $post['file'];
$valid_thumb[] = $post['thumb'];
$files = json_decode($post['files']);
foreach ($files as $i => $f) {
if ($f->file != 'deleted' && $f->file != 'spoiler' && $f->file != 'file'){
$valid_src[] = $f->filename;
$valid_thumb[] = $f->thumb;
}
}
}
$files_src = array_map('basename', glob($board['dir'] . $config['dir']['img'] . '*'));
$files_thumb = array_map('basename', glob($board['dir'] . $config['dir']['thumb'] . '*'));
$files_src = array_map('basename', glob($board['uri'] . "/" . $config['dir']['img'] . '*'));
$files_thumb = array_map('basename', glob($board['uri'] . "/" . $config['dir']['thumb'] . '*'));
$stray_src = array_diff($files_src, $valid_src);
$stray_thumb = array_diff($files_thumb, $valid_thumb);
@ -40,8 +45,8 @@ foreach ($boards as $board) {
foreach ($stray_src as $src) {
$stats['deleted']++;
$stats['size'] = filesize($board['dir'] . $config['dir']['img'] . $src);
if (!file_unlink($board['dir'] . $config['dir']['img'] . $src)) {
$stats['size'] += filesize($board['uri'] . "/" . $config['dir']['img'] . $src);
if (!file_unlink($board['uri'] . "/" . $config['dir']['img'] . $src)) {
$er = error_get_last();
die("error: " . $er['message'] . "\n");
}
@ -49,8 +54,8 @@ foreach ($boards as $board) {
foreach ($stray_thumb as $thumb) {
$stats['deleted']++;
$stats['size'] = filesize($board['dir'] . $config['dir']['thumb'] . $thumb);
if (!file_unlink($board['dir'] . $config['dir']['thumb'] . $thumb)) {
$stats['size'] += filesize($board['uri'] . "/" . $config['dir']['thumb'] . $thumb);
if (!file_unlink($board['uri'] . "/" . $config['dir']['thumb'] . $thumb)) {
$er = error_get_last();
die("error: " . $er['message'] . "\n");
}

2
tools/inc/cli.php

@ -38,7 +38,7 @@ if(!getenv('TINYBOARD_PATH')) {
putenv('TINYBOARD_PATH=' . getcwd());
require 'inc/functions.php';
require 'inc/bootstrap.php';
$mod = Array(
'id' => -1,

Loading…
Cancel
Save