Open SlyDave opened 1 day ago
The following pull added to 11.10 causes the issue: https://github.com/spatie/laravel-medialibrary/pull/3715
Reverting:
$conversion = $this
->getConversions($this->media->collection_name)
->first(fn (Conversion $conversion) => $conversion->getName() === $name);
back to
$conversion = $this->first(fn (Conversion $conversion) => $conversion->getName() === $name);
fixes the crash
same issue
ok, so the new code does what is expected and returns null for conversion when, looking for conversions on a collection that doesn't have conversions.
The problem is this is what is throwing the exception
if (! $conversion) {
throw InvalidConversion::unknownName($name);
}
The question then becomes why is ConversionCollection::getByName()
being called for a collection that doesn't have conversions
which brings you toFilesystem->renameConversionFiles()
-> foreach ($media->getMediaConversionNames()...
which comes from Filesystem->syncFileNames
which comes from the aforementioned MediaObserver->updating()
If we follow that, we can see that all the code calls $media->getMediaConversionNames()
and loops over them, it doesn't filter this list down by the conversions actually available for the currently observed collection - so it's running renameConverionsFiles on all conversions configured for the media, not just the ones for the collection - and thus when it hits the getByName which now returns null, it crashes.
// $media->getMediaConversionNames() returns all media conversions (regardless of collection)
// $conversionCollection only contains conversions for the collection the media is for
// thus a call to getByName() on each of the media is going to return null if a media has multiple collections but not all collections have all conversions defined
$conversionCollection = ConversionCollection::createForMedia($media);
foreach ($media->getMediaConversionNames() as $conversionName) {
$conversion = $conversionCollection->getByName($conversionName); <--- crash
I think the woopies here is thinking that $conversionCollection
means conversions for a Media Collection, and not a collection of Conversions for the Media :D
On 11.9.2 everything works.
On 11.10, the following error occurs when updating or saving media:
Note I am updating signatures, not avatar, and yet there is an error for "thumb", which isn't defined as a conversion on the signatures collection, so I'm not sure why it's trying to look it up?!
Other things that might be important
media-library.prefix = ''
so the above just returns uuid for the path, giving paths like"signature_url": "/storage/cf244a39-fa52-42e5-a5e0-62a9ffa5564b/33275f9e-b3a4-44a6-9334-2384f9b6eeaf.jpg"
More information, the media being added is added from base64 so it has a .tmp extension, that is then changed to the correct extension detected by the mime-type (something that media-lib doesn't do automatically! - see the graveyard that is - https://github.com/spatie/laravel-medialibrary/discussions/3089), this causes the Observer to trigger and run, which is when the problems occurs, within
syncFileNames()
insideSpatie\MediaLibrary\MediaCollections\Models\Observers\MediaObserver
.Something is causing backwards breaking in 11.10