Class: Actions::Katello::Product::Destroy
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::Katello::Product::Destroy
- Defined in:
- app/lib/actions/katello/product/destroy.rb
Instance Method Summary collapse
- #check_ready_to_delete(product, organization_destroy) ⇒ Object
- #clear_pool_associations(product) ⇒ Object
- #finalize ⇒ Object
- #humanized_name ⇒ Object
- #plan(product, options = {}) ⇒ Object
- #plan_content_destruction(product, skip_environment_update) ⇒ Object
- #plan_repo_destruction(product, options) ⇒ Object
- #view_versions(product) ⇒ Object
Instance Method Details
#check_ready_to_delete(product, organization_destroy) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/lib/actions/katello/product/destroy.rb', line 93 def check_ready_to_delete(product, organization_destroy) unless organization_destroy || product.user_deletable? if product.redhat? fail _("Cannot delete Red Hat product: %{product}") % { :product => product.name } elsif !product.published_content_view_versions.not_ignorable.empty? fail _("Cannot delete product with repositories published in a content view. Product: %{product}, %{view_versions}") % { :product => product.name, :view_versions => view_versions(product) } elsif product.repositories.any? { |repo| repo.filters.any? { |filter| filter.repositories.size == 1 } } fail _("Cannot delete product: %{product} with repositories that are the last affected repository in content view filters. Delete these repositories before deleting product.") % { :product => product.name } end end end |
#clear_pool_associations(product) ⇒ Object
59 60 61 |
# File 'app/lib/actions/katello/product/destroy.rb', line 59 def clear_pool_associations(product) product.pool_products.delete_all end |
#finalize ⇒ Object
50 51 52 53 |
# File 'app/lib/actions/katello/product/destroy.rb', line 50 def finalize product = ::Katello::Product.find(input[:product_id]) product.destroy! end |
#humanized_name ⇒ Object
55 56 57 |
# File 'app/lib/actions/katello/product/destroy.rb', line 55 def humanized_name _("Delete Product") end |
#plan(product, options = {}) ⇒ Object
5 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 46 47 48 |
# File 'app/lib/actions/katello/product/destroy.rb', line 5 def plan(product, = {}) organization_destroy = .fetch(:organization_destroy, false) skip_environment_update = .fetch(:skip_environment_update, false) || .fetch(:organization_destroy, false) check_ready_to_delete(product, organization_destroy) action_subject(product) # Candlepin::Product::ContentRemove is called with Katello::Repository::Destroy, so we only want to run ContentRemove # on repos that are not being destroyed with Katello::Repository::Destroy. content_ids = product.repositories.in_default_view.map(&:content_id) remaining_product_content = product.product_contents.select { |content| !content_ids.include?(content.content.cp_content_id) } sequence do unless organization_destroy sequence do # ContentDestroy must be called sequentially due to Candlepin's # issues with running multiple remove_content calls at the same time. plan_content_destruction(product, skip_environment_update) end concurrence do plan_repo_destruction(product, ) end 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) concurrence do remaining_product_content.each do |pc| plan_action(Candlepin::Product::ContentRemove, owner: product.organization.label, product_id: product.cp_id, content_id: pc.content.cp_content_id) end end plan_action(Candlepin::Product::Destroy, cp_id: product.cp_id, :owner => product.organization.label) end clear_pool_associations(product) plan_self(:product_id => product.id) end end |
#plan_content_destruction(product, skip_environment_update) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'app/lib/actions/katello/product/destroy.rb', line 63 def plan_content_destruction(product, skip_environment_update) product.repositories.in_default_view.each do |repo| if repo.root.repositories.where.not(id: repo.id).empty? && !repo.redhat? && !skip_environment_update plan_action(::Actions::Katello::Product::ContentDestroy, repo) end end end |
#plan_repo_destruction(product, options) ⇒ Object
73 74 75 76 77 78 |
# File 'app/lib/actions/katello/product/destroy.rb', line 73 def plan_repo_destruction(product, ) product.repositories.in_default_view.each do |repo| = .clone plan_action(Katello::Repository::Destroy, repo, .merge(destroy_content: false)) end end |
#view_versions(product) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/lib/actions/katello/product/destroy.rb', line 80 def view_versions(product) cvvs = product.published_content_view_versions.uniq views = cvvs.inject({}) do |result, version| result[version.content_view.name] ||= [] result[version.content_view.name] << version.version result end results = views.map do |view, versions| _("Content View %{view}: Versions: %{versions}") % {:view => view, :versions => versions.join(', ')} end results.join(', ') end |