Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b318ce5d6 | |||
| c10ab08803 | |||
| 85d4726415 | |||
| af13dc0237 |
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
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.
|
* Returns the Piece if its underlying row still exists in DB, otherwise null.
|
||||||
* Forces a lazy proxy to initialize via getId() and swallows EntityNotFoundException
|
* getId() on a Doctrine proxy does NOT trigger __load(), so we force the proxy
|
||||||
* so an orphan link to a deleted piece doesn't crash custom-field value writes.
|
* to initialize explicitly to handle orphan links here instead of crashing on
|
||||||
|
* the first real getter.
|
||||||
*/
|
*/
|
||||||
private function ensurePieceExists(?Piece $piece): ?Piece
|
private function ensurePieceExists(?Piece $piece): ?Piece
|
||||||
{
|
{
|
||||||
@@ -307,7 +308,7 @@ class CustomFieldValueController extends AbstractController
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$piece->getId();
|
$this->entityManager->initializeObject($piece);
|
||||||
|
|
||||||
return $piece;
|
return $piece;
|
||||||
} catch (EntityNotFoundException) {
|
} 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
|
private function normalizeCustomFieldValue(CustomFieldValue $value): array
|
||||||
{
|
{
|
||||||
$customField = $value->getCustomField();
|
$customField = $this->ensureCustomFieldExists($value->getCustomField());
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $value->getId(),
|
'id' => $value->getId(),
|
||||||
'value' => $value->getValue(),
|
'value' => $value->getValue(),
|
||||||
'customFieldId' => $customField->getId(),
|
'customFieldId' => $customField?->getId(),
|
||||||
'customField' => [
|
'customField' => $customField ? [
|
||||||
'id' => $customField->getId(),
|
'id' => $customField->getId(),
|
||||||
'name' => $customField->getName(),
|
'name' => $customField->getName(),
|
||||||
'type' => $customField->getType(),
|
'type' => $customField->getType(),
|
||||||
'required' => $customField->isRequired(),
|
'required' => $customField->isRequired(),
|
||||||
'options' => $customField->getOptions(),
|
'options' => $customField->getOptions(),
|
||||||
'orderIndex' => $customField->getOrderIndex(),
|
'orderIndex' => $customField->getOrderIndex(),
|
||||||
],
|
] : null,
|
||||||
'machineId' => $value->getMachine()?->getId(),
|
'machineId' => $value->getMachine()?->getId(),
|
||||||
'composantId' => $value->getComposant()?->getId(),
|
'composantId' => $value->getComposant()?->getId(),
|
||||||
'pieceId' => $value->getPiece()?->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.
|
* Returns the Piece if its underlying row still exists in DB, otherwise null.
|
||||||
* Forces a lazy proxy to initialize via getId() and swallows EntityNotFoundException
|
* getId() on a Doctrine proxy does NOT trigger __load() (the id is the key used
|
||||||
* so a stale FK (orphan link to a deleted piece) doesn't crash the whole machine view.
|
* 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
|
private function ensurePieceExists(?Piece $piece): ?Piece
|
||||||
{
|
{
|
||||||
@@ -824,7 +825,7 @@ class MachineStructureController extends AbstractController
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$piece->getId();
|
$this->entityManager->initializeObject($piece);
|
||||||
|
|
||||||
return $piece;
|
return $piece;
|
||||||
} catch (EntityNotFoundException) {
|
} 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
|
private function normalizePiece(Piece $piece): array
|
||||||
{
|
{
|
||||||
$type = $piece->getTypePiece();
|
$type = $piece->getTypePiece();
|
||||||
@@ -942,7 +963,10 @@ class MachineStructureController extends AbstractController
|
|||||||
if (!$cfv instanceof CustomFieldValue) {
|
if (!$cfv instanceof CustomFieldValue) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$cf = $cfv->getCustomField();
|
$cf = $this->ensureCustomFieldExists($cfv->getCustomField());
|
||||||
|
if (null === $cf) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$items[] = [
|
$items[] = [
|
||||||
'id' => $cfv->getId(),
|
'id' => $cfv->getId(),
|
||||||
'value' => $cfv->getValue(),
|
'value' => $cfv->getValue(),
|
||||||
|
|||||||
Reference in New Issue
Block a user