Sha256: 99a90775c7dd5bc9b0182b0165fe8b0e3d44a9081160807939e9634628715e1b

Contents?: true

Size: 1.22 KB

Versions: 22

Compression:

Stored size: 1.22 KB

Contents

class UpdateUrlAndRedirectUrlValue < ActiveRecord::Migration
  def up
    @redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
    I18n.available_locales.each do |locale|
      move_url_to_redirect_url(locale)
    end
  end

  def down
    @redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
    I18n.available_locales.each do |locale|
      move_redirect_url_to_url(locale)
    end

  end

  def move_url_to_redirect_url(locale)
    I18n.with_locale(locale) do
      @redirect_pages.each do |redirect_page|
        redirect_url = redirect_page.url
        redirect_page.update_attributes(:url => update_url(redirect_page), :redirect_url => redirect_url) if redirect_page
      end
    end
  end

  def move_redirect_url_to_url(locale)
    I18n.with_locale(locale) do
      @redirect_pages.each do |redirect_page|
        url = redirect_page.redirect_url
        redirect_page.update_attributes(:url => url, :redirect_url => nil, :page_type => nil) if redirect_page
      end
    end
  end

  def update_url(page)
    complete_slug = ''
    if page.parent.present?
      complete_slug << page.parent.url.to_s
    else
      complete_slug = "#{I18n.locale}"
    end
    complete_slug << "/#{page.slug}"
    complete_slug
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
kuhsaft-2.2.6 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.2.5 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.2.4 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.2.3 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.2.2 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.2.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.2.0 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.1.2 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.1.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.1.0 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-1.8.6 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-1.8.5 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.0.3 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.0.2 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-1.8.4 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-1.8.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.0.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.0.0 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-1.8.0 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-1.7.1 db/migrate/11_update_url_and_redirect_url_value.rb