File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -249,10 +249,27 @@ public function dispatchConversion(string $conversion): ?PendingDispatch
249
249
return null ;
250
250
}
251
251
252
+ public function getOrExecuteConversion (string $ name ): ?MediaConversion
253
+ {
254
+ if ($ conversion = $ this ->getConversion ($ name )) {
255
+ return $ conversion ;
256
+ }
257
+
258
+ return $ this ->executeConversion ($ name );
259
+ }
260
+
252
261
public function executeConversion (string $ conversion ): ?MediaConversion
253
262
{
254
263
if ($ definition = $ this ->getConversionDefinition ($ conversion )) {
255
- return $ definition ->execute ($ this , $ this ->getParentConversion ($ conversion ));
264
+
265
+ if (str_contains ($ conversion , '. ' )) {
266
+ $ parent = $ this ->getOrExecuteConversion (str ($ conversion )->beforeLast ('. ' ));
267
+ } else {
268
+ $ parent = null ;
269
+ }
270
+
271
+ return $ definition ->execute ($ this , $ parent );
272
+
256
273
}
257
274
258
275
return null ;
Original file line number Diff line number Diff line change 147
147
148
148
});
149
149
150
+ it ('generates non existing parents conversions when executing nested conversion ' , function () {
151
+ Storage::fake ('media ' );
152
+ $ model = new Test ;
153
+ $ model ->save ();
154
+
155
+ $ media = $ model ->addMedia (
156
+ file: $ this ->getTestFile ('videos/horizontal.mp4 ' ),
157
+ collectionName: 'conversions-delayed ' ,
158
+ disk: 'media '
159
+ );
160
+
161
+ expect ($ media ->conversions )->toHaveLength (0 );
162
+
163
+ $ media ->executeConversion ('poster.360 ' );
164
+
165
+ expect ($ media ->conversions )->toHaveLength (2 );
166
+
167
+ expect ($ media ->getConversion ('poster ' ))->not ->toBe (null );
168
+ expect ($ media ->getConversion ('poster.360 ' ))->not ->toBe (null );
169
+ });
170
+
150
171
it ('deletes old media when adding to single collection ' , function () {
151
172
Storage::fake ('media ' );
152
173
$ model = new Test ;
Original file line number Diff line number Diff line change @@ -94,6 +94,27 @@ public function registerMediaCollections(): Arrayable|iterable|null
94
94
),
95
95
]
96
96
),
97
+ new MediaCollection (
98
+ name: 'conversions-delayed ' ,
99
+ single: false ,
100
+ public: false ,
101
+ conversions: [
102
+ new MediaConversionPoster (
103
+ name: 'poster ' ,
104
+ queued: false ,
105
+ immediate: false ,
106
+ conversions: [
107
+ new MediaConversionImage (
108
+ name: '360 ' ,
109
+ width: 360 ,
110
+ queued: false ,
111
+ immediate: true ,
112
+ ),
113
+ ]
114
+ ),
115
+
116
+ ]
117
+ ),
97
118
];
98
119
}
99
120
}
You can’t perform that action at this time.
0 commit comments