Refactor platform clone controller and routes. Refactor and fix clone process for platform, repository, product. Place XML RPC clone request to DJ. Refs #207
This commit is contained in:
parent
5e58ec9e59
commit
600df031f5
|
@ -109,19 +109,21 @@ class PlatformsController < ApplicationController
|
|||
end
|
||||
|
||||
def clone
|
||||
if request.post?
|
||||
@cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'],
|
||||
:owner_id => current_user.id, :owner_type => current_user.class.to_s)
|
||||
if @cloned.persisted?
|
||||
flash[:notice] = I18n.t("flash.platform.clone_success")
|
||||
redirect_to @cloned
|
||||
else
|
||||
flash[:error] = @cloned.errors.full_messages.join('. ')
|
||||
end
|
||||
@cloned = Platform.new
|
||||
@cloned.name = @platform.name + "_clone"
|
||||
@cloned.description = @platform.description + "_clone"
|
||||
end
|
||||
|
||||
def make_clone
|
||||
@cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'],
|
||||
:owner_id => current_user.id, :owner_type => current_user.class.to_s)
|
||||
if @cloned.persisted? # valid?
|
||||
flash[:notice] = I18n.t("flash.platform.clone_success")
|
||||
redirect_to @cloned
|
||||
else
|
||||
@cloned = Platform.new
|
||||
@cloned.name = @platform.name + "_clone"
|
||||
@cloned.description = @platform.description + "_clone"
|
||||
raise @cloned.repositories.first.inspect
|
||||
flash[:error] = @cloned.errors.full_messages.join('. ')
|
||||
render 'clone'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -98,23 +98,21 @@ class Platform < ActiveRecord::Base
|
|||
platform_type == 'personal'
|
||||
end
|
||||
|
||||
def full_clone(attrs) # :description, :name, :owner
|
||||
def full_clone(attrs = {}) # :description, :name, :owner
|
||||
clone.tap do |c|
|
||||
c.attributes = attrs
|
||||
c.attributes = attrs # do not set protected
|
||||
c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
c.parent = self
|
||||
new_attrs = {:platform_id => nil}
|
||||
c.repositories = repositories.map{|r| r.full_clone(new_attrs.merge(:owner_id => attrs[:owner_id], :owner_type => attrs[:owner_type]))}
|
||||
c.products = products.map{|p| p.full_clone(new_attrs)}
|
||||
c.repositories = repositories.map(&:full_clone)
|
||||
c.products = products.map(&:full_clone)
|
||||
end
|
||||
end
|
||||
|
||||
# TODO * make it Delayed Job *
|
||||
def make_clone(attrs)
|
||||
p = full_clone(attrs)
|
||||
begin
|
||||
Thread.current[:skip] = true
|
||||
p.save and xml_rpc_clone(attrs[:name])
|
||||
p.save and self.delay.xml_rpc_clone(attrs[:name])
|
||||
ensure
|
||||
Thread.current[:skip] = false
|
||||
end
|
||||
|
|
|
@ -59,10 +59,10 @@ class Product < ActiveRecord::Base
|
|||
EOF
|
||||
end
|
||||
|
||||
def full_clone(attrs) # owner
|
||||
def full_clone(attrs = {})
|
||||
clone.tap do |c| # dup
|
||||
c.attributes = attrs
|
||||
c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
c.attributes = attrs # do not set protected
|
||||
c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ class Repository < ActiveRecord::Base
|
|||
|
||||
attr_accessible :description, :name
|
||||
|
||||
def full_clone(attrs) # owner
|
||||
def full_clone(attrs = {})
|
||||
clone.tap do |c| # dup
|
||||
c.attributes = attrs
|
||||
c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
c.attributes = attrs # do not set protected
|
||||
c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil
|
||||
c.projects = projects
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
%h2.title
|
||||
= t("layout.platforms.clone_header")
|
||||
.inner
|
||||
= form_for @cloned, :url => clone_platform_path(@platform), :html => { :class => :form } do |f|
|
||||
= form_for @cloned, :url => make_clone_platform_path(@platform), :html => { :class => :form } do |f|
|
||||
.group
|
||||
= f.label :name, :class => :label
|
||||
= f.text_field :name, :class => 'text_field'
|
||||
|
|
|
@ -71,7 +71,7 @@ Rosa::Application.routes.draw do
|
|||
post 'freeze'
|
||||
post 'unfreeze'
|
||||
get 'clone'
|
||||
post 'clone'
|
||||
post 'make_clone'
|
||||
post 'build_all'
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue