Merge pull request #211 from warpc/207-platform_clone_bg
[Refs #207] * Redo clone logic * Split clone process for repositories * Optimize and refactor
This commit is contained in:
commit
accce3e7be
|
@ -115,10 +115,8 @@ class PlatformsController < ApplicationController
|
|||
end
|
||||
|
||||
def make_clone
|
||||
@cloned = @platform.base_clone(:name => params[:platform]['name'], :description => params[:platform]['description'],
|
||||
:owner_id => current_user.id, :owner_type => current_user.class.to_s)
|
||||
if with_skip{@cloned.save}
|
||||
@cloned.delay.clone_complete
|
||||
@cloned = @platform.full_clone params[:platform].merge(:owner => current_user)
|
||||
if @cloned.persisted?
|
||||
flash[:notice] = I18n.t("flash.platform.clone_success")
|
||||
redirect_to @cloned
|
||||
else
|
||||
|
|
|
@ -100,30 +100,20 @@ class Platform < ActiveRecord::Base
|
|||
|
||||
def base_clone(attrs = {}) # :description, :name, :owner
|
||||
clone.tap do |c|
|
||||
c.attributes = attrs # do not set protected
|
||||
c.attributes = attrs # attrs.each {|k,v| c.send("#{k}=", v)}
|
||||
c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
c.parent = self
|
||||
end
|
||||
end
|
||||
|
||||
# def full_clone(attrs = {}) # :description, :name, :owner
|
||||
# clone.tap do |c|
|
||||
# c.attributes = attrs # do not set protected
|
||||
# c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
# c.parent = self
|
||||
# c.repositories = repositories.map(&:full_clone)
|
||||
# c.products = products.map(&:full_clone)
|
||||
# end
|
||||
# end
|
||||
|
||||
def clone_relations(from = parent)
|
||||
self.repositories = from.repositories.map(&:full_clone)
|
||||
self.repositories = from.repositories.map{|r| r.full_clone(:platform_id => id)}
|
||||
self.products = from.products.map(&:full_clone)
|
||||
end
|
||||
|
||||
def clone_complete
|
||||
with_skip do
|
||||
clone_relations and xml_rpc_clone
|
||||
def full_clone(attrs = {})
|
||||
base_clone(attrs).tap do |c|
|
||||
with_skip {c.save} and c.clone_relations(self) and c.delay.xml_rpc_clone
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -61,8 +61,9 @@ class Product < ActiveRecord::Base
|
|||
|
||||
def full_clone(attrs = {})
|
||||
clone.tap do |c| # dup
|
||||
c.attributes = attrs # do not set protected
|
||||
c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
c.platform_id = nil
|
||||
attrs.each {|k,v| c.send("#{k}=", v)}
|
||||
c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,11 +15,23 @@ class Repository < ActiveRecord::Base
|
|||
|
||||
attr_accessible :description, :name
|
||||
|
||||
def full_clone(attrs = {})
|
||||
def base_clone(attrs = {})
|
||||
clone.tap do |c| # dup
|
||||
c.attributes = attrs # do not set protected
|
||||
c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
c.projects = projects
|
||||
c.platform_id = nil
|
||||
attrs.each {|k,v| c.send("#{k}=", v)}
|
||||
c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
end
|
||||
end
|
||||
|
||||
def clone_relations(from)
|
||||
with_skip do
|
||||
from.projects.find_each {|p| self.projects << p}
|
||||
end
|
||||
end
|
||||
|
||||
def full_clone(attrs = {})
|
||||
base_clone(attrs).tap do |c|
|
||||
with_skip {c.save} and c.delay.clone_relations(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue