From 3f97f884fef9d3e4b33ae6361d7891c3c414802b Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Wed, 24 Nov 2021 19:12:49 +0200 Subject: [PATCH] DEV: Fail stop if theme update fails (#15074) This applies only when a single site exists. If a theme update fails when there are multiple sites, then it will continue updating the remaining themes. --- lib/tasks/themes.rake | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake index d997d579974..ddc3abb4e3f 100644 --- a/lib/tasks/themes.rake +++ b/lib/tasks/themes.rake @@ -52,20 +52,22 @@ task "themes:install" => :environment do |task, args| end end -def update_themes - Theme.where(auto_update: true, enabled: true).find_each do |theme| +def update_themes(fail_stop: true) + Theme.includes(:remote_theme).where(enabled: true, auto_update: true).find_each do |theme| begin - if theme.remote_theme.present? - puts "Updating '#{theme.name}' for '#{RailsMultisite::ConnectionManagement.current_db}'..." - theme.remote_theme.update_from_remote - theme.save! - unless theme.remote_theme.last_error_text.nil? - puts "Error updating '#{theme.name}': #{theme.remote_theme.last_error_text}" - end + next if theme.remote_theme.blank? + + puts "Updating '#{theme.name}' for '#{RailsMultisite::ConnectionManagement.current_db}'..." + theme.remote_theme.update_from_remote + + if theme.remote_theme.last_error_text.present? + puts "Error updating '#{theme.name}': #{theme.remote_theme.last_error_text}" + exit 1 if fail_stop end rescue => e STDERR.puts "Failed to update '#{theme.name}': #{e}" STDERR.puts e.backtrace + exit 1 if fail_stop end end end @@ -76,7 +78,7 @@ task "themes:update" => :environment do update_themes else RailsMultisite::ConnectionManagement.each_connection do - update_themes + update_themes(fail_stop: false) end end end