Use CollectionIterator instead of manual iteration here
This commit is contained in:
parent
c6305508bf
commit
447cdb3481
@ -416,21 +416,9 @@ class CollectionsService
|
|||||||
if ( $collection->hasField( 'totalItems' ) && is_numeric( $collection['totalItems'] ) ) {
|
if ( $collection->hasField( 'totalItems' ) && is_numeric( $collection['totalItems'] ) ) {
|
||||||
return intval( $collection['totalItems'] );
|
return intval( $collection['totalItems'] );
|
||||||
} else {
|
} else {
|
||||||
$itemsField = 'items';
|
|
||||||
if ( $collection->hasField( 'type' ) && $collection['type'] == 'OrderedCollection' ) {
|
|
||||||
$itemsField = 'orderedItems';
|
|
||||||
}
|
|
||||||
if ( ! ( $collection->hasField( $itemsField ) && $collection[$itemsField] instanceof ActivityPubObject ) ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
$items = $collection[$itemsField];
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$idx = 0;
|
foreach ( CollectionIterator::iterateCollection( $collection ) as $item ) {
|
||||||
$currentItem = $items[$idx];
|
$count += 1;
|
||||||
while ( $currentItem ) {
|
|
||||||
$count++;
|
|
||||||
$idx++;
|
|
||||||
$currentItem = $items[$idx];
|
|
||||||
}
|
}
|
||||||
$collection = $this->objectsService->update( $collection['id'], array( 'totalItems' => strval( $count ) ) );
|
$collection = $this->objectsService->update( $collection['id'], array( 'totalItems' => strval( $count ) ) );
|
||||||
return $count;
|
return $count;
|
||||||
|
Loading…
Reference in New Issue
Block a user