fix(custom-fields) : empêche EntityNotFoundException sur CustomField orphelin
Auto Tag Develop / tag (push) Successful in 9s
Auto Tag Develop / tag (push) Successful in 9s
Même pattern que la fix Piece (003e419) : helper ensureCustomFieldExists()
qui force l'init du proxy lazy et catch EntityNotFoundException dans
MachineStructureController::normalizeCustomFieldValues() et
CustomFieldValueController::normalizeCustomFieldValue(). Les CFV pointant
vers un CustomField supprimé sont silencieusement skippés au lieu de
crasher la vue machine entière.
This commit is contained in:
@@ -315,22 +315,40 @@ class CustomFieldValueController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as ensurePieceExists() but for CustomField, to keep orphan CFVs from
|
||||
* crashing the value endpoints.
|
||||
*/
|
||||
private function ensureCustomFieldExists(?CustomField $cf): ?CustomField
|
||||
{
|
||||
if (null === $cf) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$cf->getId();
|
||||
|
||||
return $cf;
|
||||
} catch (EntityNotFoundException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeCustomFieldValue(CustomFieldValue $value): array
|
||||
{
|
||||
$customField = $value->getCustomField();
|
||||
$customField = $this->ensureCustomFieldExists($value->getCustomField());
|
||||
|
||||
return [
|
||||
'id' => $value->getId(),
|
||||
'value' => $value->getValue(),
|
||||
'customFieldId' => $customField->getId(),
|
||||
'customField' => [
|
||||
'customFieldId' => $customField?->getId(),
|
||||
'customField' => $customField ? [
|
||||
'id' => $customField->getId(),
|
||||
'name' => $customField->getName(),
|
||||
'type' => $customField->getType(),
|
||||
'required' => $customField->isRequired(),
|
||||
'options' => $customField->getOptions(),
|
||||
'orderIndex' => $customField->getOrderIndex(),
|
||||
],
|
||||
] : null,
|
||||
'machineId' => $value->getMachine()?->getId(),
|
||||
'composantId' => $value->getComposant()?->getId(),
|
||||
'pieceId' => $value->getPiece()?->getId(),
|
||||
|
||||
Reference in New Issue
Block a user