From 62bdfbf9f0a34c3787011f7d3791ff8a39d2386e Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 18 Oct 2024 13:59:48 +0100 Subject: [PATCH] allow validation skipping on file attachment --- app/models/model_file.rb | 4 ++-- db/data/20240615085913_move_file_data_into_shrine.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/model_file.rb b/app/models/model_file.rb index c8e568bf0..ec7349811 100644 --- a/app/models/model_file.rb +++ b/app/models/model_file.rb @@ -84,7 +84,7 @@ def path_within_library File.join(model.path, filename) end - def attach_existing_file!(refresh: true) + def attach_existing_file!(refresh: true, skip_validations: false) return if attachment.present? || !exists_on_storage? attachment_attacher.set LibraryUploader.uploaded_file( storage: model.library.storage_key, @@ -96,7 +96,7 @@ def attach_existing_file!(refresh: true) } ) attachment_attacher.refresh_metadata! if refresh - save! + save!(validate: !skip_validations) end def exists_on_storage? diff --git a/db/data/20240615085913_move_file_data_into_shrine.rb b/db/data/20240615085913_move_file_data_into_shrine.rb index 50878efaf..fb5de7cbf 100644 --- a/db/data/20240615085913_move_file_data_into_shrine.rb +++ b/db/data/20240615085913_move_file_data_into_shrine.rb @@ -2,7 +2,7 @@ class MoveFileDataIntoShrine < ActiveRecord::Migration[7.0] def up - ModelFile.find_each { |x| x.attach_existing_file!(refresh: false) } + ModelFile.find_each { |x| x.attach_existing_file!(refresh: false, skip_validations: true) } end def down