lainchan/tools/rebuild.php

108 lines
2.5 KiB
PHP
Raw Normal View History

#!/usr/bin/php
<?php
2012-04-11 22:53:45 -04:00
/*
* 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).
*
*/
2012-04-11 22:53:45 -04:00
require dirname(__FILE__) . '/inc/cli.php';
require_once("inc/bans.php");
2012-04-11 22:53:45 -04:00
$start = microtime(true);
// parse command line
$opts = getopt('qfb:', Array('board:', 'quick', 'full', 'quiet'));
$options = Array();
$global_locale = $config['locale'];
2012-04-11 22:53:45 -04:00
$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'])
2014-04-17 11:11:27 -04:00
echo "== Tinyboard + vichan {$config['version']} ==\n";
2012-04-11 22:53:45 -04:00
if(!$options['quiet'])
echo "Clearing template cache...\n";
load_twig();
$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'])
2012-04-11 22:53:45 -04:00
echo "Opening board /{$board['uri']}/...\n";
// Reset locale to global locale
$config['locale'] = $global_locale;
2012-04-11 22:53:45 -04:00
openBoard($board['uri']);
2013-09-14 14:23:18 -04:00
$config['try_smarter'] = false;
2012-04-11 22:53:45 -04:00
if($config['file_script'] != $main_js) {
// different javascript file
if(!$options['quiet'])
echo "Generating Javascript file...\n";
buildJavascript();
}
2012-03-14 00:55:12 -04:00
if(!$options['quiet'])
2012-04-11 22:53:45 -04:00
echo "Creating index pages...\n";
buildIndex();
2012-03-14 00:55:12 -04:00
2012-04-11 22:53:45 -04:00
if($options['quick'])
continue; // do no more
2012-03-14 06:55:22 -04:00
2012-04-11 22:53:45 -04:00
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";
2012-04-11 22:53:45 -04:00
rebuildPost($post['id']);
}
}
2012-03-14 00:55:12 -04:00
$query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
2012-04-11 22:53:45 -04:00
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');