feat: import destinations from the MyE&P travel export

This commit is contained in:
fromme committed 2026-09-29 12:57:54 +02:00
1 parent 5c7e702eab
commit 0f76c5a7b6
15 files changed
+791 -422

No files matched your search

+7 -1
View File
@@ -114,7 +114,12 @@ class DestinationRow
/**
* The shape here is what the destination table stores and what
* App\BusProNet\Model\Pickup::fromArray() reads back.
* App\BusProNet\Model\Pickup::fromArray() reads back, which ignores the extra `datetime`.
*
* `datetime` is not optional decoration. MyE&P sends `time` as a bare HH:MM, so without it
* App\Service\Assignment\PickupDepartureOrder never finds a dated entry, its anchor is null
* and it falls back to sorting on the clock alone - which puts a 00:30 boarding point ahead
* of the 22:00 departure on every route that runs through the night.
*/
private static function readPickups(mixed $pickups): array
{
@@ -140,6 +145,7 @@ class DestinationRow
'city' => self::readNullableString($pickup, 'city'),
'street' => self::readNullableString($pickup, 'street'),
'time' => self::readNullableString($pickup, 'time'),
'datetime' => self::readNullableString($pickup, 'datetime'),
];
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\MyEp\Import;
/**
* The travel export as one run of the import sees it: its rows and what MyE&P dropped building them.
*
* The counters come from the first page's meta and describe the whole export, not the page, so
* reading them once is correct. They matter because both are silent losses: a skipped row is a
* travel the disposition will never offer, and a pickup without master data is a boarding point
* with no town or street. The import logs them per run so the ids can be chased upstream rather
* than quietly becoming permanent.
*/
final readonly class TravelExport
{
/**
* @param DestinationRow[] $rows
* @param int $skipped date x hotel pairs MyE&P dropped as unusable
* @param int $pickupsWithoutMasterData distinct pickup ids absent from zustiege.xml
*/
public function __construct(
public array $rows,
public int $skipped,
public int $pickupsWithoutMasterData,
public ?string $generatedAt,
) {
}
}
+11 -4
View File
@@ -26,15 +26,14 @@ class TravelExportClient
}
/**
* @return DestinationRow[]
*
* @throws ApiException
*/
public function fetchAll(): array
public function fetchAll(): TravelExport
{
$rows = [];
$page = 1;
$totalPages = 1;
$meta = [];
do {
$payload = $this->apiClient->get(self::PATH, [
@@ -63,6 +62,9 @@ class TravelExportClient
}
}
// The counters repeat unchanged on every page, so the first one answers for the run.
$meta = [] === $meta ? (array) ($payload['meta'] ?? []) : $meta;
$totalPages = max(1, (int) ($payload['meta']['totalPages'] ?? 1));
++$page;
} while ($page <= $totalPages && $page <= self::MAX_PAGES && [] !== $data);
@@ -74,6 +76,11 @@ class TravelExportClient
]);
}
return $rows;
return new TravelExport(
$rows,
(int) ($meta['skipped'] ?? 0),
(int) ($meta['pickupsWithoutMasterData'] ?? 0),
isset($meta['generatedAt']) ? (string) $meta['generatedAt'] : null,
);
}
}