task(pj): create representations for latest pieces jointes
This commit is contained in:
parent
b638b2e45a
commit
c94c2f55c8
4 changed files with 149 additions and 0 deletions
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Maintenance
|
||||
class CreatePreviewsForPjOfLatestDossiersTask < MaintenanceTasks::Task
|
||||
def collection
|
||||
dossier_ids = Dossier
|
||||
.state_en_construction_ou_instruction
|
||||
.where(depose_at: 3.months.ago..)
|
||||
.pluck(:id)
|
||||
|
||||
champ_ids = Champ
|
||||
.where(dossier_id: dossier_ids)
|
||||
.where(type: ["Champs::PieceJustificativeChamp", 'Champs::TitreIdentiteChamp'])
|
||||
.pluck(:id)
|
||||
|
||||
ActiveStorage::Attachment
|
||||
.where(record_id: champ_ids)
|
||||
end
|
||||
|
||||
def process(attachment)
|
||||
return unless attachment.previewable?
|
||||
attachment.preview(resize_to_limit: [400, 400]).processed unless attachment.preview(resize_to_limit: [400, 400]).image.attached?
|
||||
rescue MiniMagick::Error
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Maintenance
|
||||
class CreateVariantsForPjOfLatestDossiersTask < MaintenanceTasks::Task
|
||||
def collection
|
||||
dossier_ids = Dossier
|
||||
.state_en_construction_ou_instruction
|
||||
.where(depose_at: 3.months.ago..)
|
||||
.pluck(:id)
|
||||
|
||||
champ_ids = Champ
|
||||
.where(dossier_id: dossier_ids)
|
||||
.where(type: ["Champs::PieceJustificativeChamp", 'Champs::TitreIdentiteChamp'])
|
||||
.pluck(:id)
|
||||
|
||||
ActiveStorage::Attachment
|
||||
.where(record_id: champ_ids)
|
||||
end
|
||||
|
||||
def process(attachment)
|
||||
return unless attachment.variable?
|
||||
attachment.variant(resize_to_limit: [400, 400]).processed if attachment.variant(resize_to_limit: [400, 400]).key.nil?
|
||||
if attachment.blob.content_type.in?(RARE_IMAGE_TYPES) && attachment.variant(resize_to_limit: [2000, 2000]).key.nil?
|
||||
attachment.variant(resize_to_limit: [2000, 2000]).processed
|
||||
end
|
||||
rescue MiniMagick::Error
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue