Skip to content
Snippets Groups Projects
Commit ef318152 authored by pabois's avatar pabois
Browse files

Merge branch 'master' of github.com:noesya/osuny

parents b9f1a496 b7559f28
No related branches found
No related tags found
No related merge requests found
...@@ -44,13 +44,13 @@ class Communication::Website::Imported::Page < ApplicationRecord ...@@ -44,13 +44,13 @@ class Communication::Website::Imported::Page < ApplicationRecord
belongs_to :page, belongs_to :page,
class_name: 'Communication::Website::Page', class_name: 'Communication::Website::Page',
optional: true optional: true
alias_attribute :generated_object, :category alias_attribute :generated_object, :page
belongs_to :featured_medium, belongs_to :featured_medium,
class_name: 'Communication::Website::Imported::Medium', class_name: 'Communication::Website::Imported::Medium',
optional: true optional: true
before_validation :sync before_validation :sync
after_save :sync_attachments after_commit :sync_attachments, on: [:create, :update]
default_scope { order(:path) } default_scope { order(:path) }
...@@ -84,7 +84,7 @@ class Communication::Website::Imported::Page < ApplicationRecord ...@@ -84,7 +84,7 @@ class Communication::Website::Imported::Page < ApplicationRecord
# Continue only if there are remote changes # 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 local changes (page.updated_at > updated_at)
# Don't touch if there are no remote 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 end
puts "Update page #{page.id}" puts "Update page #{page.id}"
sanitized_title = Wordpress.clean_string self.title.to_s sanitized_title = Wordpress.clean_string self.title.to_s
...@@ -97,6 +97,7 @@ class Communication::Website::Imported::Page < ApplicationRecord ...@@ -97,6 +97,7 @@ class Communication::Website::Imported::Page < ApplicationRecord
end end
def sync_attachments def sync_attachments
return unless updated_at > page.updated_at
if featured_medium.present? if featured_medium.present?
unless featured_medium.file.attached? && featured_medium.file.blob.persisted? unless featured_medium.file.attached? && featured_medium.file.blob.persisted?
featured_medium.load_remote_file! featured_medium.load_remote_file!
......
...@@ -48,7 +48,7 @@ class Communication::Website::Imported::Post < ApplicationRecord ...@@ -48,7 +48,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
optional: true optional: true
before_validation :sync before_validation :sync
after_save :sync_attachments after_commit :sync_attachments, on: [:create, :update]
default_scope { order(path: :desc) } default_scope { order(path: :desc) }
...@@ -82,7 +82,7 @@ class Communication::Website::Imported::Post < ApplicationRecord ...@@ -82,7 +82,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
# Continue only if there are remote changes # 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 local changes (post.updated_at > updated_at)
# Don't touch if there are no remote 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 end
puts "Update post #{post.id}" puts "Update post #{post.id}"
sanitized_title = Wordpress.clean_string self.title.to_s sanitized_title = Wordpress.clean_string self.title.to_s
...@@ -98,6 +98,7 @@ class Communication::Website::Imported::Post < ApplicationRecord ...@@ -98,6 +98,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
end end
def sync_attachments def sync_attachments
return unless updated_at > post.updated_at
if featured_medium.present? if featured_medium.present?
unless featured_medium.file.attached? && featured_medium.file.blob.persisted? unless featured_medium.file.attached? && featured_medium.file.blob.persisted?
featured_medium.load_remote_file! featured_medium.load_remote_file!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment