symfony-cmf / media-bundle

UNMAINTAINED - Minimalistic interfaces to handle media in the context of the CMF
http://cmf.symfony.com/
30 stars 40 forks source link

Changing Media entity twice in same request is trying to delete directory #141

Closed liquorvicar closed 8 years ago

liquorvicar commented 8 years ago

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?

dbu commented 8 years ago

generally doing things in doctrine event listeners can be tricky. do you see a way to do it with a custom symfony event? otherwise, if you see a way how this could properly work, please do a bugfix pull request.

liquorvicar commented 8 years ago

Aaaaargh, posted to the wrong place. The issue I have is with Sonata and not Symfony CMF directly.

Hangs head in shame...

uwej711 commented 8 years ago

I think that could be related: https://github.com/doctrine/phpcr-odm/pull/661

Can you try that branch of phpcr-odm to find out whether this still happens?

liquorvicar commented 8 years ago

@uwej711 No, don't think it's related. I posted to the wrong place, we're using the Sonata Media bundle and regular doctrine entities, not Symfony-CMF/phpcr.

uwej711 commented 8 years ago

OK, you are right.