Example #1
0
 /**
  * Update an item
  *
  * @param $inputs
  * @return bool
  */
 public function update($inputs)
 {
     /* @var $item Item */
     $item = $this->itemsRepo->get($inputs['itemId']);
     $item->value = $inputs['value'];
     $item->description = $inputs['description'];
     $subclass = get_class($item->itemable);
     if ($subclass == 'App\\Models\\Link') {
         $item->itemable->title = $inputs['value'];
     }
     // Tags
     $this->tagsRepo->updateForItem($item, $inputs, Auth::user());
     // Cache
     $this->cacheHandler->del(CacheHandlerInterface::MAINPAGE);
     $this->cacheHandler->del(CacheHandlerInterface::TAGS);
     // Save
     $item->save();
     // Update Search
     $this->searchHandler->update($item->itemable);
     return $item;
 }
 /**
  * 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);
         }
     }
 }