You are here

function apachesolr_environment_load_subrecords in Apache Solr Search 8

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

Export callback to load the view subrecords, which are the index bundles.

1 call to apachesolr_environment_load_subrecords()
apachesolr_load_all_environments in ./apachesolr.module
Function that loads all the environments

File

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

Code

function apachesolr_environment_load_subrecords(&$environments) {
  if (empty($environments)) {

    // Nothing to do.
    return NULL;
  }
  $all_index_bundles = db_select('apachesolr_index_bundles', 'ib')
    ->fields('ib', array(
    'env_id',
    'entity_type',
    'bundle',
  ))
    ->condition('env_id', array_keys($environments), 'IN')
    ->orderBy('env_id')
    ->orderBy('entity_type')
    ->orderBy('bundle')
    ->execute()
    ->fetchAll(PDO::FETCH_ASSOC);
  $all_index_bundles_keyed = array();
  foreach ($all_index_bundles as $env_info) {
    extract($env_info);
    $all_index_bundles_keyed[$env_id][$entity_type][] = $bundle;
  }
  $all_variables = db_select('apachesolr_environment_variable', 'v')
    ->fields('v', array(
    'env_id',
    'name',
    'value',
  ))
    ->condition('env_id', array_keys($environments), 'IN')
    ->orderBy('env_id')
    ->orderBy('name')
    ->orderBy('value')
    ->execute()
    ->fetchAll(PDO::FETCH_ASSOC);
  $variables = array();
  foreach ($all_variables as $variable) {
    extract($variable);
    $variables[$env_id][$name] = unserialize($value);
  }
  foreach ($environments as $env_id => &$environment) {
    $index_bundles = !empty($all_index_bundles_keyed[$env_id]) ? $all_index_bundles_keyed[$env_id] : array();
    $conf = !empty($variables[$env_id]) ? $variables[$env_id] : array();
    if (is_array($environment)) {

      // Environment is an array.
      // If we have different values in the database compared with what we
      // have in the given environment argument we allow the admin to revert
      // the db values so we can stick with a consistent system
      if (!empty($environment['index_bundles']) && !empty($index_bundles) && $environment['index_bundles'] !== $index_bundles) {
        unset($environment['in_code_only']);
        $environment['type'] = 'Overridden';
      }
      if (!empty($environment['conf']) && !empty($conf) && $environment['conf'] !== $conf) {
        unset($environment['in_code_only']);
        $environment['type'] = 'Overridden';
      }
      $environment['index_bundles'] = empty($environment['index_bundles']) || !empty($index_bundles) ? $index_bundles : $environment['index_bundles'];
      $environment['conf'] = empty($environment['conf']) || !empty($conf) ? $conf : $environment['conf'];
    }
    elseif (is_object($environment)) {

      // Environment is an object.
      if ($environment->index_bundles !== $index_bundles && !empty($index_bundles)) {
        unset($environment->in_code_only);
        $environment->type = 'Overridden';
      }
      if ($environment->conf !== $conf && !empty($conf)) {
        unset($environment->in_code_only);
        $environment->type = 'Overridden';
      }
      $environment->index_bundles = empty($environment->index_bundles) || !empty($index_bundles) ? $index_bundles : $environment->index_bundles;
      $environment->conf = empty($environment->conf) || !empty($conf) ? $conf : $environment->conf;
    }
  }
}