diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb index 9c989f3dbbb89d7cee33e70083ae36d4ee3b9d3f..0fd79f270dc965427f76ff0336fb093ac1df8bcb 100644 --- a/app/models/communication/website/imported/page.rb +++ b/app/models/communication/website/imported/page.rb @@ -49,6 +49,7 @@ class Communication::Website::Imported::Page < ApplicationRecord optional: true before_validation :sync + after_save :sync_attachments default_scope { order(:path) } @@ -92,8 +93,11 @@ class Communication::Website::Imported::Page < ApplicationRecord page.text = Wordpress.clean_html content.to_s page.published = true page.save + end + + def sync_attachments if featured_medium.present? - unless featured_medium.file.attached? + unless featured_medium.file.attached? && featured_medium.file.blob.persisted? featured_medium.load_remote_file! featured_medium.save end @@ -118,4 +122,5 @@ class Communication::Website::Imported::Page < ApplicationRecord end page.update(text: rich_text_with_attachments(page.text.to_s)) end + handle_asynchronously :sync_attachments, queue: 'default' end diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb index c53af2a76c8eeb4eab5016e2122654b4545ecb4d..90b9cfcff5d6d3903e81ca0a7ddf8c95599c2440 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -48,6 +48,7 @@ class Communication::Website::Imported::Post < ApplicationRecord optional: true before_validation :sync + after_save :sync_attachments default_scope { order(path: :desc) } @@ -94,8 +95,11 @@ class Communication::Website::Imported::Post < ApplicationRecord post.published_at = published_at if published_at post.published = true post.save + end + + def sync_attachments if featured_medium.present? - unless featured_medium.file.attached? + unless featured_medium.file.attached? && featured_medium.file.blob.persisted? featured_medium.load_remote_file! featured_medium.save end @@ -120,4 +124,5 @@ class Communication::Website::Imported::Post < ApplicationRecord end post.update(text: rich_text_with_attachments(post.text.to_s)) end + handle_asynchronously :sync_attachments, queue: 'default' end