Last active
October 2, 2017 18:21
-
-
Save mccun934/bc0155858127bcb13d3262c89461c750 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# INSTRUCTIONS: | |
# 1) COPY THIS FILE TO /usr/share/foreman/lib/tasks | |
# 2) Run as root via: | |
# foreman-rake katello:reindex_object | |
# This will list all the model names. To index a specific object run: | |
# $ foreman-rake katello:reindex_object MODEL=System | |
# This will reindex all System objects (Content Hosts) | |
namespace :katello do | |
desc "Regenerates the index for repositories" | |
task :reindex_object => ["environment", "katello:check_ping"] do | |
User.current = User.anonymous_admin #set a user for orchestration | |
Dir.glob(Katello::Engine.root.to_s + '/app/models/katello/*.rb').each { |file| require file } | |
puts "Param #{ENV['MODEL']}" | |
if ENV['MODEL'].nil? then | |
puts "List of Model classes to reindex, use the string after the :: in the MODEL shell env" | |
puts "to reindex a specific class, eg: " | |
puts "$ foreman-rake katello:reindex_object MODEL=System" | |
puts "" | |
Katello::Util::Search.active_record_search_classes.each do |model| | |
puts "MODEL: #{model.name}" | |
end | |
end | |
Katello::Util::Search.active_record_search_classes.each do |model| | |
# puts "MODEL: #{model.name}" | |
if model.name != "Katello::#{ENV['MODEL']}" then | |
next | |
end | |
model.index.delete | |
model.create_elasticsearch_index | |
sub_classes = model.subclasses | |
if sub_classes.empty? || !model.column_names.include?('type') | |
objects = model.all | |
else | |
objects = model.where(:type => ([nil, model.name])) | |
end | |
objects.each do |object| | |
puts "indexing: #{object}" | |
object.update_index | |
end | |
sub_classes.each do |subclass| | |
subclass.all.each do |object| | |
puts "indexing: #{object}" | |
object.update_index | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment