Commit 122dd00b0f9cfe9cdb772cf4d2d5f69724d0b138
1 parent
07e6b5ab
Exists in
master
and in
27 other branches
display_content: added migration to update sections attribute
Showing
1 changed file
with
30 additions
and
0 deletions
Show diff stats
plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb
0 → 100644
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +class UpdateDisplayContentSectionsArray < ActiveRecord::Migration | ||
2 | + | ||
3 | + def self.up | ||
4 | + translator = {'Publish date' => 'publish_date', 'Title' => 'title', 'Abstract' => 'abstract', 'Body' => 'body', 'Image' => 'image', 'Tags' => 'tags', | ||
5 | + 'Data de publicação' => 'publish_date', 'Título' => 'title', 'Resumo' => 'abstract', 'Corpo' => 'body', 'Imagem' => 'image'} | ||
6 | + | ||
7 | + DisplayContentBlock.find_each do |block| | ||
8 | + new_sections = [] | ||
9 | + | ||
10 | + block.sections.each do |section| | ||
11 | + new_value = translator[section["name"]] | ||
12 | + new_section = new_value.blank? ? section : {:value => new_value, :checked => !section["checked"].blank? } | ||
13 | + | ||
14 | + new_section_to_update = new_sections.select {|s| s[:value] == new_value}.first | ||
15 | + if new_section_to_update.blank? | ||
16 | + new_sections << new_section | ||
17 | + else | ||
18 | + new_section_to_update[:checked] = new_section[:checked] | ||
19 | + end | ||
20 | + end | ||
21 | + block.sections = new_sections | ||
22 | + block.update_attribute(:settings, block.settings) | ||
23 | + end | ||
24 | + end | ||
25 | + | ||
26 | + def self.down | ||
27 | + raise "this migration can't be reverted" | ||
28 | + end | ||
29 | + | ||
30 | +end |