2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-16 07:20:48 +08:00
|
|
|
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 == ""
|
2018-03-24 04:55:17 +08:00
|
|
|
puts
|
2018-02-16 07:20:48 +08:00
|
|
|
puts "Please specify a settings yml file"
|
|
|
|
puts "Example: rake site_settings:import < settings.yml"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2018-03-24 04:55:17 +08:00
|
|
|
puts
|
2018-02-16 07:20:48 +08:00
|
|
|
puts "starting import..."
|
2018-03-24 04:55:17 +08:00
|
|
|
puts
|
2018-02-16 07:20:48 +08:00
|
|
|
|
2018-03-24 04:55:17 +08:00
|
|
|
log, counts = SiteSettingsTask.import(yml)
|
2018-02-16 07:20:48 +08:00
|
|
|
|
2018-03-24 04:55:17 +08:00
|
|
|
puts log
|
|
|
|
|
|
|
|
puts
|
2018-02-16 07:20:48 +08:00
|
|
|
puts "Results:"
|
|
|
|
puts " Updated: #{counts[:updated]}"
|
|
|
|
puts " Not Found: #{counts[:not_found]}"
|
|
|
|
puts " Errors: #{counts[:errors]}"
|
2018-10-11 15:57:57 +08:00
|
|
|
|
|
|
|
exit 1 if counts[:not_found] + counts[:errors] > 0
|
2018-02-16 07:20:48 +08:00
|
|
|
end
|
2023-08-29 23:42:52 +08:00
|
|
|
|
|
|
|
# Outputs a list of Site Settings that may no longer be in use
|
|
|
|
desc "Find dead site settings"
|
|
|
|
task "site_settings:find_dead" => :environment do
|
|
|
|
setting_names = SiteSettingsTask.names
|
|
|
|
|
|
|
|
setting_names.each do |n|
|
|
|
|
if !SiteSetting.respond_to?(n)
|
|
|
|
# Likely won't hit here, but just in case
|
|
|
|
puts "Setting #{n} does not exist."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
directories = SiteSettingsTask.directories
|
|
|
|
dead_settings = []
|
|
|
|
|
|
|
|
if !SiteSettingsTask.rg_installed?
|
|
|
|
puts "Please install ripgrep to use this command"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if !ENV["ALL_THE_PARENT_DIR"]
|
|
|
|
puts "To specify a custom parent directory for all-the-themes & all-the-plugins"
|
|
|
|
puts "use the ALL_THE_PARENT_DIR ENV var."
|
|
|
|
end
|
|
|
|
puts "Checking #{setting_names.count} settings in these directories:"
|
|
|
|
puts directories
|
|
|
|
puts
|
|
|
|
|
|
|
|
setting_names.each do |setting_name|
|
|
|
|
count = SiteSettingsTask.rg_search_count("SiteSetting.#{setting_name}", directories.first)
|
|
|
|
count =
|
|
|
|
SiteSettingsTask.rg_search_count(
|
|
|
|
"siteSettings.#{setting_name}",
|
|
|
|
directories.first,
|
|
|
|
) if count.zero?
|
|
|
|
directories.each do |directory|
|
|
|
|
count = SiteSettingsTask.rg_search_count(setting_name, directory) if count.zero?
|
|
|
|
end
|
|
|
|
if count.zero?
|
|
|
|
print setting_name
|
|
|
|
dead_settings << setting_name
|
|
|
|
else
|
|
|
|
print "."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
|
|
|
|
if dead_settings.count > 0
|
|
|
|
puts "These settings may be unused:"
|
|
|
|
puts dead_settings
|
|
|
|
else
|
|
|
|
puts "No dead settings found."
|
|
|
|
end
|
|
|
|
end
|