Skip to content
Snippets Groups Projects
Commit dbb6e141 authored by Fabian Galinski's avatar Fabian Galinski :pouting_cat:
Browse files

[BUGFIX] Sometimes an objectstorage dosen't returns all values

parent 256a0b0b
No related branches found
Tags 1.6.0
No related merge requests found
......@@ -26,6 +26,7 @@ namespace SGalinski\SgRest\Service;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgImpulse\Domain\Model\Impulse;
use SGalinski\SgRest\Utility\PathUtility;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -73,6 +74,11 @@ class DataResolveService implements SingletonInterface {
*/
protected $dateFormat = DateTimeConverter::DEFAULT_DATE_FORMAT;
/**
* @var array
*/
protected $objectCache = [];
/**
* Setter for the nesting level property.
*
......@@ -123,9 +129,15 @@ class DataResolveService implements SingletonInterface {
*/
public function getArrayFromObject(AbstractEntity $object, $returnReference = FALSE, $nestingLevel = -1) {
$entityName = $this->getEntityName($object);
$identifier = (method_exists($object, 'getUid') ? $object->getUid() : 0);
$objectCacheKey = $entityName . '-' . $identifier . '-' . ($returnReference ? 1 : 0);
if (isset($this->objectCache[$objectCacheKey])) {
return $this->objectCache[$objectCacheKey];
}
$properties = $object->_getCleanProperties();
$identifier = (method_exists($object, 'getUid') ? $object->getUid() : 0);
if ($object instanceof FileReference && $identifier) {
return [
'href' => PathUtility::createFileUrl($object),
......@@ -166,6 +178,7 @@ class DataResolveService implements SingletonInterface {
}
}
$this->objectCache[$objectCacheKey] = $properties;
return $properties;
}
......@@ -199,7 +212,9 @@ class DataResolveService implements SingletonInterface {
}
if ($subObject instanceof ObjectStorage || $subObject instanceof \Traversable) {
foreach ($subObject as $item) {
// toArray() is necessary, because an ObjectStorage is losing it's index, if the child object references to
// the same storage. So it can happen, that not all objects are iterated.
foreach ($subObject->toArray() as $item) {
$result[] = $this->getArrayFromObject($item, !$returnReference, $nestingLevel);
}
} else {
......
......@@ -4,7 +4,7 @@
"description": "The extension provieds a basis REST environment. New endpoints provides a REST environment, so that other extensions only need to register them.",
"homepage": "https://www.sgalinski.de",
"license": "GPL-2.0+",
"version": "1.0.8",
"version": "1.0.9",
"require": {
"typo3/cms-core": ">=6.2.0,<8.0"
},
......
......@@ -19,7 +19,7 @@ $EM_CONF[$_EXTKEY] = array(
'modify_tables' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
'version' => '1.0.8',
'version' => '1.0.9',
'constraints' => array(
'depends' => array(
'typo3' => '6.2.0-7.6.99',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment