From 75b5b01dcc8a0a1a1846c1524db39198a2d79853 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 10 Feb 2022 17:35:20 +0100 Subject: [PATCH] fix --- app/models/application_record.rb | 21 ----------- app/models/communication/website/post.rb | 2 -- docs/communication/wysiwyg.md | 2 ++ lib/tasks/app.rake | 44 +++++++----------------- 4 files changed, 14 insertions(+), 55 deletions(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 9919dcb3c..06f72dc36 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -10,25 +10,4 @@ class ApplicationRecord < ActiveRecord::Base serialize :#{name}, ActionText::Content CODE end - - # TODO Remove everything below after migration, please - - def self.convert_fields_to_summernote(*args) - @@summernote_fields = args - end - - # before_validation :convert_to_summernote - - def convert_to_summernote - @@summernote_fields.each do |field| - self.attributes["#{field}_new"] = send(field).body.to_html - .gsub('<div>', '<p>') - .gsub('</div>', '</p>') - .gsub('<strong>', '<b>') - .gsub('</strong>', '</b>') - .gsub('<em>', '<i>') - .gsub('</em>', '</i>') - .gsub('<p><br></p>', '') - end - end end diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 122cad798..86320e5de 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -41,8 +41,6 @@ class Communication::Website::Post < ApplicationRecord has_rich_text :text has_summernote :text_new - convert_fields_to_summernote :text - has_one :imported_post, class_name: 'Communication::Website::Imported::Post', dependent: :destroy diff --git a/docs/communication/wysiwyg.md b/docs/communication/wysiwyg.md index 06a0b10bd..684fac12a 100644 --- a/docs/communication/wysiwyg.md +++ b/docs/communication/wysiwyg.md @@ -105,6 +105,8 @@ Etapes de migration : ### Le pdf +Autoriser dans summernote + ### Code HTML cible ``` diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index baf1c9b67..d3d730177 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -8,41 +8,21 @@ namespace :app do desc 'Fix things' task fix: :environment do - Communication::Website.find_each { |website| - website.build_home(university_id: website.university_id).save if website.home.nil? - website.update_column(:url, "https://#{website.url}") unless website.url.blank? || website.url.starts_with?('https://') - } - - Education::Program.where(slug: [nil, '']).find_each { |program| program.update_column(:slug, program.name.parameterize) } - Research::Journal::Article.where(slug: [nil, '']).find_each { |article| article.update_column(:slug, article.title.parameterize) } - Research::Journal::Volume.where(slug: [nil, '']).find_each { |volume| volume.update_column(:slug, volume.title.parameterize) } - - 10.times do - Education::Program.find_each { |p| p.update_column :path, "#{p.parent&.path}/#{p.slug}".gsub(/\/+/, '/') } - end - Communication::Website::Post.find_each do |post| - post.categories = post.categories.select { |category| category.children.none? { |child| post.categories.include?(child) } } - end - - Research::Journal::Article.where(position: nil).order(:published_at, :created_at).group_by(&:research_journal_volume_id).each do |_, articles| - articles.each_with_index do |article, index| - article.update_columns({ - published: article.published_at.present?, - position: index + 1 - }) - end - end - - # MICA & Class'Code - Communication::Website.where(id: ["6dfb358c-21bc-440f-9156-e09b72671c32", "1bb0f013-4d3d-49be-84bc-087c8cff3c77"]).each do |website| - website.imported_website.posts.find_each do |imported_post| - imported_post.post&.update_column :published_at, imported_post.published_at - end + post.text_new = clean_for_summernote post.text end + end - # Website structures - Communication::Website.all.each { |w| w.build_structure(university_id: w.university_id).save } + def clean_for_summernote(actiontext) + actiontext.body + .to_html + .gsub('<div>', '<p>') + .gsub('</div>', '</p>') + .gsub('<strong>', '<b>') + .gsub('</strong>', '</b>') + .gsub('<em>', '<i>') + .gsub('</em>', '</i>') + .gsub('<p><br></p>', '') end namespace :db do -- GitLab