suivi/src/EventSubscriber/Task/CaldavSyncEventSubscriber.php

44 lines
1.2 KiB
PHP

<?php
namespace App\EventSubscriber\Task;
use App\Core\Event\Task\TaskInitEvent;
use App\Core\Event\Task\TaskRunRequestedEvent;
use App\Core\EventSubscriber\Task\TaskEventSubscriber;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
class CaldavSyncEventSubscriber extends TaskEventSubscriber
{
protected KernelInterface $kernel;
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
public function onInit(TaskInitEvent $event)
{
$event->addTask('caldav:sync', '📅 Calendrier', 'Synchronisation');
}
public function onRunRequest(TaskRunRequestedEvent $event)
{
if ('caldav:sync' !== $event->getTask()) {
return;
}
$application = new Application($this->kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'command' => 'caldav:sync',
'-e' => $this->kernel->getEnvironment(),
]);
$application->run($input, $event->getOutput());
}
}