Skip to content

Commit

Permalink
Fix asset indexing when resizing images
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Nov 7, 2022
1 parent b881400 commit cdefa7c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/services/Resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Resize extends Component
public function resize(Asset $asset, string $filename, string $path, int $width = null, int $height = null, $taskId = null): bool
{
$volume = $asset->getVolume();
$assetIndexer = Craft::$app->getAssetIndexer();

// Does the volume exist?
if (!$volume) {
Expand Down Expand Up @@ -83,7 +84,9 @@ public function resize(Asset $asset, string $filename, string $path, int $width
$volume->getFs()->writeFileFromStream($filePath, $stream, []);

// Spin up asset indexer
Craft::$app->getAssetIndexer()->indexFile($volume, $filePath, 'image-resizer');
$session = $assetIndexer->createIndexingSession([$volume]);
$assetIndexer->indexFile($volume, $filePath, $session->id);
$assetIndexer->stopIndexingSession($session);
}
}

Expand Down

0 comments on commit cdefa7c

Please sign in to comment.