Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     logger()->debug("Starting listening");
     $callback = function ($message) {
         logger()->debug('consume message - reindex started');
         $data = json_decode($message->body, true);
         logger()->debug($data);
         if (isset($data["data"]["type"]) && $data["data"]["type"] == 'product') {
             if (!isset($data["data"]["id"])) {
                 logger()->error("Product id not found.");
             } else {
                 $productId = $data["data"]["id"];
                 $this->productIndexer->indexProduct($productId);
                 $this->notificationService->success(sprintf("Indexing product %s", $productId));
             }
         } else {
             logger()->error("Bad data for reindex.");
         }
     };
     $this->connectToRabbit($callback);
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $productId = $this->input->getArgument("product_id");
     $all = $this->input->getOption('all');
     // check argument
     if (!$productId) {
         $this->output->error(sprintf("Product %s not found.", $productId));
         return self::RETURN_ERROR;
     }
     try {
         if ($all) {
             logger()->debug('Index all products');
             $this->indexer->indexAll();
         } else {
             $this->indexer->indexProduct($productId);
         }
     } catch (Exception $e) {
         $this->output->error($e);
         return self::RETURN_ERROR;
     }
     return self::RETURN_OK;
 }