diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb index 84e0b23d839ce06b58f22f744b05b28b08c37b62..ab669d4d19ff018161ee1f26358ba323e91cd7d2 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -60,7 +60,7 @@ class Communication::Website::Imported::Post < ApplicationRecord self.created_at = value['date_gmt'] self.updated_at = value['modified_gmt'] self.published_at = value['date_gmt'] - self.featured_medium = website.media.find_by(identifier: value['featured_medium']) + self.featured_medium = website.media.find_by(identifier: value['featured_media']) unless value['featured_media'] == 0 end def to_s @@ -75,11 +75,12 @@ class Communication::Website::Imported::Post < ApplicationRecord website: website.website # Real website, not imported website self.post.title = "Untitled" # No title yet self.post.save + else + # Don't touch if there are local changes (this would destroy some nice work) + # return if post.updated_at > updated_at + # Don't touch if there are no remote changes (this would do useless server workload) + # return if post.updated_at == updated_at end - # Don't touch if there are local changes (this would destroy some nice work) - # return if post.updated_at > updated_at - # Don't touch if there are no remote changes (this would do useless server workload) - # return if post.updated_at == updated_at title = Wordpress.clean title.to_s puts "Update post #{post.id}" post.title = title unless title.blank? # If there is no title, leave it with "Untitled" diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index 7f1a202b1caf713195aa8eb3c58ccc1087b5f7bc..882be65aa3ffb9e75d0242a926d1b446149b179f 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -45,7 +45,7 @@ class Communication::Website::Imported::Website < ApplicationRecord def sync_media wordpress.media.each do |data| - medium = media.where(university: university, identifier: data['id']).first_or_create + medium = media.where(university: university, identifier: data['id']).first_or_initialize medium.data = data medium.save end @@ -53,7 +53,7 @@ class Communication::Website::Imported::Website < ApplicationRecord def sync_pages wordpress.pages.each do |data| - page = pages.where(university: university, identifier: data['id']).first_or_create + page = pages.where(university: university, identifier: data['id']).first_or_initialize page.data = data page.save end @@ -70,7 +70,7 @@ class Communication::Website::Imported::Website < ApplicationRecord def sync_posts wordpress.posts.each do |data| - post = posts.where(university: university, identifier: data['id']).first_or_create + post = posts.where(university: university, identifier: data['id']).first_or_initialize post.data = data post.save end diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index 059f700376a0b0bcdc6c4d52522b6844d1801d27..4ec8f8748672906191b67a6f99e0ce9dd31f6287 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -22,6 +22,9 @@ namespace :app do Communication::Website::Post.find_each { |post| post.update(text: post.old_text) } + Communication::Website::Medium.find_each { |medium| + medium.send(:set_featured_images) + } end namespace :db do