search_api_solr_overrides.module 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @file
  4. * Core hook implementations for Search API Solr Overrides.
  5. */
  6. /**
  7. * Implements hook_search_api_server_load().
  8. *
  9. * Provide a configuration as the same structure as the
  10. * search api server entity in array form (keyed by the
  11. * machine name of the solr service).
  12. *
  13. * Example:
  14. * $conf['search_api_solr_overrides'] = array(
  15. * 'solr-server-id' => array(
  16. * 'name' => 'Solr Server (Overridden)',
  17. * 'options' => array(
  18. * 'host' => '127.0.0.1',
  19. * 'port' => 8983,
  20. * 'path' => '/solr',
  21. * ),
  22. * ),
  23. * ),
  24. * );
  25. *
  26. * Note: This is an example as solr configurations vary.
  27. */
  28. function search_api_solr_overrides_search_api_server_load($servers) {
  29. // Get the solr host overrides.
  30. $overrides = variable_get('search_api_solr_overrides', FALSE);
  31. // Ensure the is information provided.
  32. if (empty($overrides) || !is_array($overrides)) {
  33. return;
  34. }
  35. // Loop over an make the required updates.
  36. foreach ($overrides as $id => $override) {
  37. // Check to see if the server config exists.
  38. if (!empty($servers[$id])) {
  39. foreach ($servers[$id] as $key => $field) {
  40. // Ensure we need to override. User isset, so we can set FALSE values.
  41. if (!isset($override[$key])) {
  42. continue;
  43. }
  44. // Check if the field contains an array.
  45. if (is_array($field)) {
  46. $servers[$id]->$key = array_merge($servers[$id]->$key, $override[$key]);
  47. }
  48. // Else its a value.
  49. else {
  50. $servers[$id]->$key = $override[$key];
  51. }
  52. }
  53. }
  54. }
  55. }