Sha256: 0a4845d6a43c9415a2daf7c65c61b583b5092d154d302a6c73982db49aefa935

Contents?: true

Size: 937 Bytes

Versions: 4

Compression:

Stored size: 937 Bytes

Contents

class TranslateCustomTitleOnPages < ActiveRecord::Migration
  def self.up
    unless ::Page::Translation.column_names.map(&:to_sym).include?(:custom_title)
      add_column ::Page::Translation.table_name, :custom_title, :string

      # Re-save custom_title
      ::Page.all.each do |page|
        page.update_attribute(:custom_title, page.untranslated_attributes['custom_title'])
      end

    end

    if ::Page.column_names.map(&:to_sym).include?(:custom_title)
      remove_column ::Page.table_name, :custom_title
    end
  end

  def self.down
    # Restore
    add_column ::Page.table_name, :custom_title, :string

    # Re-save custom_title
    ::Page.all.each do |page|
      ::Page.update_all({
        :custom_title => page.attributes['custom_title']
      }, {
        :id => page.id.to_s
      }) unless page.attributes['custom_title'].nil?
    end

    remove_column ::Page::Translation.table_name, :custom_title
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
refinerycms-pages-0.9.9.9 db/migrate/20110307025652_translate_custom_title_on_pages.rb
refinerycms-pages-0.9.9.8 db/migrate/20110307025652_translate_custom_title_on_pages.rb
refinerycms-pages-0.9.9.7 db/migrate/20110307025652_translate_custom_title_on_pages.rb
refinerycms-pages-0.9.9.5 db/migrate/20110307025652_translate_custom_title_on_pages.rb