FIX: Make themes:update work with multisites (#14082)

FIX: Make themes:update work with multisites (#14082)

Running this Rake task in a multisite cluster updated only the default site.

diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake
index 51746bd..1e2fdfa 100644
--- a/lib/tasks/themes.rake
+++ b/lib/tasks/themes.rake
@@ -52,21 +52,20 @@ task "themes:install" => :environment do |task, args|
   end
 end
 
-desc "Update themes & theme components"
-task "themes:update" => :environment do |task, args|
+def update_themes
   Theme.where(auto_update: true, enabled: true).find_each do |theme|
     begin
       if theme.remote_theme.present?
-        puts "Updating #{theme.name}..."
+        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}"
+          puts "Error updating '#{theme.name}': #{theme.remote_theme.last_error_text}"
           exit 1
         end
       end
     rescue => e
-      STDERR.puts "Failed to update #{theme.name}"
+      STDERR.puts "Failed to update '#{theme.name}'"
       STDERR.puts e
       STDERR.puts e.backtrace
       exit 1
@@ -74,6 +73,17 @@ task "themes:update" => :environment do |task, args|
   end
 end
 
+desc "Update themes & theme components"
+task "themes:update" => :environment do
+  if ENV['RAILS_DB'].present?
+    update_themes
+  else
+    RailsMultisite::ConnectionManagement.each_connection do
+      update_themes
+    end
+  end
+end
+
 desc "List all the installed themes on the site"
 task "themes:audit" => :environment do
   components = Set.new

GitHub sha: c0ec1e931e4c78502053963d95062d313d69cb2a

This commit appears in #14082 which was approved by CvX. It was merged by udan11.