From 523ad79e71f91b8df218575473fbd20c1e4c639d Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 20 Aug 2013 17:16:15 +0200 Subject: [PATCH] SONAR-4569 The 'Bulk Deletion'>'Ghosts' page should display ALL projects whose definition exist in the DB but which are not displayed in the SonarQube main page --- .../app/controllers/bulk_deletion_controller.rb | 17 +++++++++++------ .../app/models/resource_deletion_manager.rb | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb index 5f1bb4f95cd..57a615ba430 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb @@ -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| diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb index 719a4cdc34a..6833271ce26 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb @@ -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 -- 2.39.5