Commit 9d54267
authored
fix(plugin-cloud-storage): prevent deleting original file when duplicating (#14961)
### 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 `previousDoc` parameter is
populated with the source document being duplicated. The existing
condition `if (previousDoc)` 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 (previousDoc)` to `if (previousDoc &&
operation === 'update')`
- Files are now only deleted when genuinely updating an existing
document with a new file, not when duplicating1 parent 744a593 commit 9d54267
1 file changed
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
0 commit comments