Commit fd7d75c5047258798cb5bcb1d51e40bd9178e959
1 parent
2123ef32
Exists in
stable-4.x
Improvements on task that creates discussion list
- Now the old articles are deleted and recreated following the template article Signed-off-by: Gustavo Coelho <gust.rod.coelho@gmail.com> (cherry picked from commit 2de9cb34b6729055c3c782d2157b4bbf665c5bad)
Showing
1 changed file
with
10 additions
and
6 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/tasks/templates.rake
@@ -41,21 +41,25 @@ namespace :templates do | @@ -41,21 +41,25 @@ namespace :templates do | ||
41 | 41 | ||
42 | desc "Copy mail list article from template to all Communities" | 42 | desc "Copy mail list article from template to all Communities" |
43 | task :copy_mail_article => :environment do | 43 | task :copy_mail_article => :environment do |
44 | + env = Environment.find_by_name("SPB") || Environment.default | ||
44 | article = Profile['software'].articles.find_by_slug('como-participar-da-lista-de-discussao') | 45 | article = Profile['software'].articles.find_by_slug('como-participar-da-lista-de-discussao') |
45 | - puts "Copying article #{article.title}: " | 46 | + Article.connection.execute("DELETE FROM articles WHERE slug='como-participar-da-lista-de-discussao' AND id NOT IN (#{article.id})") |
47 | + puts "Copying article #{article.title}: " if article.present? | ||
46 | if article.present? | 48 | if article.present? |
47 | - SoftwareInfo.find_each do |software| | ||
48 | - community = software.community | 49 | + env.communities.find_each do |community| |
50 | + next unless community.software? | ||
49 | a_copy = community.articles.find_by_slug('como-participar-da-lista-de-discussao') || article.copy_without_save | 51 | a_copy = community.articles.find_by_slug('como-participar-da-lista-de-discussao') || article.copy_without_save |
50 | - a_copy.profile = software.community | ||
51 | - a_copy.save if a_copy.profile.present? | 52 | + a_copy.profile = community |
53 | + a_copy.save | ||
52 | box = community.boxes.detect {|x| x.blocks.find_by_title("Participe") } if community.present? | 54 | box = community.boxes.detect {|x| x.blocks.find_by_title("Participe") } if community.present? |
53 | block = box.blocks.find_by_title("Participe") if box.present? | 55 | block = box.blocks.find_by_title("Participe") if box.present? |
54 | - link = block.links.detect { |l| l["name"] == "Lista de E-mails" } if block.present? | 56 | + link = block.links.detect { |l| l["name"] == "Listas de discussão" } if block.present? |
55 | link["address"] = "/{profile}/#{a_copy.path}" if link.present? | 57 | link["address"] = "/{profile}/#{a_copy.path}" if link.present? |
56 | block.save if block.present? | 58 | block.save if block.present? |
57 | print "." | 59 | print "." |
58 | end | 60 | end |
61 | + else | ||
62 | + puts "Article not found" | ||
59 | end | 63 | end |
60 | end | 64 | end |
61 | end | 65 | end |