<?php
namespace App\EventListener\Central;
use App\Entity\Central\Client\Client;
use App\EventListener\GenericEvent;
use App\Model\ShellExec;
use App\Service\Central\Client\ClientFlagManager;
use App\Service\Central\Client\ClientManager;
use App\Service\ShellExecManager;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpKernel\KernelInterface;
class ClientPostListener
{
private $kernel;
private $shellExecManager;
private $clientManager;
public function __construct(ShellExecManager $shellExecManager, KernelInterface $kernel, ClientManager $clientManager)
{
$this->kernel = $kernel;
$this->shellExecManager = $shellExecManager;
$this->clientManager = $clientManager;
}
public function post(GenericEvent $genericEvent)
{
$client = $genericEvent->getSubject();
if (!$client instanceof Client || $client->getId() === null) {
return;
}
$shellExec = new ShellExec('doctrine:schema:update', '--clientID='.$client->getId().' --schemas=client --force');
$this->shellExecManager->runShellExec($shellExec, true);
$this->resolveEshop($client);
}
public function update(GenericEvent $genericEvent)
{
$client = $genericEvent->getSubject();
if(!$client instanceof Client || $client->getId() === null) {
return;
}
$this->resolveEshop($client);
}
private function resolveEshop(Client $client)
{
if(!$client->hasFlag(ClientFlagManager::HAVE_ESHOP)) {
return;
}
$shellExec = new ShellExec('doctrine:schema:update', '--clientID='.$client->getId().' --schemas=eshop --kernel=eshop --force');
$this->shellExecManager->runShellExec($shellExec, true);
}
}