VichUploaderBundle
VichUploaderBundle copied to clipboard
Cleanup command
Feature Request
Q | A |
---|---|
New Feature | yes |
RFC | no |
BC Break | no |
Summary
In a relation database it is quiet easy to implicitly delete a row throw foreign key constraints without doctrine noticing.
I want to propose a cleanup command that goes through all mapped entities and all existing files and tries to delete all files that are orphaned.
I could implement this for doctrine orm but I'm not fluent in the other storage engines.
I also see that this could become challenging if the amount of files goes above ~65.535 and even before that, it probably should work in chunks to avoid loading everything into ram.
I think that getting orphaned Doctrine objects does not belong here. You should execute such task elsewhere, while deleting a mapped object should already delete related file.
Maybe I described it the wrong way.
I'm not talking about orphaned doctrine objects, I'm talking about orphaned files.
If you have a relation defined with @JoinColumn(onDelete="CASCADE")
. then the database can delete rows without doctrine knowing about it and therefore without this bundle deleting the corresponding files.
And there might also be external sources deleting rows, maybe even accidents or manual cleanup.
That's why I would like an easy way to check if the the database and the filesystem are in sync.
Oh well, in that case it looks fine to me. Waiting for your PR
Doctrine has cascade={'remove'}
which cascades on the Doctrine level instead on the DB level:
https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations
Might still make sense have a command to check data consistency though.