Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data corruption bug when storage disk becomes invalid #3139

Merged
merged 2 commits into from
Dec 30, 2022

Conversation

Pilskalns
Copy link
Contributor

This fixes a bug when a storage disk becomes invalid. The FileAdder.php#L450 would "redo" already saved records in DB, unfortunately, the produced SQL delete query scopes to all media belonging to a model (not by id).

While $model->media()->delete($media->id) call looks ok, for some reason it actually ignores specific media id and scopes to all.

The was already a test case for this scenario, but it would run on the assumption there are no other media attached. So it would produce a false positive outcome.

Sample delete query before:

DELETE FROM `media`
WHERE `media`.`model_type` = 'App\\Models\\User' and `media`.`model_id` = 2 and `media`.`model_id` IS not NULL;

Sample delete query after:

DELETE FROM `media`
WHERE `id` = 16

@freekmurze freekmurze merged commit e2f1f76 into spatie:main Dec 30, 2022
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants