You are here

function apachesolr_load_all_environments in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr.module \apachesolr_load_all_environments()
  2. 7 apachesolr.module \apachesolr_load_all_environments()

Function that loads all the environments

Return value

$environments The environments in the database

19 calls to apachesolr_load_all_environments()
apachesolr_clear_last_index_position in ./apachesolr.module
Clear a specific environment, or clear all.
apachesolr_cron in ./apachesolr.module
Implements hook_cron(). Runs the indexing process on all writable environments or just a given environment.
apachesolr_devel in ./apachesolr.admin.inc
Page callback for node/%node/devel/apachesolr.
apachesolr_drush_solr_get_env_id in drush/apachesolr.drush.inc
Get all the environments (using option all) or get the default environment id
apachesolr_entity_info_alter in ./apachesolr.module
Implements hook_entity_info_alter().

... See full list

1 string reference to 'apachesolr_load_all_environments'
apachesolr_environments_clear_cache in ./apachesolr.module
Clear all caches for environments.

File

./apachesolr.module, line 1209
Integration with the Apache Solr search application.

Code

function apachesolr_load_all_environments() {
  $environments =& drupal_static(__FUNCTION__);
  if (isset($environments)) {
    return $environments;
  }

  // Use cache_get to avoid DB when using memcache, etc.
  $cache = cache_get('apachesolr:environments', 'cache_apachesolr');
  if (isset($cache->data)) {
    $environments = $cache->data;
  }
  elseif (!db_table_exists('apachesolr_index_bundles') || !db_table_exists('apachesolr_environment')) {

    // Sometimes this function is called when the 'apachesolr_index_bundles' is
    // not created yet.
    $environments = array();
  }
  else {

    // If ctools is available use its crud functions to load the environments.
    if (module_exists('ctools')) {
      ctools_include('export');
      $environments = ctools_export_load_object('apachesolr_environment', 'all');

      // Convert environments to array.
      foreach ($environments as &$environment) {
        $environment = (array) $environment;
      }
    }
    else {
      $environments = db_query('SELECT * FROM {apachesolr_environment}')
        ->fetchAllAssoc('env_id', PDO::FETCH_ASSOC);
    }

    // Load conf and index bundles. We don't use 'subrecords callback' property
    // of ctools export API.
    apachesolr_environment_load_subrecords($environments);
    cache_set('apachesolr:environments', $environments, 'cache_apachesolr');
  }

  // Allow overrides of environments from settings.php
  $conf_environments = variable_get('apachesolr_environments', array());
  if (!empty($conf_environments)) {
    $environments = drupal_array_merge_deep($environments, $conf_environments);
  }
  return $environments;
}