@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 + '%'
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
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|
@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