discourse/lib/tasks/site_settings.rake
Chris Butler ddbed82bca Exit with an error if there are errors with settings import (#6475)
If the site_settings import has any errors or settings that are not found, this
will cause the task to exit with a non-zero exit code.

This is useful when using this task as part of automated configuration deployment,
where you may not want to continue with the process if a setting fails to
import.
2018-10-11 15:57:57 +08:00

37 lines
734 B
Ruby

require 'yaml'
desc "Exports site settings"
task "site_settings:export" => :environment do
h = SiteSettingsTask.export_to_hash
puts h.to_yaml
end
desc "Imports site settings"
task "site_settings:import" => :environment do
yml = (STDIN.tty?) ? '' : STDIN.read
if yml == ''
puts
puts "Please specify a settings yml file"
puts "Example: rake site_settings:import < settings.yml"
exit 1
end
puts
puts "starting import..."
puts
log, counts = SiteSettingsTask.import(yml)
puts log
puts
puts "Results:"
puts " Updated: #{counts[:updated]}"
puts " Not Found: #{counts[:not_found]}"
puts " Errors: #{counts[:errors]}"
if counts[:not_found] + counts[:errors] > 0
exit 1
end
end