Class: Actions::Pulp::Repository::PurgeEmptyPackageGroups

Inherits:
AbstractAsyncTask show all
Defined in:
app/lib/actions/pulp/repository/purge_empty_package_groups.rb

Constant Summary

Constants inherited from AbstractAsyncTask

AbstractAsyncTask::FINISHED_STATES

Instance Method Summary collapse

Methods inherited from AbstractAsyncTask

#cancel, #cancel!, #done?, #external_task, #humanized_state, #rescue_external_task, #run

Methods inherited from Abstract

#pulp_extensions, #pulp_resources

Instance Method Details

#invoke_external_taskObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/lib/actions/pulp/repository/purge_empty_package_groups.rb', line 9

def invoke_external_task
  repo = ::Katello::Repository.where(:pulp_id => input[:pulp_id]).first
  rpm_names = repo.rpms.pluck(:name).uniq

  # Remove all  package groups with no packages
  package_groups_to_delete = repo.package_groups.select do |group|
    (rpm_names & group.package_names).empty?
  end
  criteria = {:association => {"unit_id" => {"$in" => package_groups_to_delete.compact}}}

  ::Katello.pulp_server.extensions.repository.unassociate_units(repo.pulp_id, :filters => criteria)
end