Skip to content

Commit a39af34

Browse files
committed
wip
1 parent 3d23cd0 commit a39af34

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/Models/Media.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function dispatchConversion(
259259
): ?PendingDispatch {
260260
if (
261261
$force === false &&
262-
$this->hasConversion($conversion, MediaConversionState::Succeeded)
262+
$this->hasConversion($conversion, [MediaConversionState::Succeeded, MediaConversionState::Pending])
263263
) {
264264
return null;
265265
}
@@ -314,7 +314,7 @@ public function getOrExecuteConversion(
314314
string $name,
315315
bool $withChildren = true,
316316
): ?MediaConversion {
317-
if ($conversion = $this->getConversion($name, MediaConversionState::Succeeded)) {
317+
if ($conversion = $this->getConversion($name, [MediaConversionState::Succeeded, MediaConversionState::Pending])) {
318318
return $conversion;
319319
}
320320

@@ -328,7 +328,8 @@ public function getOrExecuteConversion(
328328
public function getConversion(
329329
string $name,
330330
null|MediaConversionState|array $state = null,
331-
null|string|array $fallback = null
331+
null|string|array $fallback = null,
332+
bool $dispatch = false,
332333
): ?MediaConversion {
333334

334335
$state = Arr::wrap($state);
@@ -343,6 +344,8 @@ public function getConversion(
343344

344345
if ($conversion) {
345346
return $conversion;
347+
} elseif ($dispatch) {
348+
$this->dispatchConversion($name, false);
346349
}
347350

348351
if (is_string($fallback)) {
@@ -360,8 +363,13 @@ public function getConversion(
360363
return null;
361364
}
362365

363-
public function hasConversion(string $name, ?MediaConversionState $state = null): bool
364-
{
366+
/**
367+
* @param null|MediaConversionState|MediaConversionState[] $state
368+
*/
369+
public function hasConversion(
370+
string $name,
371+
null|MediaConversionState|array $state = null
372+
): bool {
365373
return (bool) $this->getConversion($name, $state);
366374
}
367375

@@ -659,15 +667,17 @@ public function getUrl(
659667
$url = null;
660668

661669
if ($conversion) {
662-
$mediaConversion = $this->getConversion($conversion);
670+
$mediaConversion = $this->getConversion(
671+
name: $conversion,
672+
state: MediaConversionState::Succeeded,
673+
dispatch: $dispatch,
674+
);
663675

664-
if ($mediaConversion && $mediaConversion->state === MediaConversionState::Succeeded) {
676+
if ($mediaConversion) {
665677
$url = $mediaConversion->getUrl(
666678
parameters: $parameters,
667679
formatter: $formatter,
668680
);
669-
} elseif ($mediaConversion === null && $dispatch) {
670-
$this->dispatchConversion($conversion, false);
671681
}
672682

673683
} elseif ($this->path) {

0 commit comments

Comments
 (0)