diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb index 59809819e2be8bf2b489489c0b953c56a0ebbec0..505c2941d1d584955767c03b2d2753288fd4e288 100644 --- a/app/models/communication/website/imported/page.rb +++ b/app/models/communication/website/imported/page.rb @@ -4,6 +4,9 @@ # # id :uuid not null, primary key # content :text +# excerpt :text +# identifier :string +# parent :string # path :text # status :integer default(0) # title :string @@ -54,8 +57,7 @@ class Communication::Website::Imported::Page < ApplicationRecord end # TODO only if not modified since import page.title = Wordpress.clean title.to_s - # TODO add that - # page.description = description.to_s + post.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 154ba20e454780993dc260d18c6461aa653d1b99..c25336199ec2a1c99782ce3b7f8385e2e9268869 100644 --- a/app/models/communication/website/imported/post.rb +++ b/app/models/communication/website/imported/post.rb @@ -4,7 +4,7 @@ # # id :uuid not null, primary key # content :text -# description :text +# excerpt :text # identifier :string # path :text # published_at :datetime @@ -56,7 +56,7 @@ class Communication::Website::Imported::Post < ApplicationRecord end # TODO only if not modified since import post.title = Wordpress.clean title.to_s - post.description = Wordpress.clean description.to_s + post.description = Wordpress.clean excerpt.to_s post.text = Wordpress.clean content.to_s post.published_at = published_at if published_at post.save diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index e6330c1fe766a888205d3d9cf7eeddd25274ec0f..7e95f1e71c0ddfaeb4701aec4c90d21d9818c9d5 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -40,14 +40,13 @@ class Communication::Website::Imported::Website < ApplicationRecord end def sync_pages - wordpress.pages.each do |hash| - url = hash['link'] - path = URI(url).path - # TODO id - page = pages.where(university: university, path: path).first_or_create - page.url = url + 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'] page.save end end @@ -59,8 +58,7 @@ class Communication::Website::Imported::Website < ApplicationRecord post.url = hash['link'] post.path = URI(post.url).path post.title = hash['title']['rendered'] - # TODO excerpt - post.description = hash['content']['excerpt'] + post.excerpt = hash['excerpt']['rendered'] post.content = hash['content']['rendered'] post.published_at = hash['date'] post.save 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/20211018154020_add_identifier_to_communication_website_imported_page.rb b/db/migrate/20211018154020_add_identifier_to_communication_website_imported_page.rb new file mode 100644 index 0000000000000000000000000000000000000000..98813a817c735240f719807d5296af6abe76a5e4 --- /dev/null +++ b/db/migrate/20211018154020_add_identifier_to_communication_website_imported_page.rb @@ -0,0 +1,6 @@ +class AddIdentifierToCommunicationWebsiteImportedPage < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_imported_pages, :identifier, :string + add_column :communication_website_imported_pages, :excerpt, :text + end +end diff --git a/db/migrate/20211018154502_rename_description_to_excerpt.rb b/db/migrate/20211018154502_rename_description_to_excerpt.rb new file mode 100644 index 0000000000000000000000000000000000000000..171d77a15a86fbd8d1f5197e36123b05fb356c5c --- /dev/null +++ b/db/migrate/20211018154502_rename_description_to_excerpt.rb @@ -0,0 +1,5 @@ +class RenameDescriptionToExcerpt < ActiveRecord::Migration[6.1] + def change + rename_column :communication_website_imported_posts, :description, :excerpt + end +end diff --git a/db/migrate/20211018154621_add_parent_id_to_communication_website_imported_pages.rb b/db/migrate/20211018154621_add_parent_id_to_communication_website_imported_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..7c77fc59f00fc82baff234bf79c75bbacabadace --- /dev/null +++ b/db/migrate/20211018154621_add_parent_id_to_communication_website_imported_pages.rb @@ -0,0 +1,5 @@ +class AddParentIdToCommunicationWebsiteImportedPages < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_imported_pages, :parent, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 1f77195c1707a9db98616fdc9183015813e2a96b..316f559fda977a54147ccf0054084dfd59e92308 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_08_152623) do +ActiveRecord::Schema.define(version: 2021_10_18_154621) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -79,6 +79,9 @@ ActiveRecord::Schema.define(version: 2021_10_08_152623) do t.text "content" t.text "path" t.text "url" + t.string "identifier" + t.text "excerpt" + t.string "parent" 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" @@ -90,7 +93,7 @@ ActiveRecord::Schema.define(version: 2021_10_08_152623) do t.uuid "post_id", null: false t.integer "status", default: 0 t.string "title" - t.text "description" + t.text "excerpt" t.text "content" t.text "path" t.text "url" @@ -213,7 +216,7 @@ ActiveRecord::Schema.define(version: 2021_10_08_152623) 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"