Class: Actions::Katello::OrphanCleanup::RemoveOrphans

Inherits:
Base
  • Object
show all
Defined in:
app/lib/actions/katello/orphan_cleanup/remove_orphans.rb

Instance Method Summary collapse

Instance Method Details

#plan(proxy) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/lib/actions/katello/orphan_cleanup/remove_orphans.rb', line 8

def plan(proxy)
  sequence do
    if proxy.pulp3_enabled?
      plan_action(
        Actions::Pulp3::Orchestration::OrphanCleanup::RemoveOrphans,
        proxy)
    end
    plan_self
  end
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/lib/actions/katello/orphan_cleanup/remove_orphans.rb', line 19

def run
  models = []
  ::Katello::RepositoryTypeManager.enabled_repository_types.each_value do |repo_type|
    indexable_types = repo_type.content_types_to_index
    models += indexable_types&.map(&:model_class)
    models.select! { |model| model.many_repository_associations }
  end
  models.each do |model|
    model.joins("left join katello_#{model.repository_association} on #{model.table_name}.id = katello_#{model.repository_association}.#{model.unit_id_field}").where("katello_#{model.repository_association}.#{model.unit_id_field} IS NULL").destroy_all
  end

  ::Katello::RootRepository.orphaned.destroy_all
end