Skip to content

Commit

Permalink
Fixes issue #3276 - Software error when Elasticsearch is not configur…
Browse files Browse the repository at this point in the history
…ed and `rake searchindex:rebuild`
  • Loading branch information
zammad-sync authored and thorsteneckel committed Nov 10, 2020
1 parent bf573b4 commit cd763cc
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/tasks/search_index_es.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $LOAD_PATH << './lib'
require 'rubygems'

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...'

# drop indexes
Expand All @@ -23,7 +23,7 @@ namespace :searchindex do
Rake::Task['searchindex:drop_pipeline'].execute
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...'

if es_multi_index?
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace :searchindex do
Rake::Task['searchindex:create_pipeline'].execute
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?
Setting.set('es_pipeline', '')
next
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace :searchindex do
puts 'done'
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?

# update processors
Expand All @@ -153,8 +153,7 @@ namespace :searchindex do
puts 'done'
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...'
Models.indexable.each do |model_class|
puts " reload #{model_class}"
Expand All @@ -167,13 +166,13 @@ namespace :searchindex do

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...'

SearchIndexBackend.refresh
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:create'].execute
Rake::Task['searchindex:reload'].execute
Expand All @@ -182,7 +181,13 @@ namespace :searchindex do
task :version_supported, [:opts] => :environment do |_t, _args|
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

Expand Down Expand Up @@ -371,3 +376,10 @@ def es_type_in_mapping?

false
end

# is es configured?
def es_configured?
return false if Setting.get('es_url').blank?

true
end

0 comments on commit cd763cc

Please sign in to comment.