Fixed remove distribution that has dependency projects or jobs.
authorSungmin Kim <dev.sungmin.kim@samsung.com>
Mon, 27 Jan 2014 11:52:21 +0000 (20:52 +0900)
committerSungmin Kim <dev.sungmin.kim@samsung.com>
Mon, 27 Jan 2014 11:52:21 +0000 (20:52 +0900)
dibs-web/app/controllers/admin_distribution_controller.rb
dibs-web/app/controllers/admin_project_controller.rb

index 00b5ad43835d834529f9544aa011d31ad7184c66..10d51edd592ab471057358f20ef3b38672caf7fb 100644 (file)
@@ -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
index 14b375a8e7af20b457bcdf9a5003be0612de5e45..17a49caac212dbd90e13a184daf5686725f7145b 100644 (file)
@@ -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]