Class: Katello::Content
- Includes:
- Glue::Candlepin::Content
- Defined in:
- app/models/katello/content.rb
Class Method Summary collapse
- .import_all ⇒ Object
- .search_by_redhat(_key, _operator, value) ⇒ Object
- .substitute_content_path(content_path:, arch: nil, releasever: nil) ⇒ Object
Instance Method Summary collapse
- #can_update_to_url?(new_url) ⇒ Boolean
- #propagate_name_change? ⇒ Boolean
- #redhat? ⇒ Boolean
- #repositories ⇒ Object
- #root_repositories ⇒ Object
- #update_repository_names ⇒ Object
Methods included from Glue::Candlepin::Content
Methods inherited from Model
Class Method Details
.import_all ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/katello/content.rb', line 48 def self.import_all Organization.all.each do |org| cp_products = ::Katello::Resources::Candlepin::Product.all(org.label, [:id, :productContent]) product_hash = cp_products.group_by { |prod| prod['id'] } prod_content_importer = Katello::ProductContentImporter.new(cp_products) org.products.each do |product| product_json = product_hash[product.cp_id]&.first if product_json.nil? Rails.logger.warn _("Product with ID %s not found in Candlepin. Skipping content import for it.") % product.cp_id next end prod_content_importer.add_product_content(product, product_json['productContent']) end prod_content_importer.import end end |
.search_by_redhat(_key, _operator, value) ⇒ Object
16 17 18 19 20 21 22 |
# File 'app/models/katello/content.rb', line 16 def self.search_by_redhat(_key, _operator, value) conditions = Arel.sql(value == 'true' ? "#{Provider.table_name}.provider_type = 'Red Hat'" : "#{Provider.table_name}.provider_type != 'Red Hat'") { :conditions => conditions, :order => "#{Product.table_name}.name", :joins => {:product_contents => {:product => :provider}} } end |
.substitute_content_path(content_path:, arch: nil, releasever: nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/katello/content.rb', line 76 def self.substitute_content_path(content_path:, arch: nil, releasever: nil) arch = nil if arch == "noarch" substitutions = { :releasever => releasever, :basearch => arch, }.compact path = substitutions.inject(content_path) do |path_url, (key, value)| path_url.gsub("$#{key}", value) end { path: path, substitutions: substitutions, } end |
Instance Method Details
#can_update_to_url?(new_url) ⇒ Boolean
68 69 70 71 72 73 74 |
# File 'app/models/katello/content.rb', line 68 def can_update_to_url?(new_url) # We need to match the substitutable variables from # current content_url and new_url current_subs = content_url&.scan(/\$\w+/)&.sort new_url_subs = new_url&.scan(/\$\w+/)&.sort current_subs == new_url_subs end |
#propagate_name_change? ⇒ Boolean
44 45 46 |
# File 'app/models/katello/content.rb', line 44 def propagate_name_change? self.saved_change_to_attribute?(:name) && self.redhat? end |
#redhat? ⇒ Boolean
40 41 42 |
# File 'app/models/katello/content.rb', line 40 def redhat? products.redhat.any? end |
#repositories ⇒ Object
36 37 38 |
# File 'app/models/katello/content.rb', line 36 def repositories Katello::Repository.where(:root_id => root_repositories) end |
#root_repositories ⇒ Object
32 33 34 |
# File 'app/models/katello/content.rb', line 32 def root_repositories Katello::RootRepository.where(:content_id => self.cp_content_id) end |