gen_config.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. /**
  18. * @package GNUsocial
  19. * @copyright 2009 StatusNet, Inc.
  20. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  21. */
  22. define('INSTALLDIR', dirname(__DIR__, 3));
  23. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  24. $longoptions = array('base=', 'network');
  25. $helptext = <<<END_OF_TRIM_HELP
  26. Generates sphinx.conf file based on StatusNet configuration.
  27. --base Base dir to Sphinx install
  28. (default /usr/local)
  29. --network Use status_network global config table
  30. (non-functional at present)
  31. END_OF_TRIM_HELP;
  32. require_once INSTALLDIR . '/scripts/commandline.inc';
  33. require dirname(__FILE__) . '/sphinx-utils.php';
  34. $timestamp = date('r');
  35. print <<<END
  36. #
  37. # Sphinx configuration for StatusNet
  38. # Generated {$timestamp}
  39. #
  40. END;
  41. sphinx_iterate_sites('sphinx_site_template');
  42. print <<<END
  43. indexer
  44. {
  45. mem_limit = 300M
  46. }
  47. searchd
  48. {
  49. port = 3312
  50. log = {$base}/log/searchd.log
  51. query_log = {$base}/log/query.log
  52. read_timeout = 5
  53. max_children = 30
  54. pid_file = {$base}/log/searchd.pid
  55. max_matches = 1000
  56. seamless_rotate = 1
  57. preopen_indexes = 0
  58. unlink_old = 1
  59. }
  60. END;
  61. /**
  62. * Build config entries for a single site
  63. * @fixme we only seem to have master DB currently available...
  64. */
  65. function sphinx_site_template($sn)
  66. {
  67. if (common_config('db', 'type') !== 'mysql') {
  68. $created_ts = sprintf(
  69. '((EXTRACT(DAY %1$s) * 24 + EXTRACT(HOUR %1$s)) * 60 + ' .
  70. 'EXTRACT(MINUTE %1$s)) * 60 + FLOOR(EXTRACT(SECOND %1$s)) AS "created_ts"',
  71. 'FROM ("created" - TIMESTAMP \'1970-01-01 00:00:00\')'
  72. );
  73. } else {
  74. $created_ts = "timestampdiff(SECOND, '1970-01-01', `created`) AS `created_ts`";
  75. }
  76. return
  77. sphinx_template(
  78. $sn,
  79. 'profile',
  80. 'SELECT id, ' . $created_ts . ', nickname, fullname, location, bio, homepage FROM profile',
  81. 'SELECT * FROM profile WHERE id = $id'
  82. ) .
  83. sphinx_template(
  84. $sn,
  85. 'notice',
  86. 'SELECT id, ' . $created_ts . ', content FROM notice',
  87. 'SELECT * FROM notice WHERE notice.id = $id AND notice.is_local <> -2'
  88. );
  89. }
  90. function sphinx_template($sn, $table, $query, $query_info)
  91. {
  92. $base = sphinx_base();
  93. $dbtype = common_config('db', 'type');
  94. print <<<END
  95. #
  96. # {$sn->sitename}
  97. #
  98. source {$sn->dbname}_src_{$table}
  99. {
  100. type = {$dbtype}
  101. sql_host = {$sn->dbhost}
  102. sql_user = {$sn->dbuser}
  103. sql_pass = {$sn->dbpass}
  104. sql_db = {$sn->dbname}
  105. sql_query_pre = SET NAMES utf8;
  106. sql_query = {$query}
  107. sql_query_info = {$query_info}
  108. sql_attr_timestamp = created_ts
  109. }
  110. index {$sn->dbname}_{$table}
  111. {
  112. source = {$sn->dbname}_src_{$table}
  113. path = {$base}/data/{$sn->dbname}_{$table}
  114. docinfo = extern
  115. charset_type = utf-8
  116. min_word_len = 3
  117. }
  118. END;
  119. }