FIX: clear theme cache when restoring

FIX: clear theme cache when restoring

Previously old themes may be cached incorrectly, this also forces
a rebake of old themes to ensure version can compile cleanly

From 1b4f2029d7735cf18810f6843cb98e7dc28f321b Mon Sep 17 00:00:00 2001
From: Sam <sam.saffron@gmail.com>
Date: Tue, 20 Nov 2018 13:37:58 +1100
Subject: [PATCH] FIX: clear theme cache when restoring

Previously old themes may be cached incorrectly, this also forces
a rebake of old themes to ensure version can compile cleanly

diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb
index 62cfd24..b09e605 100644
--- a/lib/backup_restore/restorer.rb
+++ b/lib/backup_restore/restorer.rb
@@ -59,39 +59,27 @@ module BackupRestore
       if !can_restore_into_different_schema?
         log "Cannot restore into different schema, restoring in-place"
         enable_readonly_mode
-
         pause_sidekiq
         wait_for_sidekiq
-
         BackupRestore.move_tables_between_schemas("public", "backup")
-
         @db_was_changed = true
         restore_dump
-        migrate_database
-        reconnect_database
-
-        reload_site_settings
-        clear_emoji_cache
-
-        disable_readonly_mode
       else
         log "Restoring into 'backup' schema"
         restore_dump
         enable_readonly_mode
-
         pause_sidekiq
         wait_for_sidekiq
-
         switch_schema!
-
-        migrate_database
-        reconnect_database
-        reload_site_settings
-        clear_emoji_cache
-
-        disable_readonly_mode
       end
 
+      migrate_database
+      reconnect_database
+      reload_site_settings
+      clear_emoji_cache
+      disable_readonly_mode
+      clear_theme_cache
+
       extract_uploads
     rescue SystemExit
       log "Restore process was cancelled!"
@@ -489,6 +477,15 @@ module BackupRestore
       log "Something went wrong while unpausing Sidekiq.", ex
     end
 
+    def clear_theme_cache
+      log "Clear theme cache"
+      ThemeField.all.each do |field|
+        field.compiler_version = 0
+        field.ensure_baked!
+      end
+      Theme.expire_site_cache!
+    end
+
     def disable_readonly_mode
       return if @readonly_mode_was_enabled
       log "Disabling readonly mode..."

GitHub

1 Like