Skip to content

Conversation

@jhb-dev
Copy link
Contributor

@jhb-dev jhb-dev commented Dec 17, 2025

What

Fixes the beforeChange hook in the cloud-storage-plugin to only delete files from storage when the operation is update, not during create (which includes duplication).

Why

When duplicating a media document, the originalDoc parameter is populated with the source document being duplicated. The existing condition if (originalDoc) incorrectly triggered file deletion, removing the original file from cloud storage (R2/S3/etc.) while the original database document still referenced it.

This resulted in:

  • Original document in database with broken file reference
  • Original file deleted from cloud storage
  • New duplicated document working correctly

How

  • Added operation to the destructured hook parameters
  • Changed the condition from if (originalDoc) to if (originalDoc && operation === 'update')
  • Files are now only deleted when genuinely updating an existing document with a new file, not when duplicating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant