diff --git a/plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb b/plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb new file mode 100644 index 0000000..306c87d --- /dev/null +++ b/plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb @@ -0,0 +1,30 @@ +class UpdateDisplayContentSectionsArray < ActiveRecord::Migration + + def self.up + translator = {'Publish date' => 'publish_date', 'Title' => 'title', 'Abstract' => 'abstract', 'Body' => 'body', 'Image' => 'image', 'Tags' => 'tags', + 'Data de publicação' => 'publish_date', 'Título' => 'title', 'Resumo' => 'abstract', 'Corpo' => 'body', 'Imagem' => 'image'} + + DisplayContentBlock.find_each do |block| + new_sections = [] + + block.sections.each do |section| + new_value = translator[section["name"]] + new_section = new_value.blank? ? section : {:value => new_value, :checked => !section["checked"].blank? } + + new_section_to_update = new_sections.select {|s| s[:value] == new_value}.first + if new_section_to_update.blank? + new_sections << new_section + else + new_section_to_update[:checked] = new_section[:checked] + end + end + block.sections = new_sections + block.update_attribute(:settings, block.settings) + end + end + + def self.down + raise "this migration can't be reverted" + end + +end -- libgit2 0.21.2