Skip to content
Snippets Groups Projects
Unverified Commit d4751d72 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

fix seed & import wordpress

parent fd156e11
No related branches found
No related tags found
No related merge requests found
......@@ -54,7 +54,7 @@ class Communication::Website::Imported::Author < ApplicationRecord
def sync
if author.nil?
self.author = University::Person.new university: university
self.author = University::Person.new university: university, language: university.default_language
self.author.last_name = "Doe" # No title yet
self.author.first_name = "John" # No title yet
self.author.save
......
......@@ -59,8 +59,9 @@ class Communication::Website::Imported::Category < ApplicationRecord
def sync
if category.nil?
self.category = Communication::Website::Category.new university: university,
website: website.website # Real website, not imported website
self.category = Communication::Website::Category.new university: university,
website: website.website, # Real website, not imported website
language: website.website.default_language
self.category.name = "Untitled" # No title yet
self.category.save
end
......
......@@ -76,6 +76,8 @@ class Communication::Website::Imported::Page < ApplicationRecord
if page.nil?
self.page = Communication::Website::Page.new university: university,
website: website.website, # Real website, not imported website
language: website.website.default_language,
parent: website.website.special_page(Communication::Website::Page::Home),
slug: path
self.page.title = "Untitled"
self.page.save
......@@ -90,13 +92,21 @@ class Communication::Website::Imported::Page < ApplicationRecord
page.title = sanitized_title unless sanitized_title.blank? # If there is no title, leave it with "Untitled"
page.slug = slug
page.meta_description = Wordpress.clean_string excerpt.to_s
page.text = Wordpress.clean_html content.to_s
page.published = true
page.save
chapter = page.blocks.where(university: website.university, template_kind: :chapter).first_or_create
chapter_data = chapter.data.deep_dup
chapter_data['text'] = Wordpress.clean_html(content.to_s)
chapter.data = chapter_data
chapter.save
end
def sync_attachments
return unless ENV['APPLICATION_ENV'] == 'development' || updated_at > page.updated_at
chapter = page.blocks.where(university: website.university, template_kind: :chapter).first_or_create
chapter_data = chapter.data.deep_dup
if featured_medium.present?
unless featured_medium.file.attached?
featured_medium.load_remote_file!
......@@ -108,7 +118,7 @@ class Communication::Website::Imported::Page < ApplicationRecord
content_type: featured_medium.file.blob.content_type
)
else
fragment = Nokogiri::HTML.fragment(page.text.to_s)
fragment = Nokogiri::HTML.fragment(chapter_data['text'].to_s)
image = fragment.css('img').first
if image.present?
begin
......@@ -116,11 +126,12 @@ class Communication::Website::Imported::Page < ApplicationRecord
download_service = DownloadService.download(url)
page.featured_image.attach(download_service.attachable_data)
image.remove
page.update(text: fragment.to_html)
chapter_data['text'] = fragment.to_html
chapter.data = chapter_data
chapter.save
rescue
end
end
end
page.update(text: page.text.to_s)
end
end
......@@ -78,7 +78,8 @@ class Communication::Website::Imported::Post < ApplicationRecord
def sync
if post.nil?
self.post = Communication::Website::Post.new university: university,
website: website.website # Real website, not imported website
website: website.website, # Real website, not imported website
language: website.website.default_language
self.post.title = "Untitled" # No title yet
self.post.save
else
......@@ -93,7 +94,6 @@ class Communication::Website::Imported::Post < ApplicationRecord
post.title = sanitized_title unless sanitized_title.blank? # If there is no title, leave it with "Untitled"
post.slug = slug
post.meta_description = Wordpress.clean_string excerpt.to_s
post.text = Wordpress.clean_html content.to_s
post.created_at = created_at
post.updated_at = updated_at
post.published_at = published_at if published_at
......@@ -106,10 +106,19 @@ class Communication::Website::Imported::Post < ApplicationRecord
post.categories << imported_category.category unless post.categories.pluck(:id).include?(imported_category.category_id)
end
post.save
chapter = post.blocks.where(university: website.university, template_kind: :chapter).first_or_create
chapter_data = chapter.data.deep_dup
chapter_data['text'] = Wordpress.clean_html(content.to_s)
chapter.data = chapter_data
chapter.save
end
def sync_attachments
return unless ENV['APPLICATION_ENV'] == 'development' || updated_at > post.updated_at
chapter = post.blocks.where(university: website.university, template_kind: :chapter).first_or_create
chapter_data = chapter.data.deep_dup
if featured_medium.present?
unless featured_medium.file.attached?
featured_medium.load_remote_file!
......@@ -121,7 +130,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
content_type: featured_medium.file.blob.content_type
)
else
fragment = Nokogiri::HTML.fragment(post.text.body.to_html)
fragment = Nokogiri::HTML.fragment(chapter_data['text'].to_s)
image = fragment.css('img').first
if image.present?
begin
......@@ -129,11 +138,12 @@ class Communication::Website::Imported::Post < ApplicationRecord
download_service = DownloadService.download(url)
post.featured_image.attach(download_service.attachable_data)
image.remove
post.update(text: fragment.to_html)
chapter_data['text'] = fragment.to_html
chapter.data = chapter_data
chapter.save
rescue
end
end
end
post.update(text: post.text.body.to_html)
end
end
......@@ -8,10 +8,7 @@ module Communication::Website::WithImport
end
def import!
imported_website = Communication::Website::Imported::Website.where(
website: self, university: university
).first_or_create unless imported?
create_imported_website(university: university) unless imported?
imported_website.run!
reload
end
......
University.create name: 'Osuny', identifier: 'demo', sms_sender_name: 'Osuny'
Language.where(name: 'French', iso_code: 'fr').first_or_create
fr = Language.where(name: 'French', iso_code: 'fr').first_or_create
Language.where(name: 'English', iso_code: 'en').first_or_create
University.create name: 'Osuny', identifier: 'demo', sms_sender_name: 'Osuny', default_language: fr
Administration::Qualiopi::Criterion.destroy_all
Administration::Qualiopi::Criterion.create [
{
......
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