You are here

function finder_update_6100 in Finder 7

Same name and namespace in other branches
  1. 6 finder.install \finder_update_6100()

Implements hook_update_N().

Changes due to caching feature being added, including shortening the match method storage value.

See also

hook_update_N()

File

./finder.install, line 179
Finder module install file.

Code

function finder_update_6100() {

  // Update finder's settings where possible to avoid problems in this update.
  $finders = finder_load_multiple(NULL, array(), TRUE);
  $find = array(
    'contains',
    'equals',
    'starts_with',
    'ends_with',
  );
  $replace = array(
    'c',
    'e',
    'sw',
    'ew',
  );
  foreach ($finders as $finder) {
    $changed = FALSE;
    if (isset($finder->settings['advanced']['match']) && in_array($finder->settings['advanced']['match'], $find)) {
      $finder->settings['advanced']['match'] = str_replace($find, $replace, $finder->settings['advanced']['match']);
      $changed = TRUE;
    }
    foreach ($finder->elements as $key => $element) {
      if (isset($element->settings['form']['match']) && in_array($element->settings['form']['match'], $find)) {
        $element->settings['form']['match'] = str_replace($find, $replace, $element->settings['form']['match']);
        $finder->elements[$key] = $element;
        $changed = TRUE;
      }
    }
    if ($changed) {
      finder_save($finder);
    }
  }

  // Add table 'cache_finder_find' - Strange name because it is anticipated
  // that 'cache_finder' might be used for something else down the track.
  $schema['cache_finder_find'] = finder_fetch_cache_schema('Used by Finder to cache options and results.');
  db_create_table('cache_finder_find', $schema['cache_finder_find']);
  cache_clear_all();
  return t('Updated settings of existing finders.');
}