You are here

function apachesolr_environment_save in Apache Solr Search 6.3

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

Function that saves an environment

Parameters

$environment: The environment it needs to save.

11 calls to apachesolr_environment_save()
AbstractDrupalSolrOnlineWebTestCase::setUpSolr in tests/solr_index_and_search.test
apachesolr_ctools_environment_save in ./apachesolr.module
Callback for saving Apache Solr environment CTools exportables.
apachesolr_drush_solr_set_env_url in drush/apachesolr.drush.inc
apachesolr_environment_clone in ./apachesolr.module
Function that clones an environment
apachesolr_environment_edit_submit in ./apachesolr.admin.inc

... See full list

File

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

Code

function apachesolr_environment_save($environment) {
  module_load_include('inc', 'apachesolr', 'apachesolr.index');

  // Update or insert since D6 has no db_merge(). Update the environment if it exists.
  if (db_result(db_query("SELECT 1 FROM {apachesolr_environment} WHERE env_id = '%s'", $environment['env_id']))) {
    $query = "UPDATE {apachesolr_environment} SET name = '%s', url = '%s', service_class = '%s' WHERE env_id = '%s'";
    db_query($query, array(
      $environment['name'],
      $environment['url'],
      $environment['service_class'],
      $environment['env_id'],
    ));
  }
  else {
    $query = "INSERT INTO {apachesolr_environment} (env_id, name, url, service_class) VALUES ('%s', '%s', '%s', '%s')";
    db_query($query, array(
      $environment['env_id'],
      $environment['name'],
      $environment['url'],
      $environment['service_class'],
    ));
  }
  $conf = isset($environment['conf']) ? $environment['conf'] : array();
  $index_bundles = isset($environment['index_bundles']) ? $environment['index_bundles'] : array();

  // Update the environment variables (if any).
  foreach ($conf as $name => $value) {
    apachesolr_environment_variable_set($environment['env_id'], $name, $value);
  }

  // Update the index bundles (if any).
  foreach ($index_bundles as $entity_type => $bundles) {
    apachesolr_index_set_bundles($environment['env_id'], $entity_type, $bundles);
  }
  apachesolr_environments_clear_cache();
}