function apachesolr_environment_save in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.module \apachesolr_environment_save()
- 6.3 apachesolr.module \apachesolr_environment_save()
Function that saves an environment
Parameters
$environment: The environment it needs to save.
10 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 - Set the environment url based on the environment ID
- apachesolr_environment_clone in ./
apachesolr.module - Function that clones an environment
- apachesolr_environment_edit_submit in ./
apachesolr.admin.inc - Submit handler for the environment edit page
File
- ./
apachesolr.module, line 1361 - Integration with the Apache Solr search application.
Code
function apachesolr_environment_save($environment) {
module_load_include('inc', 'apachesolr', 'apachesolr.index');
$default = array(
'env_id' => '',
'name' => '',
'url' => '',
'service_class' => '',
);
// If the environment has been saved to the database before, we need to make
// sure we don't loose anything when saving it; therefore, load the existing
// environment and merge its' data with the new one.
$old_environment = apachesolr_environment_load($environment['env_id']);
if (!empty($old_environment['in_code_only']) && $environment != $old_environment) {
$environment = drupal_array_merge_deep($old_environment, $environment);
}
$conf = isset($environment['conf']) ? $environment['conf'] : array();
$index_bundles = isset($environment['index_bundles']) ? $environment['index_bundles'] : array();
// Remove any unexpected fields.
// @todo - get this from the schema?.
$environment = array_intersect_key($environment, $default);
db_merge('apachesolr_environment')
->key(array(
'env_id' => $environment['env_id'],
))
->fields($environment)
->execute();
// Update the environment variables (if any).
db_delete('apachesolr_environment_variable')
->condition('env_id', $environment['env_id'])
->execute();
foreach ($conf as $name => $value) {
db_merge('apachesolr_environment_variable')
->key(array(
'env_id' => $environment['env_id'],
'name' => $name,
))
->fields(array(
'value' => serialize($value),
))
->execute();
}
// 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();
}