Initial standalone bundle release (sanitized history)
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\KsNossenerlandBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Mummert\KsNossenerlandBundle\Service\SoapClientService;
|
||||
|
||||
class ExportEventsCommand extends Command
|
||||
{
|
||||
private $connection;
|
||||
private $soapClientService;
|
||||
|
||||
public function __construct(Connection $connection, SoapClientService $soapClientService)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->connection = $connection;
|
||||
$this->soapClientService = $soapClientService;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setHelp('Dieses Kommando exportiert zukünftige Events nach EVLKS und löscht nicht mehr vorhandene.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$today = (new \DateTimeImmutable('today'))->getTimestamp();
|
||||
|
||||
$stmt = $this->connection->executeQuery(
|
||||
'SELECT * FROM tl_calendar_events WHERE pid IN (1, 2, 3) AND evlkscalendar != 1 AND (
|
||||
(endDate IS NOT NULL AND endDate >= ?) OR (endDate IS NULL AND startDate >= ?)
|
||||
)',
|
||||
[$today, $today]
|
||||
);
|
||||
|
||||
$exportedIds = [];
|
||||
$exportCount = 0;
|
||||
|
||||
while ($event = $stmt->fetchAssociative()) {
|
||||
$response = $this->soapClientService->sendEventToSoapAPI($event);
|
||||
if ($response) {
|
||||
$exportedIds[] = (string) $event['id'];
|
||||
$exportCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$remoteExternalIds = $this->soapClientService->fetchRemoteExternalIds();
|
||||
$deletedCount = 0;
|
||||
|
||||
foreach ($remoteExternalIds as $externalId) {
|
||||
if (!in_array($externalId, $exportedIds, true)) {
|
||||
$response = $this->soapClientService->deleteEventByExternalId($externalId);
|
||||
if ($response) {
|
||||
$output->writeln("🗑️ gelöscht: $externalId");
|
||||
$deletedCount++;
|
||||
} else {
|
||||
$output->writeln("❌ Fehler beim Löschen von Event $externalId");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln('Export Summary:');
|
||||
$output->writeln('----------------');
|
||||
$output->writeln('Date: ' . date('Y-m-d H:i:s'));
|
||||
$output->writeln("Number of exported events: $exportCount");
|
||||
$output->writeln("Number of deleted events: $deletedCount");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user