From cdefa7cdfe092bc0c4817155ec652e643d119de9 Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Tue, 8 Nov 2022 09:51:34 +1100 Subject: [PATCH] Fix asset indexing when resizing images --- src/services/Resize.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/Resize.php b/src/services/Resize.php index c3419ae..490cc6b 100644 --- a/src/services/Resize.php +++ b/src/services/Resize.php @@ -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) { @@ -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); } }