You are here

function location_update_6309 in Location 7.3

Same name and namespace in other branches
  1. 6.3 location.install \location_update_6309()
  2. 7.5 location.install \location_update_6309()
  3. 7.4 location.install \location_update_6309()

There has been a change in the options for the views distance/proximity filter.

The old options need to be migrated into the new.

File

./location.install, line 1550
Install, update and uninstall functions for the location module.

Code

function location_update_6309() {
  $updated_views = array();
  if (module_exists('views')) {
    $views = views_get_all_views();
    foreach ($views as $view) {
      $modified = FALSE;

      // For each view check all filters of all displays for the distance field filter.
      foreach ($view->display as $did => $display) {
        if (isset($display->display_options['filters']) && !empty($display->display_options['filters'])) {
          foreach ($display->display_options['filters'] as $fid => $filter) {
            if ($filter['table'] == 'location' && $filter['field'] == 'distance') {

              // Set the origin (new option) from the type (old option).
              $origin = '';
              switch ($filter['type']) {
                case 'latlon':
                  $origin = 'static';
                  break;
                case 'postal':
                case 'postal_default':
                case 'latlon_gmap':
                  $origin = $filter['type'];
                  break;
              }
              if ($origin) {
                $view->display[$did]->display_options['filters'][$fid]['origin'] = $origin;
                unset($view->display[$did]->display_options['filters'][$fid]['type']);
                $modified = TRUE;
              }
            }
          }
        }
      }

      // Save the view if we changed any options on any displays.
      // Views caches are cleared during save so we don't have to do it.
      if ($modified) {
        $updated_views[] = $view->name;
        $view
          ->save();
      }
    }
  }
  if (!empty($updated_views)) {
    return t("Note: The 'Form type' option for the 'Location: Distance / Proximity' filter in views has been changed and is now the 'Origin' option.  The following views were using that setting and have been updated to use the new setting: %views.", array(
      '%views' => implode(', ', $updated_views),
    ));
  }
}