diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb index bfe5a63224e39ab7f9b5a344e32445e0c9a348ba..1ccfe98ba80bfe6051d04292c112dbfbd5618e55 100644 --- a/app/models/communication/website/imported/page.rb +++ b/app/models/communication/website/imported/page.rb @@ -50,7 +50,7 @@ class Communication::Website::Imported::Page < ApplicationRecord optional: true before_validation :sync - after_save :sync_attachments + after_commit :sync_attachments, on: [:create, :update] default_scope { order(:path) } @@ -84,7 +84,7 @@ class Communication::Website::Imported::Page < ApplicationRecord # Continue only if there are remote changes # Don't touch if there are local changes (page.updated_at > updated_at) # Don't touch if there are no remote changes (page.updated_at == updated_at) - # return unless updated_at > page.updated_at + return unless updated_at > page.updated_at end puts "Update page #{page.id}" sanitized_title = Wordpress.clean_string self.title.to_s @@ -97,6 +97,7 @@ class Communication::Website::Imported::Page < ApplicationRecord end def sync_attachments + return unless updated_at > page.updated_at if featured_medium.present? unless featured_medium.file.attached? && featured_medium.file.blob.persisted? featured_medium.load_remote_file! diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb index 47026e59a19708a171227756f37fe2480927e2e5..9920f80b6d6509e11e8c30bf4a87226daa57b027 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -48,7 +48,7 @@ class Communication::Website::Imported::Post < ApplicationRecord optional: true before_validation :sync - after_save :sync_attachments + after_commit :sync_attachments, on: [:create, :update] default_scope { order(path: :desc) } @@ -82,7 +82,7 @@ class Communication::Website::Imported::Post < ApplicationRecord # Continue only if there are remote changes # Don't touch if there are local changes (post.updated_at > updated_at) # Don't touch if there are no remote changes (post.updated_at == updated_at) - # return unless updated_at > post.updated_at + return unless updated_at > post.updated_at end puts "Update post #{post.id}" sanitized_title = Wordpress.clean_string self.title.to_s @@ -98,6 +98,7 @@ class Communication::Website::Imported::Post < ApplicationRecord end def sync_attachments + return unless updated_at > post.updated_at if featured_medium.present? unless featured_medium.file.attached? && featured_medium.file.blob.persisted? featured_medium.load_remote_file!