Using transactions to create projects
This commit is contained in:
parent
43b7c2c2eb
commit
9b4f207fe3
|
@ -7,21 +7,26 @@ module Project::MassCreate
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def run_mass_create(url, visibility, owner, add_to_repository_id)
|
def run_mass_create(url, visibility, owner, add_to_repository_id)
|
||||||
repository = Repository.find add_to_repository_id
|
repository = Repository.find add_to_repository_id
|
||||||
open(url) { |f|
|
open(url) do |f|
|
||||||
f.each_line {
|
projects = []
|
||||||
|line|
|
ActiveRecord::Base.transaction do
|
||||||
|
f.each_line do |line|
|
||||||
project = owner.projects.build(
|
project = owner.projects.build(
|
||||||
name: line,
|
name: line,
|
||||||
visibility: visibility,
|
visibility: visibility,
|
||||||
is_package: false
|
is_package: false
|
||||||
)
|
)
|
||||||
project.owner = owner
|
project.owner = owner
|
||||||
if project.save
|
projects << project if project.save
|
||||||
repository.projects << project rescue nil
|
end
|
||||||
project.update_attributes(is_package: true)
|
end
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
projects.each do |item|
|
||||||
|
repository.projects << item
|
||||||
|
item.update_attributes(is_package: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
}
|
|
||||||
}
|
|
||||||
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