You are here

function apachesolr_update_7009 in Apache Solr Search 8

Same name and namespace in other branches
  1. 7 apachesolr.install \apachesolr_update_7009()

Update Facet API block deltas to account for removal of numeric ID from field names.

File

./apachesolr.install, line 585
Install and related hooks for apachesolr_search.

Code

function apachesolr_update_7009() {
  if (variable_get('apachesolr_update_from_6303', FALSE)) {
    return NULL;
  }

  // Only run when facetapi is available and/or installed
  if (module_exists('facetapi')) {
    module_load_include('inc', 'facetapi', 'facetapi.block');

    // Get all searchers
    $searchers = facetapi_get_searcher_info();
    $realms = facetapi_get_realm_info();
    foreach ($searchers as $searcher_id => $searcher) {
      foreach ($realms as $realm_id => $realm) {
        foreach (field_info_fields() as $field_name => $field) {

          // Generate the old delta
          $facet_name_old = $field['id'] . '_' . $field['field_name'];
          $delta_old = facetapi_build_delta($searcher['name'], $realm['name'], $facet_name_old);
          $delta_old = substr(drupal_hash_base64($delta_old), 0, 32);

          // Generate the new delta
          $facet_name = $field['field_name'];
          $delta = facetapi_build_delta($searcher['name'], $realm['name'], $facet_name);
          $delta = substr(drupal_hash_base64($delta), 0, 32);
          db_update('block')
            ->fields(array(
            'delta' => $delta,
          ))
            ->condition('module', 'facetapi')
            ->condition('delta', $delta_old)
            ->execute();
        }
      }
    }
  }
}