The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 line
2.5KB

  1. #!/usr/bin/php
  2. <?php
  3. /*
  4. * rebuild.php - rebuilds all static files
  5. *
  6. * Command line arguments:
  7. * -q, --quiet
  8. * Suppress output.
  9. *
  10. * --quick
  11. * Do not rebuild posts.
  12. *
  13. * -b, --board <string>
  14. * Rebuild only the specified board.
  15. *
  16. * -f, --full
  17. * Rebuild replies as well as threads (re-markup).
  18. *
  19. */
  20. require dirname(__FILE__) . '/inc/cli.php';
  21. require_once("inc/bans.php");
  22. $start = microtime(true);
  23. // parse command line
  24. $opts = getopt('qfb:', Array('board:', 'quick', 'full', 'quiet'));
  25. $options = Array();
  26. $global_locale = $config['locale'];
  27. $options['board'] = isset($opts['board']) ? $opts['board'] : (isset($opts['b']) ? $opts['b'] : false);
  28. $options['quiet'] = isset($opts['q']) || isset($opts['quiet']);
  29. $options['quick'] = isset($opts['quick']);
  30. $options['full'] = isset($opts['full']) || isset($opts['f']);
  31. if(!$options['quiet'])
  32. echo "== Tinyboard + vichan {$config['version']} ==\n";
  33. if(!$options['quiet'])
  34. echo "Clearing template cache...\n";
  35. load_twig();
  36. $twig->clearCacheFiles();
  37. if(!$options['quiet'])
  38. echo "Regenerating theme files...\n";
  39. rebuildThemes('all');
  40. if(!$options['quiet'])
  41. echo "Generating Javascript file...\n";
  42. buildJavascript();
  43. $main_js = $config['file_script'];
  44. $boards = listBoards();
  45. foreach($boards as &$board) {
  46. if($options['board'] && $board['uri'] != $options['board'])
  47. continue;
  48. if(!$options['quiet'])
  49. echo "Opening board /{$board['uri']}/...\n";
  50. // Reset locale to global locale
  51. $config['locale'] = $global_locale;
  52. openBoard($board['uri']);
  53. $config['try_smarter'] = false;
  54. if($config['file_script'] != $main_js) {
  55. // different javascript file
  56. if(!$options['quiet'])
  57. echo "Generating Javascript file...\n";
  58. buildJavascript();
  59. }
  60. if(!$options['quiet'])
  61. echo "Creating index pages...\n";
  62. buildIndex();
  63. if($options['quick'])
  64. continue; // do no more
  65. if($options['full']) {
  66. $query = query(sprintf("SELECT `id` FROM ``posts_%s``", $board['uri'])) or error(db_error());
  67. while($post = $query->fetch()) {
  68. if(!$options['quiet'])
  69. echo "Rebuilding #{$post['id']}...\n";
  70. rebuildPost($post['id']);
  71. }
  72. }
  73. $query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
  74. while($post = $query->fetch()) {
  75. if(!$options['quiet'])
  76. echo "Rebuilding #{$post['id']}...\n";
  77. buildThread($post['id']);
  78. }
  79. }
  80. if(!$options['quiet'])
  81. printf("Complete! Took %g seconds\n", microtime(true) - $start);
  82. unset($board);
  83. modLog('Rebuilt everything using tools/rebuild.php');