Sha256: 26509ae13d888190bcfe4f4379905e0992ab3080a59b230a46f9559c0638b134

Contents?: true

Size: 1.59 KB

Versions: 15

Compression:

Stored size: 1.59 KB

Contents

module Katello
  module Glue::Candlepin::CandlepinObject
    extend ActiveSupport::Concern

    module ClassMethods
      def get_candlepin_ids(organization)
        self.get_for_owner(organization.label).map { |subscription| subscription["id"] }
      end

      def import_candlepin_ids(organization)
        candlepin_ids = self.get_candlepin_ids(organization)
        candlepin_ids.each do |cp_id|
          Katello::Util::Support.active_record_retry do
            self.where(:cp_id => cp_id, :organization_id => organization.id).first_or_create unless cp_id.nil?
          end
        end
        candlepin_ids
      end

      def with_identifier(ids)
        self.with_identifiers(ids).first
      end

      def with_identifiers(ids)
        ids = [ids] unless ids.is_a?(Array)
        ids.map!(&:to_s)
        id_integers = ids.map { |string| Integer(string) rescue -1 }
        where("#{self.table_name}.id = (?) or #{self.table_name}.cp_id = (?)", id_integers, ids)
      end

      def import_all(organization = nil, import_managed_associations = true)
        organizations = organization ? [organization] : Organization.all

        organizations.each do |org|
          candlepin_ids = import_candlepin_ids(org)

          objects = self.in_organization(org)
          objects.each do |item|
            if candlepin_ids.include?(item.cp_id)
              item.import_data
              item.import_managed_associations if import_managed_associations && item.respond_to?(:import_managed_associations)
            else
              item.destroy
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
katello-3.15.3.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.3 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.16.0.rc3 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.16.0.rc2.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.16.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.16.0.rc1.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.16.0.rc1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.0.1 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.0 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.0.rc2 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.0.rc1.3 app/models/katello/glue/candlepin/candlepin_object.rb
katello-3.15.0.rc1.2 app/models/katello/glue/candlepin/candlepin_object.rb