wip: modernized edit flow
This commit is contained in:
@@ -121,7 +121,7 @@ class TravelDataService
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
throw $e;
|
||||
} catch (HotelNotFoundException | HotelNotInTravelException $e) {
|
||||
} catch (HotelNotFoundException|HotelNotInTravelException $e) {
|
||||
$this->logger->debug('Hotel not found in XML', [
|
||||
'dateId' => $dateId,
|
||||
'hotelId' => $hotelId,
|
||||
@@ -433,7 +433,44 @@ class TravelDataService
|
||||
*
|
||||
* @return BaseData|null The mutability data or null if not available or error occurred
|
||||
*/
|
||||
public function getMutabilityData(int $dateId): ?BaseData
|
||||
/**
|
||||
* Gets mutability data for a travel date.
|
||||
*
|
||||
* @param int $dateId The travel date ID for API call
|
||||
* @param bool $cached Whether to use cached data (default: true, TTL: 12 hours)
|
||||
*
|
||||
* @return BaseData|null The mutability data or null if not available or error occurred
|
||||
*/
|
||||
public function getMutabilityData(int $dateId, bool $cached = true): ?BaseData
|
||||
{
|
||||
if ($cached) {
|
||||
$cacheKey = sprintf('mutability_%d', $dateId);
|
||||
|
||||
try {
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId) {
|
||||
// 12 hours TTL - mutability dates have date-only granularity
|
||||
$item->expiresAfter(43200);
|
||||
|
||||
return $this->fetchMutabilityData($dateId);
|
||||
});
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->logger->error('Cache error in getMutabilityData', [
|
||||
'dateId' => $dateId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
// Fallback to direct API call
|
||||
return $this->fetchMutabilityData($dateId);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->fetchMutabilityData($dateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches mutability data directly from the API without caching.
|
||||
*/
|
||||
private function fetchMutabilityData(int $dateId): ?BaseData
|
||||
{
|
||||
try {
|
||||
$mutableData = $this->apiClient->getMutableData($dateId);
|
||||
@@ -482,16 +519,44 @@ class TravelDataService
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch availability data from API.
|
||||
* Gets availability data for a travel date.
|
||||
*
|
||||
* Retrieves availability information from the API for a specific travel date.
|
||||
* Handles API errors and notification responses gracefully.
|
||||
*
|
||||
* @param int $dateId The travel date ID for API call
|
||||
* @param int $dateId The travel date ID for API call
|
||||
* @param bool $cached Whether to use cached data (default: false, TTL when cached: 60 seconds)
|
||||
* @param int $ttl Cache TTL in seconds when $cached is true (default: 60 seconds)
|
||||
*
|
||||
* @return BaseData|null The availability data or null if not available or error occurred
|
||||
*/
|
||||
public function getAvailabilityData(int $dateId): ?BaseData
|
||||
public function getAvailabilityData(int $dateId, bool $cached = false, int $ttl = 60): ?BaseData
|
||||
{
|
||||
if ($cached) {
|
||||
$cacheKey = sprintf('availability_%d', $dateId);
|
||||
|
||||
try {
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId, $ttl) {
|
||||
// Short TTL - availability is volatile and changes with bookings
|
||||
$item->expiresAfter($ttl);
|
||||
|
||||
return $this->fetchAvailabilityData($dateId);
|
||||
});
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->logger->error('Cache error in getAvailabilityData', [
|
||||
'dateId' => $dateId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
// Fallback to direct API call
|
||||
return $this->fetchAvailabilityData($dateId);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->fetchAvailabilityData($dateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches availability data directly from the API without caching.
|
||||
*/
|
||||
private function fetchAvailabilityData(int $dateId): ?BaseData
|
||||
{
|
||||
try {
|
||||
$availabilities = $this->apiClient->getAvailabilities($dateId);
|
||||
@@ -524,9 +589,7 @@ class TravelDataService
|
||||
/**
|
||||
* Fetch availability data with short-term caching.
|
||||
*
|
||||
* Retrieves availability information from the API with caching to reduce
|
||||
* API calls during booking form interactions. Uses a short TTL to ensure
|
||||
* reasonably fresh data while avoiding excessive API requests.
|
||||
* @deprecated Use getAvailabilityData($dateId, cached: true) instead
|
||||
*
|
||||
* @param int $dateId The travel date ID for API call
|
||||
* @param int $ttl Cache TTL in seconds (default: 60 seconds)
|
||||
@@ -535,23 +598,7 @@ class TravelDataService
|
||||
*/
|
||||
public function getAvailabilityDataCached(int $dateId, int $ttl = 60): ?BaseData
|
||||
{
|
||||
$cacheKey = sprintf('availability_%d', $dateId);
|
||||
|
||||
try {
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($dateId, $ttl) {
|
||||
$item->expiresAfter($ttl);
|
||||
|
||||
return $this->getAvailabilityData($dateId);
|
||||
});
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->logger->error('Cache error in getAvailabilityDataCached', [
|
||||
'dateId' => $dateId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
// Fallback to direct API call
|
||||
return $this->getAvailabilityData($dateId);
|
||||
}
|
||||
return $this->getAvailabilityData($dateId, cached: true, ttl: $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -606,7 +653,8 @@ class TravelDataService
|
||||
{
|
||||
try {
|
||||
$insurances = $this->insuranceLoader->loadAll();
|
||||
$travel->insurances = array_values($insurances);
|
||||
// Keep insurances indexed by ID for efficient lookups
|
||||
$travel->insurances = $insurances;
|
||||
|
||||
// Hydrate package relationships after loading
|
||||
// Packages lose their containedInsurances during serialization, so rebuild them
|
||||
|
||||
Reference in New Issue
Block a user