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(); $exportedIds = []; $exportCount = 0; $lastId = 0; while (true) { $rows = $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 >= ?)) AND id > ? ORDER BY id ASC LIMIT ' . self::BATCH_SIZE, [$today, $today, $lastId] )->fetchAllAssociative(); if (empty($rows)) { break; } foreach ($rows as $event) { $response = $this->soapClientService->sendEventToSoapAPI($event); if ($response) { $exportedIds[] = (string) $event['id']; $exportCount++; } $lastId = (int) $event['id']; } } $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; } }