Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
class BlocksMigration
def self.cleanup
clean_cta
clean_chapter
clean_definitions
clean_gallery
clean_image
clean_posts
clean_pages
end
private
def self.clean_cta
Communication::Block.where(template_kind: 'call_to_action').each do |block|
data = block['data']
if data && data['url'].present?
elements = []
if data['url'].present?
elements << { title: data['button'], url: data['url'], target_blank: data['target_blank']}
end
if data['url_secondary'].present?
elements << { title: data['button_secondary'], url: data['url_secondary'], target_blank: data['target_blank_secondary']}
end
if data['url_tertiary'].present?
elements << { title: data['button_tertiary'], url: data['url_tertiary'], target_blank: data['target_blank_tertiary']}
end
data['elements'] = elements
data['alt'] = data['image_alt']
data['credit'] = data['image_credit']
block['data'] = data
block.save
end
end
end
def self.clean_chapter
Communication::Block.where(template_kind: 'chapter').each do |block|
data = block['data']
if data && (data['image_alt'].present? || data['image_credit'].present?)
data['alt'] = data['image_alt']
data['credit'] = data['image_credit']
block['data'] = data
block.save
end
end
end
def self.clean_definitions
Communication::Block.where(template_kind: 'definitions').each do |block|
data = block['data']
if data && data['elements'].any? && data['elements'].first.has_key?('text')
elements = []
data['elements'].each do |elmt|
elements << { title: elmt['title'], description: elmt['text'] }
end
data['elements'] = elements
block['data'] = data
block.save
end
end
end
def self.clean_gallery
Communication::Block.where(template_kind: 'gallery').each do |block|
data = block['data']
if data && data['elements'].any? && data['elements'].first.has_key?('file')
elements = []
data['elements'].each do |elmt|
elements << { alt: elmt['alt'], text: elmt['text'], credit: elmt['credit'], image: elmt['file'] }
end
data['elements'] = elements
block['data'] = data
block.save
end
end
end
def self.clean_image
Communication::Block.where(template_kind: 'image').each do |block|
data = block['data']
if data && (data['image_alt'].present? || data['image_credit'].present?)
data['alt'] = data['image_alt']
data['credit'] = data['image_credit']
block['data'] = data
block.save
end
end
end
def self.clean_posts
Communication::Block.where(template_kind: 'posts').each do |block|
data = block['data']
if data && data['kind'].present?
data['mode'] = data['kind']
block['data'] = data
block.save
end
end
end
def self.clean_pages
Communication::Block.where(template_kind: 'pages').each do |block|
data = block['data']
if data && data['kind'].present?
data['mode'] = data['kind']
block['data'] = data
block.save
end
end
end
end