/** * Execute the console command. * * @param ImageHandlerInterface $imageHandler * @param CacheHandlerInterface $cacheHandler * @param SearchHandlerInterface $searchHandler * @return mixed */ public function handle(ImageHandlerInterface $imageHandler, CacheHandlerInterface $cacheHandler, SearchHandlerInterface $searchHandler) { // Find all links with photos URLs that need thumbnails $links = Link::with('item', 'item.user')->whereNull('photo')->take(100)->get(); /* @var $link \App\Models\Link */ foreach ($links as $link) { // Try to generate a thumbnail for the desired photo try { $generatedFilename = $imageHandler->generateThumbnail($link->photo_url); if ($generatedFilename) { $link->photo = $generatedFilename; $link->save(); // Update Search $searchHandler->update($link); // Update cache for user $cacheHandler->del(CacheHandlerInterface::MAINPAGE, $link->item->user->id); } } catch (\Exception $e) { error_log($e); } } }