mirror of
https://github.com/discourse/discourse.git
synced 2026-08-01 09:08:08 -05:00
FIX: Handle missing sketch logo during backup restore (#36541)
When restoring an empty backup, 'SiteIconManager.ensure_optimized!' is triggered during 'reload_site_settings', before 'run_seed_fu' has created the sketch logo upload (ID -6). This causes 'ActiveRecord::RecordNotFound'. Use 'find_by' instead of 'find' to gracefully return 'nil' when the sketch logo doesn't exist yet. Internal ref - t/8308
This commit is contained in:
@@ -123,7 +123,7 @@ module SiteIconManager
|
||||
value = SiteSetting.get(setting_name)
|
||||
return value if value
|
||||
end
|
||||
return Upload.find(SKETCH_LOGO_ID) if info[:fallback_to_sketch]
|
||||
return Upload.find_by(id: SKETCH_LOGO_ID) if info[:fallback_to_sketch]
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,21 @@ RSpec.describe SiteIconManager do
|
||||
# Falls back to sketch for some icons
|
||||
expect(SiteIconManager.favicon.upload_id).to eq(SiteIconManager::SKETCH_LOGO_ID)
|
||||
expect(SiteIconManager.mobile_logo).to eq(nil)
|
||||
end
|
||||
|
||||
it "handles missing sketch logo gracefully" do
|
||||
SiteSetting.logo = ""
|
||||
SiteSetting.logo_small = ""
|
||||
|
||||
Upload.find_by(id: SiteIconManager::SKETCH_LOGO_ID)&.destroy
|
||||
|
||||
expect(SiteIconManager.favicon).to eq(nil)
|
||||
expect(SiteIconManager.large_icon).to eq(nil)
|
||||
expect(SiteIconManager.mobile_logo).to eq(nil)
|
||||
expect(SiteIconManager.opengraph_image).to eq(nil)
|
||||
end
|
||||
|
||||
it "resizes icons correctly" do
|
||||
SiteSetting.logo_small = upload
|
||||
|
||||
# Always resizes to 512x512
|
||||
|
||||
Reference in New Issue
Block a user