Skip to content

Commit

Permalink
Merge pull request #3 from basilicom/recursion-prevention-patch-1
Browse files Browse the repository at this point in the history
Prevent recursion when exporting object fields
  • Loading branch information
christophluehr authored Dec 18, 2020
2 parents 470e955 + 45ef217 commit 07a80ec
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Service/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Xml

private $language = null;

private $exportCache = []; // stores id

/**
* @param string|bool $xslt
*/
Expand Down Expand Up @@ -107,6 +109,8 @@ private function exportObject(DataObject $object, $useRecursion=true, $addFields
{
$objectData = [];

$this->exportCache[$object->getId()] = true; // remember that we are exported this object

$className = 'Folder';

if ($object->getType() !== 'folder') {
Expand Down Expand Up @@ -224,7 +228,13 @@ private function getForTypeManyToManyObjectRelation($object, $fieldname): array

if (is_iterable($relationObjects)) {
foreach($relationObjects as $relationObject) {
$exportObject = $this->exportObject($relationObject, false, !$this->omitRelationObjectFields);

$addFields = !$this->omitRelationObjectFields;

if ($this->exportCache[$relationObject->getId()]) {
$addFields = false;
}
$exportObject = $this->exportObject($relationObject, false, $addFields);

if (!array_key_exists($exportObject['_attributes']['class'], $relations)) {
$relations[$exportObject['_attributes']['class']] = [];
Expand Down Expand Up @@ -254,7 +264,13 @@ private function getForTypeAdvancedManyToManyObjectRelation($object, $fieldname)
if (is_iterable($relationMetaObjects)) {
foreach ($object->$getterFunction() as $relationMetaObject) {
$relationObject = $relationMetaObject->getObject();
$exportObject = $this->exportObject($relationObject, false, !$this->omitRelationObjectFields);

$addFields = !$this->omitRelationObjectFields;

if ($this->exportCache[$relationObject->getId()]) {
$addFields = false;
}
$exportObject = $this->exportObject($relationObject, false, $addFields);
$data = $relationMetaObject->getData();

$meta['pc:relation'][] = [
Expand Down

0 comments on commit 07a80ec

Please sign in to comment.