rebuild.php command line switches (--quiet, --board, etc.)
This commit is contained in:
parent
224c776307
commit
6b42c71c79
@ -1,24 +1,55 @@
|
|||||||
#!/usr/bin/php
|
#!/usr/bin/php
|
||||||
<?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';
|
require dirname(__FILE__) . '/inc/cli.php';
|
||||||
|
|
||||||
$start = microtime(true);
|
|
||||||
|
|
||||||
echo "== Tinyboard {$config['version']} ==\n";
|
|
||||||
|
|
||||||
if(!is_writable($config['file_script'])) {
|
if(!is_writable($config['file_script'])) {
|
||||||
get_httpd_privileges();
|
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";
|
echo "Clearing template cache...\n";
|
||||||
$twig = new Twig_Environment($loader, Array(
|
$twig = new Twig_Environment($loader, Array(
|
||||||
'cache' => "{$config['dir']['template']}/cache"
|
'cache' => "{$config['dir']['template']}/cache"
|
||||||
));
|
));
|
||||||
$twig->clearCacheFiles();
|
$twig->clearCacheFiles();
|
||||||
|
|
||||||
|
if(!$options['quiet'])
|
||||||
echo "Regenerating theme files...\n";
|
echo "Regenerating theme files...\n";
|
||||||
rebuildThemes('all');
|
rebuildThemes('all');
|
||||||
|
|
||||||
|
if(!$options['quiet'])
|
||||||
echo "Generating Javascript file...\n";
|
echo "Generating Javascript file...\n";
|
||||||
buildJavascript();
|
buildJavascript();
|
||||||
|
|
||||||
@ -27,25 +58,46 @@
|
|||||||
$boards = listBoards();
|
$boards = listBoards();
|
||||||
|
|
||||||
foreach($boards as &$board) {
|
foreach($boards as &$board) {
|
||||||
|
if($options['board'] && $board['uri'] != $options['board'])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!$options['quiet'])
|
||||||
echo "Opening board /{$board['uri']}/...\n";
|
echo "Opening board /{$board['uri']}/...\n";
|
||||||
openBoard($board['uri']);
|
openBoard($board['uri']);
|
||||||
|
|
||||||
echo "Creating index pages...\n";
|
|
||||||
buildIndex();
|
|
||||||
|
|
||||||
if($config['file_script'] != $main_js) {
|
if($config['file_script'] != $main_js) {
|
||||||
// different javascript file
|
// different javascript file
|
||||||
|
if(!$options['quiet'])
|
||||||
echo "Generating Javascript file...\n";
|
echo "Generating Javascript file...\n";
|
||||||
buildJavascript();
|
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());
|
$query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
|
||||||
while($post = $query->fetch()) {
|
while($post = $query->fetch()) {
|
||||||
|
if(!$options['quiet'])
|
||||||
echo "Rebuilding #{$post['id']}...\n";
|
echo "Rebuilding #{$post['id']}...\n";
|
||||||
buildThread($post['id']);
|
buildThread($post['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$options['quiet'])
|
||||||
printf("Complete! Took %g seconds\n", microtime(true) - $start);
|
printf("Complete! Took %g seconds\n", microtime(true) - $start);
|
||||||
|
|
||||||
modLog('Rebuilt everything using tools/rebuild.php');
|
modLog('Rebuilt everything using tools/rebuild.php');
|
||||||
|
Loading…
Reference in New Issue
Block a user