The version of vichan running on lainchan.org
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

141 рядки
3.9KB

  1. #!/usr/bin/php
  2. <?php
  3. /*
  4. * rebuild.php - rebuilds all static files
  5. * This is much different than the one in vichan because we have way more static files. It will not work without pcntl_fork.
  6. * You must specify the things you want to rebuild. By default the script does nothing.
  7. * Example of how to use:
  8. * php rebuild.php --cache --js --indexes --processes 5
  9. * That will clear the cache, rebuild all JS files and all indexes, and fork 5 processes to do it faster.
  10. * I removed the quiet option, it's useless. Just use output redirection.
  11. */
  12. require dirname(__FILE__) . '/inc/cli.php';
  13. $start = microtime(true);
  14. // parse command line
  15. $opts = getopt('', Array('board:', 'themes', 'js', 'indexes', 'threads', 'processes:', 'cache', 'postmarkup', 'api'));
  16. $options = Array();
  17. $global_locale = $config['locale'];
  18. // Do only one board?
  19. $options['board'] = isset($opts['board']) ? $opts['board'] : (isset($opts['b']) ? $opts['b'] : false);
  20. // Clear the cache?
  21. $options['cache'] = isset($opts['cache']);
  22. // Rebuild themes (catalogs)?
  23. $options['themes'] = isset($opts['themes']);
  24. // Rebuild JS?
  25. $options['js'] = isset($opts['js']);
  26. // Rebuild indexes? (e.g. /b/index.html)
  27. $options['indexes'] = isset($opts['indexes']);
  28. // Rebuild threads? (e.g. /b/res/1.html)
  29. $options['threads'] = isset($opts['threads']);
  30. // Rebuild all post markup? (e.g. /b/res/1.html#2)
  31. $options['postmarkup'] = isset($opts['postmarkup']);
  32. // Rebuild API pages? (e.g. /b/res/1.json')
  33. $options['api'] = isset($opts['api']);
  34. // How many processes?
  35. $options['processes'] = isset($opts['processes']) ? $opts['processes'] : 1;
  36. echo "== Tinyboard + vichan {$config['version']} ==\n";
  37. if ($options['cache']) {
  38. echo "Clearing template cache...\n";
  39. load_twig();
  40. $twig->clearCacheFiles();
  41. }
  42. if($options['themes']) {
  43. echo "Regenerating theme files...\n";
  44. rebuildThemes('all');
  45. }
  46. if($options['js']) {
  47. echo "Generating Javascript file...\n";
  48. buildJavascript();
  49. }
  50. $main_js = $config['file_script'];
  51. $boards = listBoards();
  52. //$boards = array(array('uri'=>'test'), array('uri'=>'tester'), array('uri'=>'testing'));
  53. $boards_m = array_chunk($boards, floor(sizeof($boards)/$options['processes']));
  54. function doboard($board) {
  55. global $global_locale, $config, $main_js, $options;
  56. $config['mask_db_error'] = false;
  57. if (!$options['api']) $config['api']['enabled'] = false;
  58. echo "Opening board /{$board['uri']}/...\n";
  59. // Reset locale to global locale
  60. $config['locale'] = $global_locale;
  61. init_locale($config['locale'], 'error');
  62. openBoard($board['uri']);
  63. $config['try_smarter'] = false;
  64. if($config['file_script'] != $main_js && $options['js']) {
  65. // different javascript file
  66. echo "(/{$board['uri']}/) Generating Javascript file...\n";
  67. buildJavascript();
  68. }
  69. if ($options['indexes']) {
  70. echo "(/{$board['uri']}/) Creating index pages...\n";
  71. buildIndex();
  72. }
  73. if($options['postmarkup']) {
  74. $query = query(sprintf("SELECT `id` FROM ``posts_%s``", $board['uri'])) or error(db_error());
  75. while($post = $query->fetch()) {
  76. echo "(/{$board['uri']}/) Rebuilding #{$post['id']}...\n";
  77. rebuildPost($post['id']);
  78. }
  79. }
  80. if ($options['threads']) {
  81. $query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
  82. while($post = $query->fetch()) {
  83. echo "(/{$board['uri']}/) Rebuilding #{$post['id']}...\n";
  84. @buildThread($post['id']);
  85. }
  86. }
  87. }
  88. $children = array();
  89. foreach ($boards_m as $i => $bb) {
  90. $pid = pcntl_fork();
  91. if ($pid == -1) {
  92. die('Fork failed?');
  93. } else if ($pid) {
  94. echo "Started PID #$pid...\n";
  95. $children[] = $pid;
  96. } else {
  97. unset($pdo);
  98. $i = 0;
  99. $total = sizeof($bb);
  100. sql_open();
  101. foreach ($bb as $i => $b) {
  102. $i++;
  103. doboard($b);
  104. echo "I'm on board $i/$total\n";
  105. }
  106. break;
  107. }
  108. }
  109. printf("Complete! Took %g seconds\n", microtime(true) - $start);
  110. unset($board);
  111. foreach ($children as $child) {
  112. pcntl_waitpid($child, $status);
  113. unset($children[$child]);
  114. }
  115. //modLog('Rebuilt everything using tools/rebuild.php');