Class: Katello::Content

Inherits:
Model
  • Object
show all
Includes:
Glue::Candlepin::Content
Defined in:
app/models/katello/content.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Glue::Candlepin::Content

#modified_product_ids

Methods inherited from Model

#destroy!

Class Method Details

.import_allObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


40
41
42
# File 'app/models/katello/content.rb', line 40

def redhat?
  products.redhat.any?
end

#repositoriesObject



36
37
38
# File 'app/models/katello/content.rb', line 36

def repositories
  Katello::Repository.where(:root_id => root_repositories)
end

#root_repositoriesObject



32
33
34
# File 'app/models/katello/content.rb', line 32

def root_repositories
  Katello::RootRepository.where(:content_id => self.cp_content_id)
end

#update_repository_namesObject



26
27
28
29
30
# File 'app/models/katello/content.rb', line 26

def update_repository_names
  root_repositories.each do |root|
    root.update!(:name => root.calculate_updated_name)
  end
end