]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4569 The 'Bulk Deletion'>'Ghosts' page should display ALL projects whose defini...
authorJulien Lancelot <julien.lancelot@gmail.com>
Tue, 20 Aug 2013 15:16:15 +0000 (17:16 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Tue, 20 Aug 2013 15:16:15 +0000 (17:16 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb

index 5f1bb4f95cd8dfb7ab73b3ecfccc5ade2c618f3d..57a615ba4305b9d3d110485499498e2a21a0540d 100644 (file)
@@ -34,9 +34,9 @@ class BulkDeletionController < ApplicationController
     @selected_tab = params[:resource_type]
     @selected_tab = 'TRK' unless @tabs.include?(@selected_tab)
     
-    # Search for resources
-    conditions = "resource_index.qualifier=:qualifier"
-    values = {:qualifier => @selected_tab}
+    # Search for resources having snapshot with islast column to true
+    conditions = "resource_index.qualifier=:qualifier AND snapshots.islast=:islast"
+    values = {:qualifier => @selected_tab, :islast => true}
     if params[:name_filter] && !params[:name_filter].blank?
       conditions += " AND resource_index.kee LIKE :kee"
       values[:kee] = params[:name_filter].strip.downcase + '%'
@@ -46,7 +46,7 @@ class BulkDeletionController < ApplicationController
     values[:enabled] = true
     @resources = Project.all(:select => 'distinct(resource_index.resource_id),projects.id,projects.name,projects.kee,projects.long_name',
                               :conditions => [conditions, values],
-                              :joins => :resource_index)
+                              :joins => [:resource_index, :snapshots])
     @resources = Api::Utils.insensitive_sort!(@resources){|r| r.name}
   end
 
@@ -66,8 +66,13 @@ class BulkDeletionController < ApplicationController
     already_processed_project_ids = Snapshot.all(
         :select => 'project_id',
         :conditions => [conditions + " AND project_id IN (:pids)", values.merge({:status => Snapshot::STATUS_PROCESSED, :pids => unprocessed_project_ids})]).map(&:project_id).uniq
-    
-    @ghosts = Project.all(:conditions => ["id IN (?)", unprocessed_project_ids - already_processed_project_ids])
+
+    # Detect active projects without any snapshots or with no snapshot having islast column to true
+    projects_not_having_snapshots_islast_to_true =
+        Project.find_by_sql ["SELECT p.id FROM projects p WHERE p.enabled=? AND p.scope=? AND p.qualifier IN (?) AND NOT EXISTS (SELECT id FROM snapshots WHERE islast=? and project_id=p.id)",
+                             true, 'PRJ', @tabs, true]
+
+    @ghosts = Project.all(:conditions => ["id IN (?)", unprocessed_project_ids - already_processed_project_ids + projects_not_having_snapshots_islast_to_true])
     
     @ghosts_by_qualifier = {}
     @ghosts.each do |p|
index 719a4cdc34ab158ef11890364ef9710244c82dba..6833271ce269543fe6d21f8ea190005a128d9a24 100644 (file)
@@ -96,7 +96,7 @@ class ResourceDeletionManager
         @start_time = Time.now
         # launch the deletion
         resource_ids.each_with_index do |resource_id, index|
-          resource = Project.find(:first, :conditions => {:id => resource_id.to_i})
+          resource = Project.first(:conditions => {:id => resource_id.to_i})
           @message = Api::Utils.message('bulk_deletion.deletion_manager.currently_deleting_x_out_of_x', :params => [(index+1).to_s, resource_ids.size.to_s])
           if resource && java_facade.getResourceTypeBooleanProperty(resource.qualifier, 'deletable')
             begin