function apachesolr_load_all_environments in Apache Solr Search 6.3
Same name and namespace in other branches
- 8 apachesolr.module \apachesolr_load_all_environments()
 - 7 apachesolr.module \apachesolr_load_all_environments()
 
Function that loads all the environments
Parameters
$reset: If TRUE, all environment caches are cleared and returns NULL.
Return value
$environments The environments in the database
22 calls to apachesolr_load_all_environments()
- apachesolr_clear_last_index_position in ./
apachesolr.module  - Clear a specific environment, or clear all.
 - apachesolr_content_extra_fields in ./
apachesolr.module  - Implements hook_content_extra_fields().
 - apachesolr_cron in ./
apachesolr.module  - Implements hook_cron(). Runs the indexing process on all writable environments or just a given environment. @todo See if we can add info to the content type array for the cron_check
 - apachesolr_devel in ./
apachesolr.admin.inc  - Callback for node/%node/devel/apachesolr
 - apachesolr_drush_solr_get_env_id in drush/
apachesolr.drush.inc  
File
- ./
apachesolr.module, line 1200  - Integration with the Apache Solr search application.
 
Code
function apachesolr_load_all_environments($reset = FALSE) {
  static $environments;
  if ($reset) {
    $environments = NULL;
    cache_clear_all('apachesolr:environments', 'cache_apachesolr');
    if (module_exists('ctools')) {
      ctools_include('export');
      ctools_export_load_object_reset('apachesolr_environment');
    }
    return;
  }
  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_results = db_query('SELECT * FROM {apachesolr_environment}');
      while ($environment_result = db_fetch_array($environments_results)) {
        $environments[$environment_result['env_id']] = $environment_result;
      }
    }
    // 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 = apachesolr_array_merge_deep_array(array(
      $environments,
      $conf_environments,
    ));
  }
  return $environments;
}