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

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

parents 7b3445e8 fa50abf5
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
class AddSlugToCommunicationWebsiteImportedPages < ActiveRecord::Migration[6.1]
def change
add_column :communication_website_imported_pages, :slug, :text
end
end
class AddDataToCommunicationWebsiteImportedPages < ActiveRecord::Migration[6.1]
def change
add_column :communication_website_imported_pages, :data, :jsonb
end
end
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
......@@ -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"
......
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