Commit 7258b524 authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Benni Mack

[BUGFIX] Prematurely end data array processing on invalid item

In case the amount of items, shown in the workspace module,
does not exceed the pagination limit - default 30 - the items
array was previously filled with invalid items till the limit
was reached.

This is now fixed by a guard clause which prematurely ends the
processing (the corresponding loop) as soon as no more item
exists.

This guard clause is also implemented in the calculation of
the start value. Usually there shouldn't be any invalid items,
but as such behaviour can not always be ruled out, especially
on multi-user systems, it seems reasonable to add it here, too.

Resolves: #93915
Relates: #93645
Releases: master, 10.4
Change-Id: I619c9063f12c3b1d5c446f9ca1a0e35e646f90f7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68779Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 881906ee
......@@ -118,15 +118,14 @@ class GridDataService implements LoggerAwareInterface
} else {
throw new \InvalidArgumentException('No such workspace defined', 1476048304);
}
$data = [];
$data['data'] = [];
$this->generateDataArray($versions, $filterTxt);
// Only count parent records for pagination
$data['total'] = count(array_filter($this->dataArray, static function ($element) {
return (int)($element[self::GridColumn_CollectionLevel] ?? 0) === 0;
}));
$data['data'] = $this->getDataArray($start, $limit);
return $data;
return [
// Only count parent records for pagination
'total' => count(array_filter($this->dataArray, static function ($element) {
return (int)($element[self::GridColumn_CollectionLevel] ?? 0) === 0;
})),
'data' => $this->getDataArray($start, $limit)
];
}
/**
......@@ -670,6 +669,15 @@ class GridDataService implements LoggerAwareInterface
// parentRecordsCount only takes the parent records into account
$recordsCount = $parentRecordsCount = 0;
while ($parentRecordsCount < $start) {
// As soon as no more item exists in the dataArray, the loop needs to end
// prematurely to prevent invalid items which would may led to some unexpected
// behaviour. Note: This usually should never happen since these records must
// exists => As they were responsible for increasing the start value. However to
// prevent errors in case multiple different users manipulate the records count
// somehow simultaneously, we apply this check to be save.
if (!isset($this->dataArray[$recordsCount])) {
break;
}
// Loop over the dataArray until we found enough parent records
$item = $this->dataArray[$recordsCount];
if (($item[self::GridColumn_CollectionLevel] ?? 0) === 0) {
......@@ -706,6 +714,11 @@ class GridDataService implements LoggerAwareInterface
// parentRecordsCount only takes the parent records into account.
$itemsCount = $parentRecordsCount = $start;
while ($parentRecordsCount < $end) {
// As soon as no more item exists in the dataArray, the loop needs to end
// prematurely to prevent invalid items which would trigger JavaScript errors.
if (!isset($this->dataArray[$itemsCount])) {
break;
}
// Loop over the dataArray until we found enough parent records
$item = $this->dataArray[$itemsCount];
// Add the item to the $dataArrayPart
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment