gen_config.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. $base = $base ?? '/usr/local';
  35. $timestamp = date('r');
  36. echo <<<END
  37. #
  38. # Sphinx configuration for GNU social
  39. # Generated {$timestamp}
  40. #
  41. END;
  42. sphinx_iterate_sites('sphinx_site_template');
  43. print <<<END
  44. indexer
  45. {
  46. mem_limit = 300M
  47. }
  48. searchd
  49. {
  50. port = 3312
  51. log = {$base}/log/searchd.log
  52. query_log = {$base}/log/query.log
  53. read_timeout = 5
  54. max_children = 30
  55. pid_file = {$base}/log/searchd.pid
  56. max_matches = 1000
  57. seamless_rotate = 1
  58. preopen_indexes = 0
  59. unlink_old = 1
  60. }
  61. END;
  62. /**
  63. * Build config entries for a single site
  64. * @fixme we only seem to have master DB currently available...
  65. */
  66. function sphinx_site_template($sn)
  67. {
  68. if (common_config('db', 'type') !== 'mysql') {
  69. $created_ts = sprintf(
  70. '((EXTRACT(DAY %1$s) * 24 + EXTRACT(HOUR %1$s)) * 60 + ' .
  71. 'EXTRACT(MINUTE %1$s)) * 60 + FLOOR(EXTRACT(SECOND %1$s)) AS "created_ts"',
  72. 'FROM ("created" - TIMESTAMP \'1970-01-01 00:00:00\')'
  73. );
  74. } else {
  75. $created_ts = "timestampdiff(SECOND, '1970-01-01', `created`) AS `created_ts`";
  76. }
  77. return
  78. sphinx_template(
  79. $sn,
  80. 'profile',
  81. 'SELECT id, ' . $created_ts . ', nickname, fullname, location, bio, homepage FROM profile',
  82. 'SELECT * FROM profile WHERE id = $id'
  83. ) .
  84. sphinx_template(
  85. $sn,
  86. 'notice',
  87. 'SELECT id, ' . $created_ts . ', content FROM notice',
  88. 'SELECT * FROM notice WHERE notice.id = $id AND notice.is_local <> -2'
  89. );
  90. }
  91. function sphinx_template($sn, $table, $query, $query_info)
  92. {
  93. $base = sphinx_base();
  94. $dbtype = common_config('db', 'type');
  95. $charset = common_database_charset();
  96. echo <<<END
  97. #
  98. # {$sn->sitename}
  99. #
  100. source {$sn->dbname}_src_{$table}
  101. {
  102. type = {$dbtype}
  103. sql_host = {$sn->dbhost}
  104. sql_user = {$sn->dbuser}
  105. sql_pass = {$sn->dbpass}
  106. sql_db = {$sn->dbname}
  107. sql_query_pre = SET NAMES '{$charset}';
  108. sql_query = {$query}
  109. sql_query_info = {$query_info}
  110. sql_attr_timestamp = created_ts
  111. }
  112. index {$sn->dbname}_{$table}
  113. {
  114. source = {$sn->dbname}_src_{$table}
  115. path = {$base}/data/{$sn->dbname}_{$table}
  116. docinfo = extern
  117. charset_type = utf-8
  118. min_word_len = 3
  119. }
  120. END;
  121. }