Fixed: import.rake task: Validation failed: Project already exists in platform

This commit is contained in:
Vokhmin Alexey V 2013-10-24 19:43:18 +04:00
parent 21883a9e02
commit 6172d27a7b
1 changed files with 3 additions and 3 deletions

View File

@ -46,14 +46,14 @@ namespace :import do
if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present?
if clear # simply add
project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id)
repo.projects << project
repo.projects << project rescue nil
else # check if project already added
if project = repo.projects.find_by_name(name) || repo.projects.by_name(name).first # fallback to speedup
print "Found project '#{project.name_with_owner}' in '#{platform.name}/#{repo.name}'."
elsif scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) and
project = scoped.find_by_name(name) || scoped.by_name(name).first
begin
repo.projects << project
repo.projects << project rescue nil
rescue Exception => e
print "Add project '#{project.name_with_owner}' to '#{platform.name}/#{repo.name}' FAILED: #{e.message}."
else
@ -62,7 +62,7 @@ namespace :import do
else
description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`)
project = Project.create!(:name => name, :description => description) {|p| p.owner = owner}
repo.projects << project
repo.projects << project rescue nil
print "Create project #{project.name_with_owner} in #{platform.name}/#{repo.name} OK."
end
end