This commit is contained in:
Marko 2024-11-04 22:28:41 +01:00
parent 99551c9e31
commit c4db83daec
No known key found for this signature in database

View File

@ -26,13 +26,13 @@ class SlackNotifySubscriber implements EventSubscriberInterface
private $warehouseRepository;
public function __construct(string $slackWebhookUrl, ProductRepository $productRepository, StockRepository $stockRepository, WarehouseRepository $warehouseRepository)
public function __construct(string $slackWebhookUrl, ProductRepository $productRepository, StockRepository $stockRepository, WarehouseRepository $warehouseRepository, LoggerInterface $logger)
{
$this->slackWebhookUrl = $slackWebhookUrl;
$this->productRepository = $productRepository;
$this->stockRepository = $stockRepository;
$this->warehouseRepository = $warehouseRepository;
$this->logger = $logger;
}
public static function getSubscribedEvents(): array
@ -65,6 +65,7 @@ class SlackNotifySubscriber implements EventSubscriberInterface
$warehouse = $this->getWarehouseByGtin($item['gtin']);
if ($warehouse == false) {
$this->logger->error('Warehouse not found for GTIN: ' . $item['gtin']);
continue;
}
@ -82,9 +83,7 @@ class SlackNotifySubscriber implements EventSubscriberInterface
$msg .= ' - ' . $item['han'];
$msg .= ' * - ' . $item['menge'] . "* \n";
$slack->from('CDS-Notify')->send($msg);
}
}
}
@ -92,14 +91,14 @@ class SlackNotifySubscriber implements EventSubscriberInterface
/**
* @param string $gtin
* @return array
* @return string|bool
*/
private function getWarehouseByGtin(string $gtin)
private function getWarehouseByGtin(string $gtin): bool|string
{
if ($gtin == null) {
return false;
}
$warehouse = "";
$warehouse = false;
$product = $this->productRepository->findOneBy(['gtin' => $gtin]);
@ -125,4 +124,4 @@ class SlackNotifySubscriber implements EventSubscriberInterface
return $warehouse;
}
}
}