apply-template
2.1 KB
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
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
include GetText
ActionController::Base.init_gettext 'noosfero'
set_locale_all 'pt_BR'
env = Environment.default
def move_articles_to_blog(profile)
profile.articles.each { |article|
if !article.blog? && !article.is_a?(RssFeed) && article.published?
puts 'including ' + article.path + ' in the blog'
article.parent = profile.blog
article.save!
end
}
end
def report_doing(n, text)
puts "#{n} - #{text} ..."
end
def report_done
puts "[done]"
end
case $ARGV[0]
when 'inactive-enterprise'
offset = 0
excluded = [env.inactive_enterprise_template, env.enterprise_template]
template = excluded.first
while enterprise = Enterprise.where(enabled: false).order(:id).offset(offset)
# do nothing with templates
next if excluded.include?(enterprise)
# do the thing
enterprise.apply_template(template)
puts "#{offset} - #{enterprise.identifier}"
# bring it on ...
offset = offset + 1
end
when 'active-enterprise'
active_enterprises = Enterprise.where(enabled: true).all - [env.enterprise_template, env.enterprise_template]
active_enterprises.each do |enterprise|
old_home = enterprise.home_page
enterprise.apply_template(env.enterprise_template)
enterprise.home_page.update!(:body => old_home.body)
enterprise.save!
end
when 'community'
excluded = ['espaco', 'anarquismo']
template = env.community_template
offset = 0
while community = Community.order(:id).offset(offset)
if community != template && !excluded.include?(community.identifier)
report_doing offset, community.name
community.apply_template(template)
move_articles_to_blog(community)
report_done
end
offset = offset + 1
end
when 'person'
template = env.person_template
offset = 0
while person = Person.order(:id).offset(offset).first
if person != template
report_doing offset, person.identifier
person.apply_template(template)
# move_articles_to_blog(person) # does not make sense in most cases
report_done
end
offset = offset + 1
end
end