Skip to content

Commit

Permalink
Move check for objects referencing external content
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bkembreeBPS committed Jul 5, 2024
1 parent 9f7fe66 commit 12a63d4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/RT/Record.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 12a63d4

Please sign in to comment.