Skip to content
Snippets Groups Projects
Commit 75b5b01d authored by Arnaud Levy's avatar Arnaud Levy
Browse files

fix

parent 4d0150cf
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
......@@ -105,6 +105,8 @@ Etapes de migration :
### Le pdf
Autoriser dans summernote
### Code HTML cible
```
......
......@@ -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
......
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