fix: report an unresolvable hotel instead of failing on it

This commit is contained in:
fromme committed 2026-09-29 15:27:44 +02:00
1 parent 72be779038
commit 2329fe17a0
6 files changed
+317 -7

No files matched your search

@@ -0,0 +1,21 @@
<?php
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* The chosen hotel must still resolve against MyE&P's base data.
*
* Everything a destination records about its house is derived from that lookup - name, code,
* cost unit, country - so an id that no longer resolves cannot produce a complete row. It used
* to reach App\Controller\Administrative\System\Destination\DestinationTrait::updateEntity()
* and fail there on a null, which is a 500 on a form submit rather than a message on a field.
*/
#[\Attribute]
class ResolvableHotel extends Constraint
{
public string $unknownMessage = 'Dieser Vertragspartner ist nicht mehr verfügbar';
public string $unavailableMessage = 'Die Stammdaten sind gerade nicht erreichbar – bitte später erneut versuchen';
}
@@ -0,0 +1,40 @@
<?php
namespace App\Validator\Constraints;
use App\BusProNet\DataProvider\HotelDataProvider;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class ResolvableHotelValidator extends ConstraintValidator
{
public function __construct(private readonly HotelDataProvider $hotelDataProvider)
{
}
public function validate(mixed $value, Constraint $constraint): void
{
if (false === $constraint instanceof ResolvableHotel) {
return;
}
// Whether a hotel was chosen at all is NotBlank's business, not this one's.
if (null === $value || '' === $value) {
return;
}
// An empty list is MyE&P being unreachable rather than a bad choice: StaleWhileErrorCache
// answers [] instead of throwing, so this is the only place the two are still
// distinguishable. Reporting an outage as an invalid selection sends the operator looking
// for a different answer when the one they gave was right.
if ([] === $hotels = $this->hotelDataProvider->getAll()) {
$this->context->buildViolation($constraint->unavailableMessage)->addViolation();
return;
}
if (false === isset($hotels[(int) $value])) {
$this->context->buildViolation($constraint->unknownMessage)->addViolation();
}
}
}