From cf6a964e12b41e73125dffb611da31ea075e0470 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Thu, 28 Mar 2024 09:15:59 +0000 Subject: [PATCH] Update storage mirror task Fix existing integrity errors preventing mirroring of attachments to the secondary storage services. --- lib/tasks/storage/storage.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tasks/storage/storage.rb b/lib/tasks/storage/storage.rb index a9bcc3e315..2e59294ce9 100644 --- a/lib/tasks/storage/storage.rb +++ b/lib/tasks/storage/storage.rb @@ -46,7 +46,16 @@ def mirror count = mirrorable_blobs.count mirrorable_blobs.find_each.with_index do |blob, index| - mirror_service.mirror(blob.key, checksum: blob.checksum) + begin + mirror_service.mirror(blob.key, checksum: blob.checksum) + rescue ActiveStorage::IntegrityError => ex + raise ex unless @klass == FoiAttachment + + # Fix for https://github.com/mysociety/alaveteli/issues/8181 + attachment = FoiAttachment.joins(:file_blob). + find_by(active_storage_blobs: { id: blob }) + FoiAttachmentMaskJob.perform_later(attachment) # this also mirrors + end print "#{prefix}: Mirrored #{index + 1}/#{count}" end