sphinx-utils.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. function sphinx_use_network()
  20. {
  21. return have_option('network');
  22. }
  23. function sphinx_base()
  24. {
  25. if (have_option('base')) {
  26. return get_option_value('base');
  27. } else {
  28. return "/usr/local/sphinx";
  29. }
  30. }
  31. function sphinx_iterate_sites($callback)
  32. {
  33. if (sphinx_use_network()) {
  34. // @fixme this should use, like, some kind of config
  35. Status_network::setupDB('localhost', 'statusnet', 'statuspass', 'statusnet');
  36. $sn = new Status_network();
  37. if (!$sn->find()) {
  38. die("Confused... no sites in status_network table or lookup failed.\n");
  39. }
  40. while ($sn->fetch()) {
  41. $callback($sn);
  42. }
  43. } else {
  44. if (preg_match('!^(mysqli?|pgsql)://(.*?):(.*?)@(.*?)/(.*?)$!',
  45. common_config('db', 'database'), $matches)) {
  46. list(/*all*/, $dbtype, $dbuser, $dbpass, $dbhost, $dbname) = $matches;
  47. $sn = (object)array(
  48. 'sitename' => common_config('site', 'name'),
  49. 'dbhost' => $dbhost,
  50. 'dbuser' => $dbuser,
  51. 'dbpass' => $dbpass,
  52. 'dbname' => $dbname);
  53. $callback($sn);
  54. } else {
  55. print "Unrecognized database configuration string in config.php\n";
  56. exit(1);
  57. }
  58. }
  59. }