From 6b42c71c791aa1646cc481cdd6d3f033dd592844 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 15 Mar 2012 22:37:43 +1100 Subject: [PATCH] rebuild.php command line switches (--quiet, --board, etc.) --- tools/rebuild.php | 80 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/tools/rebuild.php b/tools/rebuild.php index 29331ce4..0e63dc74 100755 --- a/tools/rebuild.php +++ b/tools/rebuild.php @@ -1,25 +1,56 @@ #!/usr/bin/php + * Rebuild only the specified board. + * + * -f, --full + * Rebuild replies as well as threads (re-markup). + * + */ + require dirname(__FILE__) . '/inc/cli.php'; - $start = microtime(true); - - echo "== Tinyboard {$config['version']} ==\n"; - if(!is_writable($config['file_script'])) { get_httpd_privileges(); } - echo "Clearing template cache...\n"; + $start = microtime(true); + + // parse command line + $opts = getopt('qfb:', Array('board:', 'quick', 'full', 'quiet')); + $options = Array(); + + $options['board'] = isset($opts['board']) ? $opts['board'] : (isset($opts['b']) ? $opts['b'] : false); + $options['quiet'] = isset($opts['q']) || isset($opts['quiet']); + $options['quick'] = isset($opts['quick']); + $options['full'] = isset($opts['full']) || isset($opts['f']); + + if(!$options['quiet']) + echo "== Tinyboard {$config['version']} ==\n"; + + if(!$options['quiet']) + echo "Clearing template cache...\n"; $twig = new Twig_Environment($loader, Array( 'cache' => "{$config['dir']['template']}/cache" )); $twig->clearCacheFiles(); - echo "Regenerating theme files...\n"; + if(!$options['quiet']) + echo "Regenerating theme files...\n"; rebuildThemes('all'); - echo "Generating Javascript file...\n"; + if(!$options['quiet']) + echo "Generating Javascript file...\n"; buildJavascript(); $main_js = $config['file_script']; @@ -27,26 +58,47 @@ $boards = listBoards(); foreach($boards as &$board) { - echo "Opening board /{$board['uri']}/...\n"; - openBoard($board['uri']); + if($options['board'] && $board['uri'] != $options['board']) + continue; - echo "Creating index pages...\n"; - buildIndex(); + if(!$options['quiet']) + echo "Opening board /{$board['uri']}/...\n"; + openBoard($board['uri']); if($config['file_script'] != $main_js) { // different javascript file - echo "Generating Javascript file...\n"; + if(!$options['quiet']) + echo "Generating Javascript file...\n"; buildJavascript(); } + + if(!$options['quiet']) + echo "Creating index pages...\n"; + buildIndex(); + + if($options['quick']) + continue; // do no more + + if($options['full']) { + $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"; + rebuildPost($post['id']); + } + } + $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); while($post = $query->fetch()) { - echo "Rebuilding #{$post['id']}...\n"; + if(!$options['quiet']) + echo "Rebuilding #{$post['id']}...\n"; buildThread($post['id']); } } - printf("Complete! Took %g seconds\n", microtime(true) - $start); + if(!$options['quiet']) + printf("Complete! Took %g seconds\n", microtime(true) - $start); modLog('Rebuilt everything using tools/rebuild.php');