We have a situation where we create a Media entity using a dummy file, then after we have saved it (and can get a provider reference for where the image is stored) we set the file size etc. When we make the second change the postUpdate doctrine lifecycle event is trying to delete the whole directory.
Our code in question:
$this->em->persist($mediaEntity);
$this->em->flush();
$fileSource->process($mediaEntity);
$this->em->flush($mediaEntity);
On the second flush, the code in \Sonata\MediaBundle\Provider\FileProvider::postUpdate is deleting the current file from the filesystem using $media->getPreviousProviderReference() which is null.
Is this a bug?