fixed remove distribution that has dependency. 63/15963/1
authorSungmin Kim <dev.sungmin.kim@samsung.com>
Mon, 3 Feb 2014 07:06:10 +0000 (16:06 +0900)
committerSungmin Kim <dev.sungmin.kim@samsung.com>
Mon, 3 Feb 2014 07:06:10 +0000 (16:06 +0900)
Signed-off-by: Sungmin Kim <dev.sungmin.kim@samsung.com>
Change-Id: Iac995325124e8300c1e275f1080837c24099d824

dibs-web/app/controllers/admin_distribution_controller.rb
dibs-web/app/controllers/admin_project_controller.rb
dibs-web/app/controllers/admin_server_controller.rb
dibs-web/public/javascripts/dibs-api.js

index 10d51ed..eb1b354 100644 (file)
@@ -157,12 +157,9 @@ class AdminDistributionController < ApplicationController
             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
+                    AdminProjectController.removeJob(job.id)
                 end
-
             end
             
                        # remove distribution
index 17a49ca..214a0b9 100644 (file)
@@ -193,7 +193,7 @@ class AdminProjectController < ApplicationController
 
                project_id  = change_item[:ProjectId]
 
-        err = remove_project(project_id)
+        err = AdminProjectController.remove_project(project_id)
         if err then
                        render :json => { :error => err}, :status => 406
         else
@@ -213,27 +213,34 @@ class AdminProjectController < ApplicationController
         jobs = Job.find(:all, :conditions => ["project_id =?", project_id])
 
         if not jobs.nil? then
-            # remove job_timestamps table
             jobs.each do |job|
-                jobTimestamp = JobTimestamp.delete_all(["job_id=?", job.id])
-                job.destroy
+                AdminProjectController.removeJob(job.id)
             end
-
         end
 
-               case project.ptype
-               when "GIT"
-            # remove source info
-            sources = Source.find(:all, :conditions => ["project_id = ?", project_id])
-
-            if not sources.nil? then
+        # remove source info
+        sources = Source.find(:all, :conditions => ["project_id = ?", project_id])
+        if not sources.nil? then
+            sources.each do |source|
                 # remove package
-                sources.each do |source|
-                           Package.delete_all(["source_id = ?", source.id])
-                    source.destroy
+                   Package.delete_all(["source_id = ?", source.id])
+                
+                # remove job info (If sync job ,project_id is empty in jobs)
+                jobs = Job.find(:all, :conditions => ["source_id =?", source.id])
+                if not jobs.nil? then
+                    jobs.each do |job|
+                        AdminProjectController.removeJob(job.id)
+                    end
                 end
+
+                source.destroy
             end
+            
+        end
 
+        # remove sub-project table
+               case project.ptype
+               when "GIT"
                        ProjectGit.delete_all(["project_id = ?", project_id])
                        ProjectOs.delete_all(["project_id = ?", project_id])
                        GroupProjectAccess.delete_all(["project_id = ?", project_id])
@@ -255,6 +262,19 @@ class AdminProjectController < ApplicationController
         return
     end
 
+    def AdminProjectController.removeJob(id)
+        job = Job.find(id)
+        
+        # remove child job
+        children_job = Job.find(:all, :conditions => ["parent_job_id = ?", job.id])
+        children_job.each do |child_job|
+            AdminProjectController.removeJob(child_job.id)
+        end
+        
+        JobTimestamp.delete_all(["job_id=?", job.id])
+        job.destroy
+    end
+
        def modifyProject
                change_group_list = params[:ChangeInfoList]
                change_item = change_group_list[0]
index aa55578..5136382 100644 (file)
@@ -244,13 +244,27 @@ class AdminServerController < ApplicationController
 
                server = RemoteBuildServer.find(:first, :conditions => ["id = ?", id])
         
-               if server.nil? 
+               if server.nil? then
                        errmsg = "Server does not exist"
                        render :json => { :error => errmsg }, :status => 406
-               else
-                       server.destroy
-                       render :json => { :success => "OK!" }
-               end
+            return
+        end
+        
+        # remove job info
+        jobs = Job.find(:all, :conditions => ["remote_build_server_id=?", 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
+
+               server.destroy
+               render :json => { :success => "OK!" }
+               
        end
 
        def addOSCategory
index fd324b7..70d601e 100644 (file)
@@ -332,7 +332,7 @@ function getInfoFromServerData(url, data, successFunction) {
                dataType: 'xml',
                text: 'JSONP',
                data: data,
-               timeout: 10000,
+               timeout: 300000,
                success: function(xml) {
                        setSessionInfo(xml);
                        successFunction(xml);
@@ -350,9 +350,9 @@ function postForServer(url, changeInfoList, successFunction) {
                data: JSON.stringify({ ChangeInfoList: changeInfoList }),
                dataType: 'json',
                contentType: "application/json; charset=utf-8",
-               timeout: 10000,
+               timeout: 3600000,
                beforeSend: function() { $.mobile.showPageLoadingMsg(); }, //Show spinner
-               complete: function() { $.mobile.hidePageLoadingMsg() }, //Hide spinner
+               complete: function() { $.mobile.hidePageLoadingMsg(); }, //Hide spinner
                success: function(xml) {
                        successFunction(xml);
                },
@@ -371,7 +371,7 @@ function deleteForServer(url, successFunction) {
                dataType: 'xml',
                timeout: 1000,
                beforeSend: function() { $.mobile.showPageLoadingMsg(); }, //Show spinner
-               complete: function() { $.mobile.hidePageLoadingMsg() }, //Hide spinner
+               complete: function() { $.mobile.hidePageLoadingMsg(); }, //Hide spinner
                success: function(xml) {
                        expireSession();
                        dibsWebClear();