From 854434f977cf4c72538c00db67cc39e84db77f91 Mon Sep 17 00:00:00 2001 From: Brad Embree Date: Fri, 5 Jul 2024 12:13:33 -0700 Subject: [PATCH] Move check for objects referencing external content Moved the check for other objects referencing external content to after it is internalized. This stops the external content from being deleted while still internalizing the external content for the record being shredded. --- lib/RT/Record.pm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm index 4c7f19fd9e..dea51a1666 100644 --- a/lib/RT/Record.pm +++ b/lib/RT/Record.pm @@ -2623,18 +2623,6 @@ sub BeforeWipeout { { my $digest = $self->ExternalStoreDigest; - # Delete external resource only if there are no objects referenced to it - for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) { - my $objects = $class->new( $self->CurrentUser ); - $objects->Limit( FIELD => 'ContentEncoding', VALUE => 'external' ); - $objects->Limit( FIELD => 'Content', VALUE => $digest ); - $objects->Limit( FIELD => 'id', VALUE => $self->Id, OPERATOR => '!=' ); - if ( $objects->First ) { - RT->Logger->info("$digest is referenced by other objects, skipping"); - return 1; - } - } - my $storage = RT->System->ExternalStorage; unless ($storage) { RT->Logger->error("External storage not configured"); @@ -2663,6 +2651,18 @@ sub BeforeWipeout { return 1; } + # Delete external resource only if there are no objects referenced to it + for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) { + my $objects = $class->new( $self->CurrentUser ); + $objects->Limit( FIELD => 'ContentEncoding', VALUE => 'external' ); + $objects->Limit( FIELD => 'Content', VALUE => $digest ); + $objects->Limit( FIELD => 'id', VALUE => $self->Id, OPERATOR => '!=' ); + if ( $objects->First ) { + RT->Logger->info("$digest is referenced by other objects, skipping"); + return 1; + } + } + my ( $ret, $msg ) = $storage->Delete($digest); if ( !$ret ) { RT->Logger->error("Failed to delete $digest from external storage: $msg");