-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37795 - set multiple Content Views via a single Activation key
- Loading branch information
Showing
25 changed files
with
502 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Katello | ||
module Util | ||
class FakeActivationKey < ApplicationRecord | ||
self.table_name = 'katello_activation_keys' | ||
end | ||
|
||
class CVEAKMigrator # used in db/migrate/20220929204746_add_content_view_environment_content_facet.rb | ||
def execute! | ||
aks_with_no_cve = [] | ||
aks_with_missing_cve = [] | ||
|
||
FakeActivationKey.all.each do |ak| | ||
if ::Katello::ContentView.exists?(id: ak.content_view_id) && ::Katello::KTEnvironment.exists?(ak.environment_id) | ||
cve = ::Katello::ContentViewEnvironment.find_by(content_view_id: ak.content_view_id, environment_id: ak.environment_id) | ||
if cve.blank? | ||
aks_with_no_cve << ak | ||
end | ||
else | ||
aks_with_missing_cve << ak | ||
end | ||
end | ||
|
||
if aks_with_missing_cve.present? || aks_with_no_cve.present? | ||
Rails.logger.warn "Found #{aks_with_no_cve.count} activation keys whose lifecycle environment does not have a corresponding ContentViewEnvironment" | ||
Rails.logger.warn "Found #{aks_with_missing_cve.count} activation keys whose content facet is missing either content_view_id or lifecycle_environment_id" | ||
Rails.logger.info "You may want to change the content view / lifecycle environment for these activation keys manually." | ||
end | ||
(aks_with_no_cve + aks_with_missing_cve).each do |ak| | ||
default_content_view = ak.organization.default_content_view | ||
library = ak.organization.library | ||
Rails.logger.info "Updating activation key #{ak.name} with default content_view_id and lifecycle_environment_id" | ||
ak&.update_columns(content_view_id: default_content_view&.id, environment_id: library&.id) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.