Fixes issue #3276 - Software error when Elasticsearch is not configured and rake searchindex:rebuild
This commit is contained in:
parent
8e7abc45fb
commit
d7ba83681e
1 changed files with 21 additions and 9 deletions
|
@ -2,7 +2,7 @@ $LOAD_PATH << './lib'
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
||||||
namespace :searchindex do
|
namespace :searchindex do
|
||||||
task :drop, [:opts] => %i[environment searchindex:version_supported] do |_t, _args|
|
task :drop, [:opts] => %i[environment searchindex:configured searchindex:version_supported] do |_t, _args|
|
||||||
print 'drop indexes...'
|
print 'drop indexes...'
|
||||||
|
|
||||||
# drop indexes
|
# drop indexes
|
||||||
|
@ -23,7 +23,7 @@ namespace :searchindex do
|
||||||
Rake::Task['searchindex:drop_pipeline'].execute
|
Rake::Task['searchindex:drop_pipeline'].execute
|
||||||
end
|
end
|
||||||
|
|
||||||
task :create, [:opts] => %i[environment searchindex:version_supported] do |_t, _args|
|
task :create, [:opts] => %i[environment searchindex:configured searchindex:version_supported] do |_t, _args|
|
||||||
print 'create indexes...'
|
print 'create indexes...'
|
||||||
|
|
||||||
if es_multi_index?
|
if es_multi_index?
|
||||||
|
@ -67,7 +67,7 @@ namespace :searchindex do
|
||||||
Rake::Task['searchindex:create_pipeline'].execute
|
Rake::Task['searchindex:create_pipeline'].execute
|
||||||
end
|
end
|
||||||
|
|
||||||
task :create_pipeline, [:opts] => %i[environment searchindex:version_supported] do |_t, _args|
|
task :create_pipeline, [:opts] => %i[environment searchindex:configured searchindex:version_supported] do |_t, _args|
|
||||||
if !es_pipeline?
|
if !es_pipeline?
|
||||||
Setting.set('es_pipeline', '')
|
Setting.set('es_pipeline', '')
|
||||||
next
|
next
|
||||||
|
@ -135,7 +135,7 @@ namespace :searchindex do
|
||||||
puts 'done'
|
puts 'done'
|
||||||
end
|
end
|
||||||
|
|
||||||
task :drop_pipeline, [:opts] => %i[environment searchindex:version_supported] do |_t, _args|
|
task :drop_pipeline, [:opts] => %i[environment searchindex:configured searchindex:version_supported] do |_t, _args|
|
||||||
next if !es_pipeline?
|
next if !es_pipeline?
|
||||||
|
|
||||||
# update processors
|
# update processors
|
||||||
|
@ -153,8 +153,7 @@ namespace :searchindex do
|
||||||
puts 'done'
|
puts 'done'
|
||||||
end
|
end
|
||||||
|
|
||||||
task :reload, [:opts] => %i[environment searchindex:version_supported] do |_t, _args|
|
task :reload, [:opts] => %i[environment searchindex:configured searchindex:version_supported] do |_t, _args|
|
||||||
|
|
||||||
puts 'reload data...'
|
puts 'reload data...'
|
||||||
Models.indexable.each do |model_class|
|
Models.indexable.each do |model_class|
|
||||||
puts " reload #{model_class}"
|
puts " reload #{model_class}"
|
||||||
|
@ -167,13 +166,13 @@ namespace :searchindex do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
task :refresh, [:opts] => %i[environment searchindex:version_supported] do |_t, _args|
|
task :refresh, [:opts] => %i[environment searchindex:configured searchindex:version_supported] do |_t, _args|
|
||||||
print 'refresh all indexes...'
|
print 'refresh all indexes...'
|
||||||
|
|
||||||
SearchIndexBackend.refresh
|
SearchIndexBackend.refresh
|
||||||
end
|
end
|
||||||
|
|
||||||
task :rebuild, [:opts] => %i[environment searchindex:version_supported] do |_t, _args|
|
task :rebuild, [:opts] => %i[environment searchindex:configured searchindex:version_supported] do |_t, _args|
|
||||||
Rake::Task['searchindex:drop'].execute
|
Rake::Task['searchindex:drop'].execute
|
||||||
Rake::Task['searchindex:create'].execute
|
Rake::Task['searchindex:create'].execute
|
||||||
Rake::Task['searchindex:reload'].execute
|
Rake::Task['searchindex:reload'].execute
|
||||||
|
@ -182,7 +181,13 @@ namespace :searchindex do
|
||||||
task :version_supported, [:opts] => :environment do |_t, _args|
|
task :version_supported, [:opts] => :environment do |_t, _args|
|
||||||
next if es_version_supported?
|
next if es_version_supported?
|
||||||
|
|
||||||
abort "Your elastic search version is not supported! Please update your version to a greater equal than 5.6.0 (Your current version: #{es_version})."
|
abort "Your Elasticsearch version is not supported! Please update your version to a greater equal than 5.6.0 (Your current version: #{es_version})."
|
||||||
|
end
|
||||||
|
|
||||||
|
task :configured, [:opts] => :environment do |_t, _args|
|
||||||
|
next if es_configured?
|
||||||
|
|
||||||
|
abort "You have not configured Elasticsearch (Setting.get('es_url'))."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -371,3 +376,10 @@ def es_type_in_mapping?
|
||||||
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# is es configured?
|
||||||
|
def es_configured?
|
||||||
|
return false if Setting.get('es_url').blank?
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue