Skip to content

Instantly share code, notes, and snippets.

@parthaa
Created May 26, 2021 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parthaa/754d896decc68b91108a1e3f2a36dc14 to your computer and use it in GitHub Desktop.
Save parthaa/754d896decc68b91108a1e3f2a36dc14 to your computer and use it in GitHub Desktop.
def interested_hostgroups
Hostgroup.where(id: Katello::Hostgroup::ContentFacet.where(content_source_id: nil, kickstart_repository_id: nil, content_view_id: nil, lifecycle_environment_id: nil).select(:hostgroup_id))
end
def pick_facet_values(hg)
facet_values = {}
hg.audits.reverse.each do |audit|
hg_changes = audit.audited_changes.slice("lifecycle_environment_id", "kickstart_repository_id", "content_view_id", "content_source_id")
facet_values = hg_changes.merge(facet_values)
end
facet_values.map do |k,v|
v = v[-1] if v.is_a? Array
[k, v]
end.to_h
end
interested_hostgroups.each do |hg|
hg.content_facet.update!(pick_facet_values(hg))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment