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

Flushing an Image document closes the stream #128

Closed gonzalovilaseca closed 8 years ago

gonzalovilaseca commented 9 years ago

Not sure if this is a MediaBundle issue or a Doctrine problem. in this case:

$om->persist($image);
$om->flush();
$stream = $image->getFileContentAsStream()

$stream is null, previous to the flush getFileContentAsStream returns a stream.

OTOH with this code:

$om->persist($image);
$om->flush();
$om->clear();
$image = $this->mr->getRepository($this->class)->find($image->getId());
$stream = $image->getFileContentAsStream()

$stream is a valid stream.

Any ideas?

dbu commented 9 years ago

hm, that is strange. we do wipe the stream from the property during the save operation: https://github.com/jackalope/jackalope/blob/master/src/Jackalope/Property.php#L269-L271 unfortunately i don't remember why exactly (that code is 4 years old, after all) but i think it had to do with memory consumption and with normalizing how streams look.

but the getBinary method is supposed to reload it immediately. https://github.com/jackalope/jackalope/blob/master/src/Jackalope/Property.php#L308-L312

could this be a bug when wrapBinaryStreams is true? indeed there are some illogic things in that method, as the value is unconditionally set to null.

do you have time to investigate into this? we should create some unit tests for the different flags i think, to check which cases work and which dont. and then fix the cases that don't work.

dbu commented 9 years ago

hm, just realized that your code is mapped on a document, so it would also be something with what the unit of work does during the save - the mystery deepens. but can you try playing with the Property class to re-load the stream even if the streamwrapper is not enabled, or not set the value to null, just to see on which layer the issue is?

gonzalovilaseca commented 9 years ago

Ok, I will investigate and report back as soon as I find something.

dbu commented 8 years ago

@gonzalovilaseca did you happen to find anything here?

gonzalovilaseca commented 8 years ago

Sorry, I didn't.

dbu commented 8 years ago

i will close this for now. if you find a way to reproduce it (ideally with a phpunit test in this bundle) please re-open or do a pull request with the failing test.