<?php
namespace App\EventListener\Custom\Gonarex;
use App\Entity\Central\Client\Client;
use App\Entity\Client\Store\StoreHeader;
use App\EventListener\GenericEvent;
use App\Model\ShellExec;
use App\Service\AppManager;
use App\Service\ShellExecManager;
use App\Utils\ClientUtils;
class StoreWarehouseDuplicityListener
{
private AppManager $appManager;
private ShellExecManager $shellExecManager;
public function __construct(AppManager $appManager, ShellExecManager $shellExecManager)
{
$this->appManager = $appManager;
$this->shellExecManager = $shellExecManager;
}
public function confirm(GenericEvent $genericEvent): void
{
$client = $this->appManager->getClient();
if (!$client instanceof Client || $client->getCode() !== ClientUtils::GONAREX) {
return;
}
$storeHeader = $genericEvent->getSubject();
if (!$storeHeader instanceof StoreHeader || $storeHeader->getType() !== StoreHeader::STORE_HEADER_WAREHOUSE_RECEIPT) {
return;
}
$shellExec = new ShellExec('gonarex:duplicity_warehouse_receipt', '--id=' . $storeHeader->getId() . ' --kernel=custom');
$this->shellExecManager->runShellExec($shellExec, true);
}
}