Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b318ce5d6 | |||
| c10ab08803 | |||
| 85d4726415 | |||
| af13dc0237 |
+1
-1
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '1.9.40'
|
||||
app.version: '1.9.42'
|
||||
|
||||
@@ -298,8 +298,9 @@ class CustomFieldValueController extends AbstractController
|
||||
|
||||
/**
|
||||
* Returns the Piece if its underlying row still exists in DB, otherwise null.
|
||||
* Forces a lazy proxy to initialize via getId() and swallows EntityNotFoundException
|
||||
* so an orphan link to a deleted piece doesn't crash custom-field value writes.
|
||||
* getId() on a Doctrine proxy does NOT trigger __load(), so we force the proxy
|
||||
* to initialize explicitly to handle orphan links here instead of crashing on
|
||||
* the first real getter.
|
||||
*/
|
||||
private function ensurePieceExists(?Piece $piece): ?Piece
|
||||
{
|
||||
@@ -307,7 +308,7 @@ class CustomFieldValueController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$piece->getId();
|
||||
$this->entityManager->initializeObject($piece);
|
||||
|
||||
return $piece;
|
||||
} catch (EntityNotFoundException) {
|
||||
@@ -315,22 +316,42 @@ class CustomFieldValueController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getId() on a Doctrine proxy returns the identifier without triggering __load(),
|
||||
* so it never raises EntityNotFoundException even if the row is gone. Force the
|
||||
* proxy to initialize explicitly so an orphan CFV is handled here instead of
|
||||
* crashing on the first real getter.
|
||||
*/
|
||||
private function ensureCustomFieldExists(?CustomField $cf): ?CustomField
|
||||
{
|
||||
if (null === $cf) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$this->entityManager->initializeObject($cf);
|
||||
|
||||
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(),
|
||||
|
||||
@@ -815,8 +815,9 @@ class MachineStructureController extends AbstractController
|
||||
|
||||
/**
|
||||
* Returns the Piece if its underlying row still exists in DB, otherwise null.
|
||||
* Forces a lazy proxy to initialize via getId() and swallows EntityNotFoundException
|
||||
* so a stale FK (orphan link to a deleted piece) doesn't crash the whole machine view.
|
||||
* getId() on a Doctrine proxy does NOT trigger __load() (the id is the key used
|
||||
* to build the proxy), so we force initialization via initializeObject() to
|
||||
* surface a stale FK here instead of crashing on the first real getter.
|
||||
*/
|
||||
private function ensurePieceExists(?Piece $piece): ?Piece
|
||||
{
|
||||
@@ -824,7 +825,7 @@ class MachineStructureController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$piece->getId();
|
||||
$this->entityManager->initializeObject($piece);
|
||||
|
||||
return $piece;
|
||||
} catch (EntityNotFoundException) {
|
||||
@@ -832,6 +833,26 @@ class MachineStructureController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the CustomField if its underlying row still exists, otherwise null.
|
||||
* getId() on a Doctrine proxy does NOT trigger __load() — the id is the key used
|
||||
* to build the proxy. We force initialization explicitly so a stale FK to a
|
||||
* deleted CustomField surfaces here instead of crashing on getName() later.
|
||||
*/
|
||||
private function ensureCustomFieldExists(?CustomField $cf): ?CustomField
|
||||
{
|
||||
if (null === $cf) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$this->entityManager->initializeObject($cf);
|
||||
|
||||
return $cf;
|
||||
} catch (EntityNotFoundException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizePiece(Piece $piece): array
|
||||
{
|
||||
$type = $piece->getTypePiece();
|
||||
@@ -942,7 +963,10 @@ class MachineStructureController extends AbstractController
|
||||
if (!$cfv instanceof CustomFieldValue) {
|
||||
continue;
|
||||
}
|
||||
$cf = $cfv->getCustomField();
|
||||
$cf = $this->ensureCustomFieldExists($cfv->getCustomField());
|
||||
if (null === $cf) {
|
||||
continue;
|
||||
}
|
||||
$items[] = [
|
||||
'id' => $cfv->getId(),
|
||||
'value' => $cfv->getValue(),
|
||||
|
||||
Reference in New Issue
Block a user