Commit 82355e30511bf415c3ac3177dbb13e29cd77bfa9
1 parent
53f76fb0
Exists in
sisp_simple_version
check if env and domain exists before create
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
1 changed file
with
15 additions
and
5 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake
@@ -10,8 +10,9 @@ namespace :sisp do | @@ -10,8 +10,9 @@ namespace :sisp do | ||
10 | 10 | ||
11 | desc "Creates the SISP Environment" | 11 | desc "Creates the SISP Environment" |
12 | task :create_env => :environment do | 12 | task :create_env => :environment do |
13 | - env = Environment.create!(name: "SISP") | ||
14 | - env.domains << Domain.create!(name: "dev.sisp.gov.br") | 13 | + env = Environment.find_or_create_by_name("SISP") |
14 | + domain = Domain.find_or_create_by_name("novo.sisp.gov.br") | ||
15 | + env.domains << domain unless env.domains.include?(domain) | ||
15 | create_link_blocks env | 16 | create_link_blocks env |
16 | 17 | ||
17 | puts "SISP Environment created" | 18 | puts "SISP Environment created" |
@@ -36,6 +37,11 @@ namespace :sisp do | @@ -36,6 +37,11 @@ namespace :sisp do | ||
36 | task :create_template => :environment do | 37 | task :create_template => :environment do |
37 | env = Environment.find_by_name("SISP") | 38 | env = Environment.find_by_name("SISP") |
38 | 39 | ||
40 | + unless env.present? | ||
41 | + Rake::Task['sisp:create_env'].invoke | ||
42 | + env = Environment.find_by_name("SISP") | ||
43 | + end | ||
44 | + | ||
39 | if env.present? | 45 | if env.present? |
40 | template = Community.where(identifier: "sisp-software", environment_id: env).last | 46 | template = Community.where(identifier: "sisp-software", environment_id: env).last |
41 | template.destroy if template | 47 | template.destroy if template |
@@ -47,9 +53,12 @@ namespace :sisp do | @@ -47,9 +53,12 @@ namespace :sisp do | ||
47 | 53 | ||
48 | env.community_default_template = template | 54 | env.community_default_template = template |
49 | env.save! | 55 | env.save! |
56 | + | ||
57 | + puts "SISP Template created" | ||
58 | + else | ||
59 | + puts "SISP Template *NOT* created. Environment SISP not found." | ||
50 | end | 60 | end |
51 | 61 | ||
52 | - puts "SISP Template created" | ||
53 | end | 62 | end |
54 | 63 | ||
55 | def create_template_blocks template | 64 | def create_template_blocks template |
@@ -69,8 +78,9 @@ namespace :sisp do | @@ -69,8 +78,9 @@ namespace :sisp do | ||
69 | $imported_data = YAML.load_file('plugins/software_communities/public/static/sisp-catalog.yml') | 78 | $imported_data = YAML.load_file('plugins/software_communities/public/static/sisp-catalog.yml') |
70 | $env = Environment.find_by_name("SISP") | 79 | $env = Environment.find_by_name("SISP") |
71 | 80 | ||
72 | - $software_category = Category.find_by_name("Software") | ||
73 | - $software_category ||= Category.create(:name => "Software", :environment => $env) | 81 | + $software_category = Category.find_or_create_by_name("Software") |
82 | + $software_category.environment = $env | ||
83 | + $software_category.save! | ||
74 | 84 | ||
75 | $sisp_user = create_sisp_user | 85 | $sisp_user = create_sisp_user |
76 | 86 |