You are here

function _search_api_elasticsearch_elastica_path in Search API Elasticsearch 7

Return path to Elastica library path, or FALSE if not found.

1 call to _search_api_elasticsearch_elastica_path()
_search_api_elasticsearch_elastica_autoload in modules/elastica/search_api_elasticsearch_elastica.module
Autoloader for the Elastica classes.

File

modules/elastica/search_api_elasticsearch_elastica.module, line 58
Provides an elasticsearch-based service class for the Search API.

Code

function _search_api_elasticsearch_elastica_path($reset = FALSE) {
  static $path = NULL;
  if ($reset === TRUE) {
    $path = NULL;
  }
  if (!isset($path)) {
    $path = FALSE;

    // If Libraries API is installed, we first use that to try and find the
    // library. Otherwise we manually check a few locations.
    $search_dirs = array();
    if (function_exists('libraries_get_path')) {
      $dir = libraries_get_path('Elastica');

      // Confusingly, Libraries API 1.x will return sites/all/libraries/NAME on
      // failure, while Libraries API 2.x returns FALSE in that case.
      if (!empty($dir)) {
        $search_dirs[] = $dir;
      }
    }
    else {
      $search_dirs[] = 'sites/all/libraries/Elastica';
    }
    $search_dirs[] = drupal_get_path('module', 'search_api_elasticsearch') . '/Elastica';
    foreach ($search_dirs as $dir) {
      $dir = DRUPAL_ROOT . '/' . $dir . '/lib';
      if (is_dir($dir)) {
        $path = $dir;
        break;
      }
    }
  }
  return $path;
}