diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
| commit | fef9a3ca82144348924852f68aee35ff4bf6ca25 (patch) | |
| tree | 2eb7dd277177fcbd572884d15ed3ce100aa61c7c /tools/rebuild.php | |
| parent | 52443d3da98e992953d8214b7848350f70d02336 (diff) | |
| parent | 2df1ebd88c266d984cbaa6c26917c2ea89c2ae0e (diff) | |
Merge branch 'master' of github.com:savetheinternet/Tinyboard-Tools into tools
Conflicts:
README.md
Diffstat (limited to 'tools/rebuild.php')
| -rwxr-xr-x | tools/rebuild.php | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/tools/rebuild.php b/tools/rebuild.php new file mode 100755 index 00000000..1560893c --- /dev/null +++ b/tools/rebuild.php @@ -0,0 +1,105 @@ +#!/usr/bin/php +<?php +/* + * rebuild.php - rebuilds all static files + * + * Command line arguments: + * -q, --quiet + * Suppress output. + * + * --quick + * Do not rebuild posts. + * + * -b, --board <string> + * Rebuild only the specified board. + * + * -f, --full + * Rebuild replies as well as threads (re-markup). + * + */ + + require dirname(__FILE__) . '/inc/cli.php'; + + if(!is_writable($config['file_script'])) { + get_httpd_privileges(); + } + + $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(); + + if(!$options['quiet']) + echo "Regenerating theme files...\n"; + rebuildThemes('all'); + + if(!$options['quiet']) + echo "Generating Javascript file...\n"; + buildJavascript(); + + $main_js = $config['file_script']; + + $boards = listBoards(); + + foreach($boards as &$board) { + if($options['board'] && $board['uri'] != $options['board']) + continue; + + if(!$options['quiet']) + echo "Opening board /{$board['uri']}/...\n"; + openBoard($board['uri']); + + if($config['file_script'] != $main_js) { + // different javascript file + 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()) { + if(!$options['quiet']) + echo "Rebuilding #{$post['id']}...\n"; + buildThread($post['id']); + } + } + + if(!$options['quiet']) + printf("Complete! Took %g seconds\n", microtime(true) - $start); + + unset($board); + modLog('Rebuilt everything using tools/rebuild.php'); + |
