Class: Actions::Katello::Product::Destroy

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/katello/product/destroy.rb

Instance Method Summary collapse

Instance Method Details

#finalizeObject



47
48
49
50
# File 'app/lib/actions/katello/product/destroy.rb', line 47

def finalize
  product = ::Katello::Product.find(input[:product_id])
  product.destroy!
end

#humanized_nameObject



52
53
54
# File 'app/lib/actions/katello/product/destroy.rb', line 52

def humanized_name
  _("Delete Product")
end

#plan(product, options = {}) ⇒ Object

rubocop:disable MethodLength



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/lib/actions/katello/product/destroy.rb', line 6

def plan(product, options = {})
  organization_destroy = options.fetch(:organization_destroy, false)

  unless organization_destroy || product.user_deletable?
    fail _("Cannot delete a Red Hat Products or Products with Repositories published in a Content View")
  end

  action_subject(product)

  sequence do
    unless organization_destroy
      concurrence do
        product.repositories.in_default_view.each do |repo|
          repo_options = options.clone
          repo_options[:planned_destroy] = true
          plan_action(Katello::Repository::Destroy, repo, repo_options)
        end
      end
      concurrence do
        plan_action(Candlepin::Product::DeletePools,
                      cp_id: product.cp_id, organization_label: product.organization.label)
        plan_action(Candlepin::Product::DeleteSubscriptions,
                      cp_id: product.cp_id, organization_label: product.organization.label)
      end
    end

    if !product.used_by_another_org? && !organization_destroy
      concurrence do
        product.productContent.each do |pc|
          plan_action(Candlepin::Product::ContentRemove,
                      product_id: product.cp_id,
                      content_id: pc.content.id)
        end
      end
      plan_action(Candlepin::Product::Destroy, cp_id: product.cp_id)
    end

    plan_self(:product_id => product.id)
  end
end