From 968e8e24b25aabf455c8d9e0e86b1a2fe52e3c79 Mon Sep 17 00:00:00 2001 From: Sungmin Kim Date: Mon, 27 Jan 2014 20:52:21 +0900 Subject: [PATCH] Fixed remove distribution that has dependency projects or jobs. --- .../admin_distribution_controller.rb | 22 +++++++++++++++++++ .../controllers/admin_project_controller.rb | 16 ++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dibs-web/app/controllers/admin_distribution_controller.rb b/dibs-web/app/controllers/admin_distribution_controller.rb index 00b5ad4..10d51ed 100644 --- a/dibs-web/app/controllers/admin_distribution_controller.rb +++ b/dibs-web/app/controllers/admin_distribution_controller.rb @@ -143,6 +143,28 @@ class AdminDistributionController < ApplicationController sync_pkg_svr.destroy end + # remove project + projects = Project.find(:all, :conditions => ["distribution_id = ?", dist.id]) + projects.each do |project| + err = AdminProjectController.remove_project(project.id) + if err then + render :json => { :error => err}, :status => 406 + return + end + end + + # remove job info + jobs = Job.find(:all, :conditions => ["distribution_id = ?", dist.id]) + + if not jobs.nil? then + # remove job_timestamps table + jobs.each do |job| + jobTimestamp = JobTimestamp.delete_all(["job_id=?", job.id]) + job.destroy + end + + end + # remove distribution dist.destroy end diff --git a/dibs-web/app/controllers/admin_project_controller.rb b/dibs-web/app/controllers/admin_project_controller.rb index 14b375a..17a49ca 100644 --- a/dibs-web/app/controllers/admin_project_controller.rb +++ b/dibs-web/app/controllers/admin_project_controller.rb @@ -193,12 +193,20 @@ class AdminProjectController < ApplicationController project_id = change_item[:ProjectId] + err = remove_project(project_id) + if err then + render :json => { :error => err}, :status => 406 + else + render :json => { :success => "OK!" } + end + end + + def AdminProjectController.remove_project(project_id) project = Project.find(:first, :conditions => ["id = ?", project_id]) if project.nil? errmsg = "project does not exist: #{project_id}" - render :json => { :error => errmsg }, :status => 406 - return + return errmsg end # remove job info @@ -244,8 +252,8 @@ class AdminProjectController < ApplicationController # remove project project.destroy - render :json => { :success => "OK!" } - end + return + end def modifyProject change_group_list = params[:ChangeInfoList] -- 2.34.1