This needs to be refactored. Among others :
- No need to do custom pre-flush stuff anymore, as it is in Doctrine Core
- File unlinking could use a revamp, and everything needs to be unit-tested
- Too many passes - we need to listen to fewer events and to avoid processing the same entities / files over and over again
- Upload dir should be a service config param