Using transactions to create projects
This commit is contained in:
parent
43b7c2c2eb
commit
9b4f207fe3
|
@ -7,21 +7,26 @@ module Project::MassCreate
|
|||
module ClassMethods
|
||||
def run_mass_create(url, visibility, owner, add_to_repository_id)
|
||||
repository = Repository.find add_to_repository_id
|
||||
open(url) { |f|
|
||||
f.each_line {
|
||||
|line|
|
||||
open(url) do |f|
|
||||
projects = []
|
||||
ActiveRecord::Base.transaction do
|
||||
f.each_line do |line|
|
||||
project = owner.projects.build(
|
||||
name: line,
|
||||
visibility: visibility,
|
||||
is_package: false
|
||||
)
|
||||
project.owner = owner
|
||||
if project.save
|
||||
repository.projects << project rescue nil
|
||||
project.update_attributes(is_package: true)
|
||||
end
|
||||
}
|
||||
}
|
||||
projects << project if project.save
|
||||
end
|
||||
end
|
||||
ActiveRecord::Base.transaction do
|
||||
projects.each do |item|
|
||||
repository.projects << item
|
||||
item.update_attributes(is_package: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue