Commit 2de9cb34b6729055c3c782d2157b4bbf665c5bad
1 parent
f099ccdc
Exists in
master
and in
12 other branches
Improvements on task that creates discussion list
- Now the old articles are deleted and recreated following the template article igned-off-by: Gustavo Coelho <gust.rod.coelho@gmail.com>
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 | 41 | |
| 42 | 42 | desc "Copy mail list article from template to all Communities" |
| 43 | 43 | task :copy_mail_article => :environment do |
| 44 | + env = Environment.find_by_name("SPB") || Environment.default | |
| 44 | 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 | 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 | 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 | 54 | box = community.boxes.detect {|x| x.blocks.find_by_title("Participe") } if community.present? |
| 53 | 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 | 57 | link["address"] = "/{profile}/#{a_copy.path}" if link.present? |
| 56 | 58 | block.save if block.present? |
| 57 | 59 | print "." |
| 58 | 60 | end |
| 61 | + else | |
| 62 | + puts "Article not found" | |
| 59 | 63 | end |
| 60 | 64 | end |
| 61 | 65 | end | ... | ... |