forked from refinery/refinerycms
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change from :custom_title to :menu_title in existing migration.
- Loading branch information
Showing
2 changed files
with
42 additions
and
27 deletions.
There are no files selected for viewing
26 changes: 13 additions & 13 deletions
26
db/migrate/20110307025652_translate_custom_title_on_pages.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 29 additions & 14 deletions
43
pages/db/migrate/20110307025652_translate_custom_title_on_pages.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
class TranslateCustomTitleOnPages < ActiveRecord::Migration | ||
def self.up | ||
unless ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(:custom_title) | ||
add_column ::Refinery::Page.translation_class.table_name, :custom_title, :string | ||
unless ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(:menu_title) | ||
add_column ::Refinery::Page.translation_class.table_name, :menu_title, :string | ||
|
||
# Re-save custom_title | ||
::Refinery::Page.all.each do |page| | ||
page.update_attribute(:custom_title, page.untranslated_attributes['custom_title']) | ||
say_with_time("Re-save menu_title") do | ||
::Refinery::Page.all.each do |page| | ||
say "updating menu_title field for page##{page.id}" | ||
page.update_attribute(:menu_title, page.untranslated_attributes['menu_title']) | ||
end | ||
end | ||
|
||
else | ||
say "Nothing done, ::Refinery::Page.translation_class table already includes a menu_title field" | ||
end | ||
|
||
::Refinery::Page.translation_class.reset_column_information | ||
end | ||
|
||
def self.down | ||
# Re-save custom_title | ||
::Refinery::Page.all.each do |page| | ||
::Refinery::Page.update_all({ | ||
:custom_title => page.attributes['custom_title'] | ||
}, { | ||
:id => page.id.to_s | ||
}) unless page.attributes['custom_title'].nil? | ||
say_with_time("Re-save menu_title") do | ||
::Refinery::Page.all.each do |page| | ||
if page.attributes['menu_title'].nil? | ||
say "Nothing done, page##{page.id} menu_title field is nil" | ||
else | ||
say "updating menu_title field for page #{page.id}" | ||
::Refinery::Page.update_all({ | ||
:menu_title => page.attributes['menu_title'] | ||
}, { | ||
:id => page.id.to_s | ||
}) | ||
end | ||
end | ||
end | ||
|
||
remove_column ::Refinery::Page.translation_class.table_name, :custom_title | ||
remove_column ::Refinery::Page.translation_class.table_name, :menu_title | ||
|
||
::Refinery::Page.translated_attribute_names.delete(:menu_title) | ||
|
||
::Refinery::Page.translation_class.reset_column_information | ||
end | ||
end |