Skip to content

Commit d218bf6

Browse files
committed
[BUGFIX] Avoid using null as array key in extbase Backend
Using `NULL` as array key is converted to an empty string in PHP and is deprecated since PHP8.5.0, honored with following `E_DEPRECATED` error: Using null as an array offset is deprecated, use an empty string instead Extbase `\TYPO3\CMS\Extbase\Persistence\Generic\Backend` is modified now to mitigate using `NULL` as possible array key in following methods: * `Backend::insertRelationInRelationtable()` * `Backend::updateRelationInRelationTable()` * `Backend::deleteAllRelationsFromRelationtable()` * `Backend::deleteRelationFromRelationtable()` Resolves: #108347 Releases: main, 13.4, 12.4 Change-Id: I0d3fdeac05f48a5164125d2671ffc02d1d050937 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/91911 Tested-by: Stefan Bürk <[email protected]> Tested-by: Anja Leichsenring <[email protected]> Reviewed-by: Christian Kuhn <[email protected]> Reviewed-by: Stefan Bürk <[email protected]> Tested-by: Christian Kuhn <[email protected]> Tested-by: core-ci <[email protected]> Reviewed-by: Anja Leichsenring <[email protected]> Reviewed-by: Oliver Klee <[email protected]>
1 parent 0c62b2d commit d218bf6

File tree

1 file changed

+31
-17
lines changed
  • typo3/sysext/extbase/Classes/Persistence/Generic

1 file changed

+31
-17
lines changed

typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,16 @@ protected function insertRelationInRelationtable(
615615
if ($parentObject->_getProperty(AbstractDomainObject::PROPERTY_LOCALIZED_UID) !== null) {
616616
$parentUid = $parentObject->_getProperty(AbstractDomainObject::PROPERTY_LOCALIZED_UID);
617617
}
618-
$row = [
619-
$columnMap->parentKeyFieldName => (int)$parentUid,
620-
$columnMap->childKeyFieldName => (int)$object->getUid(),
621-
$columnMap->childSortByFieldName => $sortingPosition ?? 0,
622-
];
618+
$row = [];
619+
if ($columnMap->parentKeyFieldName !== null) {
620+
$row[$columnMap->parentKeyFieldName] = (int)$parentUid;
621+
}
622+
if ($columnMap->childKeyFieldName !== null) {
623+
$row[$columnMap->childKeyFieldName] = (int)$object->getUid();
624+
}
625+
if ($columnMap->childSortByFieldName !== null) {
626+
$row[$columnMap->childSortByFieldName] = $sortingPosition ?? 0;
627+
}
623628
$relationTableName = $columnMap->relationTableName;
624629
if ($this->tcaSchemaFactory->has($relationTableName)) {
625630
$row[AbstractDomainObject::PROPERTY_PID] = $this->determineStoragePageIdForNewRecord();
@@ -641,11 +646,16 @@ protected function updateRelationInRelationTable(
641646
): bool {
642647
$dataMap = $this->dataMapFactory->buildDataMap(get_class($parentObject));
643648
$columnMap = $dataMap->getColumnMap($propertyName);
644-
$row = [
645-
$columnMap->parentKeyFieldName => (int)$parentObject->getUid(),
646-
$columnMap->childKeyFieldName => (int)$object->getUid(),
647-
$columnMap->childSortByFieldName => $sortingPosition,
648-
];
649+
$row = [];
650+
if ($columnMap->parentKeyFieldName !== null) {
651+
$row[$columnMap->parentKeyFieldName] = (int)$parentObject->getUid();
652+
}
653+
if ($columnMap->childKeyFieldName !== null) {
654+
$row[$columnMap->childKeyFieldName] = (int)$object->getUid();
655+
}
656+
if ($columnMap->childSortByFieldName !== null) {
657+
$row[$columnMap->childSortByFieldName] = $sortingPosition;
658+
}
649659
$relationTableName = $columnMap->relationTableName;
650660
$row = array_merge($columnMap->relationTableMatchFields, $row);
651661
$this->storageBackend->updateRelationTableRow($relationTableName, $row);
@@ -664,9 +674,10 @@ protected function deleteAllRelationsFromRelationtable(
664674
$dataMap = $this->dataMapFactory->buildDataMap(get_class($parentObject));
665675
$columnMap = $dataMap->getColumnMap($parentPropertyName);
666676
$relationTableName = $columnMap->relationTableName;
667-
$relationMatchFields = [
668-
$columnMap->parentKeyFieldName => (int)$parentObject->getUid(),
669-
];
677+
$relationMatchFields = [];
678+
if ($columnMap->parentKeyFieldName !== null) {
679+
$relationMatchFields[$columnMap->parentKeyFieldName] = (int)$parentObject->getUid();
680+
}
670681
$relationMatchFields = array_merge($columnMap->relationTableMatchFields, $relationMatchFields);
671682
$this->storageBackend->removeRow($relationTableName, $relationMatchFields);
672683
return true;
@@ -683,10 +694,13 @@ protected function deleteRelationFromRelationtable(
683694
$dataMap = $this->dataMapFactory->buildDataMap(get_class($parentObject));
684695
$columnMap = $dataMap->getColumnMap($parentPropertyName);
685696
$relationTableName = $columnMap->relationTableName;
686-
$relationMatchFields = [
687-
$columnMap->parentKeyFieldName => (int)$parentObject->getUid(),
688-
$columnMap->childKeyFieldName => (int)$relatedObject->getUid(),
689-
];
697+
$relationMatchFields = [];
698+
if ($columnMap->parentKeyFieldName !== null) {
699+
$relationMatchFields[$columnMap->parentKeyFieldName] = (int)$parentObject->getUid();
700+
}
701+
if ($columnMap->childKeyFieldName !== null) {
702+
$relationMatchFields[$columnMap->childKeyFieldName] = (int)$relatedObject->getUid();
703+
}
690704
$relationMatchFields = array_merge($columnMap->relationTableMatchFields, $relationMatchFields);
691705
$this->storageBackend->removeRow($relationTableName, $relationMatchFields);
692706
return true;

0 commit comments

Comments
 (0)