Using transactions to create projects

This commit is contained in:
duratarskeyk 2015-12-18 00:42:55 +00:00
parent 43b7c2c2eb
commit 9b4f207fe3
3 changed files with 26923 additions and 9 deletions

View File

@ -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

15654
open-uri20151217-2923-1xq4zau Normal file

File diff suppressed because it is too large Load Diff

11255
open-uri20151218-4828-118k1vj Normal file

File diff suppressed because it is too large Load Diff