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

cleanup

parent 660228f7
No related branches found
No related tags found
No related merge requests found
......@@ -35,8 +35,6 @@ class Communication::Website::Post::Category < ApplicationRecord
include WithTree
include WithUniversity
has_one_attached_deletable :featured_image # TODO L10N remove
belongs_to :parent,
class_name: 'Communication::Website::Post::Category',
optional: true
......
......@@ -69,15 +69,15 @@ module Importers
end
def find_organization_with_siren_and_nic
@university.organizations.tmp_original.find_by(siren: @company_siren, nic: @company_nic)
@university.organizations.find_by(siren: @company_siren, nic: @company_nic)
end
def find_organization_with_siren
@university.organizations.tmp_original.find_by(siren: @company_siren)
@university.organizations.find_by(siren: @company_siren)
end
def find_organization_with_name_in_current_language
@university.organizations.tmp_original
@university.organizations
.joins(:localizations)
.where(university_organization_localizations: {
language_id: @language.id, name: @company_name
......@@ -86,7 +86,7 @@ module Importers
end
def find_organization_with_name_in_another_language
@university.organizations.tmp_original
@university.organizations
.joins(:localizations)
.where.not(university_organization_localizations: {
language_id: @language.id
......
......@@ -79,15 +79,15 @@ module Importers
end
def find_organization_with_siren_and_nic
@university.organizations.tmp_original.find_by(siren: @siren, nic: @nic)
@university.organizations.find_by(siren: @siren, nic: @nic)
end
def find_organization_with_siren
@university.organizations.tmp_original.find_by(siren: @siren)
@university.organizations.find_by(siren: @siren)
end
def find_organization_with_name_in_current_language
@university.organizations.tmp_original
@university.organizations
.joins(:localizations)
.where(university_organization_localizations: {
language_id: @language.id,
......@@ -97,7 +97,7 @@ module Importers
end
def find_organization_with_name_in_another_language
@university.organizations.tmp_original
@university.organizations
.joins(:localizations)
.where.not(university_organization_localizations: {
language_id: @language.id
......
......@@ -88,11 +88,11 @@ module Importers
end
def find_person_with_email
@university.people.tmp_original.find_by(email: @email)
@university.people.find_by(email: @email)
end
def find_person_with_name_in_current_language
@university.people.tmp_original
@university.people
.joins(:localizations)
.where(university_person_localizations: {
language_id: @language.id,
......@@ -102,7 +102,7 @@ module Importers
end
def find_person_with_name_in_another_language
@university.people.tmp_original
@university.people
.joins(:localizations)
.where.not(university_person_localizations: {
language_id: @language.id
......
module Migrations
class L10nCleaner
def self.execute
::Communication::Website.skip_callback :save, :after, :create_missing_special_pages
::Communication::Website.skip_callback :touch, :after, :create_missing_special_pages
remove_non_original_objects
remove_obsolete_permalinks
ensure
::Communication::Website.set_callback :touch, :after, :create_missing_special_page
::Communication::Website.set_callback :save, :after, :create_missing_special_pages
end
protected
def self.remove_non_original_objects
Administration::Location.where.not(original_id: nil).destroy_all
Communication::Website::Agenda::Category.where.not(original_id: nil).destroy_all
Communication::Website::Agenda::Event.where.not(original_id: nil).destroy_all
Communication::Website::Page.where.not(original_id: nil).destroy_all
Communication::Website::Portfolio::Category.where.not(original_id: nil).destroy_all
Communication::Website::Portfolio::Project.where.not(original_id: nil).destroy_all
Communication::Website::Post::Category.where.not(original_id: nil).destroy_all
Communication::Website::Post.where.not(original_id: nil).destroy_all
Education::Diploma.where.not(original_id: nil).destroy_all
Education::Program.where.not(original_id: nil).destroy_all
Education::School.where.not(original_id: nil).destroy_all
University::Organization::Category.where.not(original_id: nil).destroy_all
University::Organization.where.not(original_id: nil).destroy_all
University::Person.where.not(original_id: nil).destroy_all
University::Person::Category.where.not(original_id: nil).destroy_all
University::Person::Involvement.where.not(original_id: nil).destroy_all
University::Role.where.not(original_id: nil).destroy_all
end
def self.remove_obsolete_permalinks
about_types_to_delete = [
"Administration::Location",
"Communication::Website::Agenda::Event",
"Communication::Website::Agenda::Category",
"Communication::Website::Page",
"Communication::Website::Portfolio::Project",
"Communication::Website::Portfolio::Category",
"Communication::Website::Post",
"Communication::Website::Post::Category",
"Education::Diploma",
"Education::Program",
"Research::Journal::Paper",
"Research::Journal::Volume",
"University::Organization",
"University::Organization::Category",
"University::Person",
"University::Person::Category",
"University::Person::Administrator",
"University::Person::Author",
"University::Person::Researcher",
"University::Person::Teacher"
]
Communication::Website::Permalink.where(about_type: about_types_to_delete).destroy_all
end
end
end
\ No newline at end of file
......@@ -8,19 +8,7 @@ namespace :app do
desc 'Fix things'
task fix: :environment do
Communication::Website::Post::Category.find_each do |category|
next unless category.featured_image.attached?
puts '---'
puts category.localizations.first.to_s
category.localizations.each do |l10n|
puts l10n
l10n.featured_image.attach(
io: URI.open(category.featured_image.url),
filename: category.featured_image.filename.to_s,
content_type: category.featured_image.content_type
)
end
end
end
namespace :websites 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