From a725a51bc315a4bf174973dbc78b0e36a539f086 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 3 Nov 2011 22:41:06 +0200 Subject: [PATCH] Disable XML callbacks during platform clone. Code cleanup. Refs #2162 --- app/models/platform.rb | 14 ++++++++------ app/models/project_to_repository.rb | 2 +- app/models/repository.rb | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index f1a6229f3..09852be09 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -23,7 +23,7 @@ class Platform < ActiveRecord::Base before_save :check_owner_rel # before_save :create_directory # after_destroy :remove_directory - before_create :xml_rpc_create + before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy # before_update :check_freezing after_create lambda { add_downloads_symlink unless self.hidden? } @@ -36,7 +36,6 @@ class Platform < ActiveRecord::Base #attr_accessible :visibility - def urpmi_list(host, pair = nil) blank_pair = {:login => 'login', :pass => 'password'} pair = blank_pair if pair.blank? @@ -83,7 +82,13 @@ class Platform < ActiveRecord::Base # TODO * make it Delayed Job * def make_clone(attrs) p = full_clone(attrs) - p.save and xml_rpc_clone(attrs[:unixname]) + begin + Thread.current[:skip] = true + p.save and xml_rpc_clone(attrs[:unixname]) + ensure + Thread.current[:skip] = false + end + # (Thread.current[:skip] = true) and p.save and (Thread.current[:skip] = false or true) and xml_rpc_clone(attrs[:unixname]) p end @@ -157,7 +162,6 @@ class Platform < ActiveRecord::Base end def xml_rpc_create -# return true result = BuildServer.add_platform unixname, APP_CONFIG['root_path'] + '/platforms' , distrib_type if result == BuildServer::SUCCESS return true @@ -167,7 +171,6 @@ class Platform < ActiveRecord::Base end def xml_rpc_destroy -# return true result = BuildServer.delete_platform unixname if result == BuildServer::SUCCESS return true @@ -177,7 +180,6 @@ class Platform < ActiveRecord::Base end def xml_rpc_clone(new_unixname) -# return true result = BuildServer.clone_platform new_unixname, self.unixname, APP_CONFIG['root_path'] + '/platforms' if result == BuildServer::SUCCESS return true diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index f8caddff8..69fb46a92 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -9,7 +9,7 @@ class ProjectToRepository < ActiveRecord::Base #after_destroy :remove_link #after_destroy :remove_compability_link - after_create lambda { project.xml_rpc_create(repository) } + after_create lambda { project.xml_rpc_create(repository) }, :unless => lambda {Thread.current[:skip]} after_destroy lambda { project.xml_rpc_destroy(repository) } after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? } diff --git a/app/models/repository.rb b/app/models/repository.rb index 9a8d1a9c1..7ebffc674 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -23,7 +23,7 @@ class Repository < ActiveRecord::Base #before_save :add_owner_rel #after_destroy :remove_directory - before_create :xml_rpc_create + before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy attr_accessible :name, :unixname, :platform_id