apply-template
1.7 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
#!/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
case $ARGV[0]
when 'inactive-enterprise'
offset = 0
excluded = [env.inactive_enterprise_template, env.enterprise_template]
template = excluded.first
while enterprise = Enterprise.find(:first, :conditions => {: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.find(:all, :conditions => {:enabled => true}) - [env.enterprise_template, env.enterprise_template]
active_enterprises.each { |enterprise| enterprise.apply_template(env.enterprise_template) }
when 'community'
communities = Community.find(:all) - [Community['espaco'], Community['anarquismo']]
communities.each { |community|
puts 'c: ' + community.identifier
community.apply_template(env.community_template)
community.reload
puts 'template applied'
community.articles.each { |article|
puts 'including ' + article.path + ' in the blog'
if !article.blog? && !article.is_a?(RssFeed)
article.parent_id = community.blog.id
article.save!
end
}
}
when 'person'
offset = 0
template = env.person_template
while person = Person.find(:first, :order => :id, :offset => offset)
if person != template
person.apply_template(template)
puts "#{offset} - #{person.identifier}"
end
offset = offset + 1
end
end