diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb index 505c2941d1d584955767c03b2d2753288fd4e288..00d49f2d74abbda0eba34de1431b539e77259b1f 100644 --- a/app/models/communication/website/imported/page.rb +++ b/app/models/communication/website/imported/page.rb @@ -4,10 +4,12 @@ # # id :uuid not null, primary key # content :text +# data :jsonb # excerpt :text # identifier :string # parent :string # path :text +# slug :text # status :integer default(0) # title :string # url :text @@ -41,6 +43,16 @@ class Communication::Website::Imported::Page < ApplicationRecord default_scope { order(:path) } + def data=(value) + super value + self.url = value['link'] + self.slug = value['slug'] + self.title = value['title']['rendered'] + self.excerpt = value['excerpt']['rendered'] + self.content = value['content']['rendered'] + self.parent = value['parent'] + end + def to_s "#{title}" end @@ -49,15 +61,15 @@ class Communication::Website::Imported::Page < ApplicationRecord def sync if page.nil? - self.page = Communication::Website::Page.new university: university, - website: website.website, # Real website, not imported website - slug: path + self.page = Communication::Website::Page.new university: university, + website: website.website, # Real website, not imported website + slug: path self.page.title = "TMP" self.page.save end # TODO only if not modified since import page.title = Wordpress.clean title.to_s - post.description = Wordpress.clean excerpt.to_s + page.description = Wordpress.clean excerpt.to_s page.text = Wordpress.clean content.to_s page.save end diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb index c25336199ec2a1c99782ce3b7f8385e2e9268869..ba052620a21290e6568475a2cd50003d61b906c2 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -4,10 +4,12 @@ # # id :uuid not null, primary key # content :text +# data :jsonb # excerpt :text # identifier :string # path :text # published_at :datetime +# slug :text # status :integer default(0) # title :string # url :text @@ -41,6 +43,17 @@ class Communication::Website::Imported::Post < ApplicationRecord default_scope { order(path: :desc) } + def data=(value) + super value + self.url = value['link'] + self.slug = value['slug'] + self.path = URI(self.url).path + self.title = value['title']['rendered'] + self.excerpt = value['excerpt']['rendered'] + self.content = value['content']['rendered'] + self.published_at = value['date'] + end + def to_s "#{title}" end diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index 7e95f1e71c0ddfaeb4701aec4c90d21d9818c9d5..962cd135a4f5e3cb5b39f0ef18a1c1c8ce857208 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -29,8 +29,8 @@ class Communication::Website::Imported::Website < ApplicationRecord class_name: 'Communication::Website::Imported::Post' def run! - sync_posts sync_pages + sync_posts end protected @@ -40,27 +40,18 @@ class Communication::Website::Imported::Website < ApplicationRecord end def sync_pages - wordpress.pages.find_each do |hash| - page = pages.where(university: university, identifier: hash['id']).first_or_create - page.url = hash['link'] - page.title = hash['title']['rendered'] - page.excerpt = hash['excerpt']['rendered'] - page.content = hash['content']['rendered'] - page.parent = hash['parent'] + wordpress.pages.each do |data| + page = pages.where(university: university, identifier: data['id']).first_or_create + page.data = data page.save end + # TODO parents end def sync_posts - wordpress.posts.each do |hash| - identifier = hash['id'] - post = posts.where(university: university, identifier: identifier).first_or_create - post.url = hash['link'] - post.path = URI(post.url).path - post.title = hash['title']['rendered'] - post.excerpt = hash['excerpt']['rendered'] - post.content = hash['content']['rendered'] - post.published_at = hash['date'] + wordpress.posts.each do |data| + post = posts.where(university: university, identifier: data['id']).first_or_create + post.data = data post.save end end diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index 0410c664d3b6e9859bf11e853a325e9043904631..20a415c655deaf08befa1c4a77cf15c2faa94b1f 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -10,7 +10,7 @@ # text :text # title :string # created_at :datetime not null -# updated_at :datetime not null +# updated_at :date not null # research_journal_id :uuid not null # research_journal_volume_id :uuid # university_id :uuid not null diff --git a/db/migrate/20211019090915_add_slug_to_communication_website_imported_pages.rb b/db/migrate/20211019090915_add_slug_to_communication_website_imported_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..20f52c28268ddb5ef70ec0ddfe1c8069561a48a7 --- /dev/null +++ b/db/migrate/20211019090915_add_slug_to_communication_website_imported_pages.rb @@ -0,0 +1,5 @@ +class AddSlugToCommunicationWebsiteImportedPages < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_imported_pages, :slug, :text + end +end diff --git a/db/migrate/20211019091225_add_data_to_communication_website_imported_pages.rb b/db/migrate/20211019091225_add_data_to_communication_website_imported_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..c9ee2444b8e704d308127d68da8ec39ee04e9c68 --- /dev/null +++ b/db/migrate/20211019091225_add_data_to_communication_website_imported_pages.rb @@ -0,0 +1,5 @@ +class AddDataToCommunicationWebsiteImportedPages < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_imported_pages, :data, :jsonb + end +end diff --git a/db/migrate/20211019092503_add_slug_and_data_to_communication_website_imported_posts.rb b/db/migrate/20211019092503_add_slug_and_data_to_communication_website_imported_posts.rb new file mode 100644 index 0000000000000000000000000000000000000000..3bcf70533b914ef9e1749db8bad47ee16655d9cd --- /dev/null +++ b/db/migrate/20211019092503_add_slug_and_data_to_communication_website_imported_posts.rb @@ -0,0 +1,6 @@ +class AddSlugAndDataToCommunicationWebsiteImportedPosts < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_imported_posts, :slug, :text + add_column :communication_website_imported_posts, :data, :jsonb + end +end diff --git a/db/schema.rb b/db/schema.rb index 3c98d4348b4a09828e1b0c378a8f273beed8c336..683a249f59f00cafadae14bb6a5d1fedb82aafaa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_19_083328) do +ActiveRecord::Schema.define(version: 2021_10_19_092503) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -82,6 +82,8 @@ ActiveRecord::Schema.define(version: 2021_10_19_083328) do t.string "identifier" t.text "excerpt" t.string "parent" + t.text "slug" + t.jsonb "data" t.index ["page_id"], name: "index_communication_website_imported_pages_on_page_id" t.index ["university_id"], name: "index_communication_website_imported_pages_on_university_id" t.index ["website_id"], name: "index_communication_website_imported_pages_on_website_id" @@ -101,6 +103,8 @@ ActiveRecord::Schema.define(version: 2021_10_19_083328) do t.string "identifier" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.text "slug" + t.jsonb "data" t.index ["post_id"], name: "index_communication_website_imported_posts_on_post_id" t.index ["university_id"], name: "index_communication_website_imported_posts_on_university_id" t.index ["website_id"], name: "index_communication_website_imported_posts_on_website_id" @@ -216,7 +220,7 @@ ActiveRecord::Schema.define(version: 2021_10_19_083328) do t.uuid "research_journal_id", null: false t.uuid "research_journal_volume_id" t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.date "updated_at", null: false t.uuid "updated_by_id" t.text "abstract" t.text "references"