Merge pull request #209 from warpc/207-platform_clone_bg

[Refs #207] Place XML RPC clone request to DJ
Refactor platform clone controller and routes
Refactor and fix clone process for platform, repository, product
This commit is contained in:
Vladimir Sharshov 2012-02-21 13:44:49 -08:00
commit 39f9e98d04
6 changed files with 26 additions and 27 deletions

View File

@ -109,19 +109,20 @@ 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"
flash[:error] = @cloned.errors.full_messages.join('. ')
render 'clone'
end
end

View File

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

View File

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

View File

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

View File

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

View File

@ -71,7 +71,7 @@ Rosa::Application.routes.draw do
post 'freeze'
post 'unfreeze'
get 'clone'
post 'clone'
post 'make_clone'
post 'build_all'
end