diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x[-rw-r--r--] | tools/benchmark.php | 9 | ||||
| -rwxr-xr-x | tools/delete-stray-images.php | 60 | ||||
| -rw-r--r-- | tools/inc/cli.php | 2 | ||||
| -rwxr-xr-x | tools/rebuild.php | 5 |
4 files changed, 71 insertions, 5 deletions
diff --git a/tools/benchmark.php b/tools/benchmark.php index 8c97364c..ed7c200d 100644..100755 --- a/tools/benchmark.php +++ b/tools/benchmark.php @@ -47,6 +47,11 @@ function benchmark($method) { } benchmark('gd'); -benchmark('imagick'); +if (extension_loaded('imagick')) { + benchmark('imagick'); +} else { + echo "Imagick extension not loaded... skipping.\n"; +} benchmark('convert'); - +benchmark('gm'); +becnhmark('convert+gifsicle'); diff --git a/tools/delete-stray-images.php b/tools/delete-stray-images.php new file mode 100755 index 00000000..cf94dfe5 --- /dev/null +++ b/tools/delete-stray-images.php @@ -0,0 +1,60 @@ +#!/usr/bin/php +<?php +/* + * delete-stray-images.php - there was a period when undoImage() was not working at all. This meant that + * if an error occured while uploading an image, the uploaded images might not have been deleted. + * + * This script iterates through every board and deletes any stray files in src/ or thumb/ that don't + * exist in the database. + * + */ + +require dirname(__FILE__) . '/inc/cli.php'; + +$boards = listBoards(); + +foreach ($boards as $board) { + echo "/{$board['uri']}/... "; + + openBoard($board['uri']); + + $query = query(sprintf("SELECT `file`, `thumb` FROM ``posts_%s`` WHERE `file` 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_src = array_map('basename', glob($board['dir'] . $config['dir']['img'] . '*')); + $files_thumb = array_map('basename', glob($board['dir'] . $config['dir']['thumb'] . '*')); + + $stray_src = array_diff($files_src, $valid_src); + $stray_thumb = array_diff($files_thumb, $valid_thumb); + + $stats = array( + 'deleted' => 0, + 'size' => 0 + ); + + 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)) { + $er = error_get_last(); + die("error: " . $er['message'] . "\n"); + } + } + + 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)) { + $er = error_get_last(); + die("error: " . $er['message'] . "\n"); + } + } + + echo sprintf("deleted %s files (%s)\n", $stats['deleted'], format_bytes($stats['size'])); +} diff --git a/tools/inc/cli.php b/tools/inc/cli.php index 294609cd..ac430cca 100644 --- a/tools/inc/cli.php +++ b/tools/inc/cli.php @@ -33,7 +33,7 @@ if(!getenv('TINYBOARD_PATH')) { putenv('TINYBOARD_PATH=' . getcwd()); require 'inc/functions.php'; -require 'inc/mod.php'; +require 'inc/mod/auth.php'; $mod = Array( 'id' => -1, diff --git a/tools/rebuild.php b/tools/rebuild.php index 3b5c0de2..7d6a5abc 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -64,6 +64,7 @@ foreach($boards as &$board) { if(!$options['quiet']) echo "Opening board /{$board['uri']}/...\n"; openBoard($board['uri']); + $config['try_smarter'] = false; if($config['file_script'] != $main_js) { // different javascript file @@ -81,7 +82,7 @@ foreach($boards as &$board) { continue; // do no more if($options['full']) { - $query = query(sprintf("SELECT `id` FROM `posts_%s`", $board['uri'])) or error(db_error()); + $query = query(sprintf("SELECT `id` FROM ``posts_%s``", $board['uri'])) or error(db_error()); while($post = $query->fetch()) { if(!$options['quiet']) echo "Rebuilding #{$post['id']}...\n"; @@ -89,7 +90,7 @@ foreach($boards as &$board) { } } - $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); + $query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); while($post = $query->fetch()) { if(!$options['quiet']) echo "Rebuilding #{$post['id']}...\n"; |
