Add EVLKS accessibility field and export mapping
This commit is contained in:
@@ -12,6 +12,7 @@ class ExportEventsCommand extends Command
|
||||
{
|
||||
private $connection;
|
||||
private $soapClientService;
|
||||
private const BATCH_SIZE = 200;
|
||||
|
||||
public function __construct(Connection $connection, SoapClientService $soapClientService)
|
||||
{
|
||||
@@ -29,21 +30,35 @@ class ExportEventsCommand extends Command
|
||||
{
|
||||
$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++;
|
||||
$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'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use SoapHeader;
|
||||
use Exception;
|
||||
use StdClass;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class SoapClientService
|
||||
{
|
||||
@@ -14,10 +15,12 @@ class SoapClientService
|
||||
private string $apiKey;
|
||||
private string $vid;
|
||||
private Connection $connection;
|
||||
private Client $httpClient;
|
||||
|
||||
public function __construct(Connection $connection, string $wsdlUrl, string $endpointUrl, string $apiKey, string $vid)
|
||||
public function __construct(Connection $connection, Client $httpClient, string $wsdlUrl, string $endpointUrl, string $apiKey, string $vid)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->httpClient = $httpClient;
|
||||
$this->apiKey = $apiKey;
|
||||
$this->vid = $vid;
|
||||
|
||||
@@ -211,6 +214,7 @@ class SoapClientService
|
||||
|
||||
$link = 'https://kirchspiel-nossener-land.de/termine/' . $eventData['alias'];
|
||||
$menue1 = (isset($eventData['godi_options']) && in_array('2', explode(',', $eventData['godi_options']))) ? 100 : null;
|
||||
$access = $this->normalizeCsvSelection($eventData['evlks_access'] ?? null, range(1, 9));
|
||||
|
||||
$event = [
|
||||
'externalid' => strval($eventData['id']),
|
||||
@@ -233,6 +237,7 @@ class SoapClientService
|
||||
'textline1' => $people,
|
||||
'people' => null,
|
||||
'menue1' => $menue1,
|
||||
'access' => $access,
|
||||
'kollekte' => 0,
|
||||
];
|
||||
|
||||
@@ -244,6 +249,19 @@ class SoapClientService
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeCsvSelection(?string $csv, array $allowedIds): ?string
|
||||
{
|
||||
if (null === $csv || '' === trim($csv)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$allowed = array_map('strval', $allowedIds);
|
||||
$items = array_filter(array_map('trim', explode(',', $csv)), static fn ($v) => '' !== $v);
|
||||
$items = array_values(array_unique(array_filter($items, static fn ($v) => in_array($v, $allowed, true))));
|
||||
|
||||
return empty($items) ? null : implode(',', $items);
|
||||
}
|
||||
|
||||
public function deleteEventByExternalId(string $externalId): bool
|
||||
{
|
||||
if (!$this->client instanceof SoapClient) {
|
||||
@@ -272,9 +290,25 @@ class SoapClientService
|
||||
{
|
||||
$url = 'https://kalender.evlks.de/json?vid=' . $this->vid;
|
||||
|
||||
$json = @file_get_contents($url);
|
||||
if (!$json) {
|
||||
error_log("❌ Fehler beim Abrufen der JSON-Daten von $url");
|
||||
try {
|
||||
$response = $this->httpClient->request('GET', $url, [
|
||||
'timeout' => 3.0,
|
||||
'connect_timeout' => 2.0,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
error_log("❌ Fehler beim Abrufen der JSON-Daten von $url: " . $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
|
||||
if (200 !== $response->getStatusCode()) {
|
||||
error_log("❌ EVLKS JSON antwortete mit HTTP " . $response->getStatusCode());
|
||||
return [];
|
||||
}
|
||||
|
||||
$json = (string) $response->getBody();
|
||||
if ('' === $json) {
|
||||
error_log("❌ Leere JSON-Antwort von $url");
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user