From 122dd00b0f9cfe9cdb772cf4d2d5f69724d0b138 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 20 May 2014 11:00:00 -0300 Subject: [PATCH] display_content: added migration to update sections attribute --- plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+), 0 deletions(-) create mode 100644 plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb 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