Sha256: cbb1dc820647bb74c5ba33c75e16681e357a90e73df789487843d4a3055864bc

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# Returns a lambda that you can use with a before_filter in your
# CatalogController to catch and redirect query params using the old
# style
#
# This can be used to keep any old bookmarked URLs still working.
#
#     before_action BlacklightAdvancedSearch::RedirectLegacyParamsFilter, :only => :index
#
module BlacklightAdvancedSearch
  class RedirectLegacyParamsFilter
    def self.before(controller)
      params = controller.send(:params)
      legacy_converted = false

      # This was used prior to blacklight_advanceod_search 8
      i = 0
      controller.blacklight_config.search_fields.each do |_key, field|
        next unless params[field.key].present?
        legacy_converted = true

        params[:clause] ||= {}
        params[:clause][i] = {
          field: field.key,
          query: params[field.key]
        }
        i += 1

        params.delete(field.key)
      end

      # This was used prior to blacklight_advanced_search 5.0.
      if params[:f_inclusive] && params[:f_inclusive].respond_to?(:each_pair)

        params[:f_inclusive].each_pair do |field, value|
          next unless value.is_a? Hash
          # old style! convert!
          legacy_converted = true
          params[:f_inclusive][field] = value.keys
        end
      end

      if legacy_converted
        controller.send(:redirect_to, params, :status => :moved_permanently)
      end
    end
  end
  end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight_advanced_search-8.0.0.alpha1 lib/blacklight_advanced_search/redirect_legacy_params_filter.rb