From 87cf14789ac7788fb00d208a0fdd436bdb903fbf Mon Sep 17 00:00:00 2001 From: PiTrem Date: Tue, 5 Jul 2022 01:47:19 +0200 Subject: [PATCH] attachment jobs: skip if not a valid attachment (#781) --- app/jobs/transfer_file_from_tmp_job.rb | 4 +++- app/jobs/transfer_thumbnail_to_public_job.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/jobs/transfer_file_from_tmp_job.rb b/app/jobs/transfer_file_from_tmp_job.rb index 61f67ec67c..caa653b49d 100644 --- a/app/jobs/transfer_file_from_tmp_job.rb +++ b/app/jobs/transfer_file_from_tmp_job.rb @@ -5,7 +5,9 @@ def perform(attach_ary) primary_store = Rails.configuration.storage.primary_store begin attach_ary.each do |attach_id| - attachment = Attachment.find(attach_id) + attachment = Attachment.find_by(id: attach_id) + next unless attachment + if attachment.storage == 'tmp' attachment.update!(storage: primary_store) end diff --git a/app/jobs/transfer_thumbnail_to_public_job.rb b/app/jobs/transfer_thumbnail_to_public_job.rb index b25b2dfff9..c6f4c7e9c9 100644 --- a/app/jobs/transfer_thumbnail_to_public_job.rb +++ b/app/jobs/transfer_thumbnail_to_public_job.rb @@ -5,7 +5,9 @@ class TransferThumbnailToPublicJob < ApplicationJob queue_as :transfer_thumbnail_to_public def perform(attach_ary) attach_ary.each do |attach_id| - a = Attachment.find(attach_id) + a = Attachment.find_by(id: attach_id) + next unless a + file_path = Rails.public_path.join('images', 'thumbnail', a.identifier) File.write(file_path, a.read_thumbnail.force_encoding('UTF-8')) if a.read_thumbnail end