From 447cdb348172f17431e92a389c35e85d7c9bd681 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 11 Apr 2019 23:46:18 -0400 Subject: [PATCH] Use CollectionIterator instead of manual iteration here --- src/Objects/CollectionsService.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Objects/CollectionsService.php b/src/Objects/CollectionsService.php index 1832293..0774bb3 100644 --- a/src/Objects/CollectionsService.php +++ b/src/Objects/CollectionsService.php @@ -416,21 +416,9 @@ class CollectionsService if ( $collection->hasField( 'totalItems' ) && is_numeric( $collection['totalItems'] ) ) { return intval( $collection['totalItems'] ); } 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; - $idx = 0; - $currentItem = $items[$idx]; - while ( $currentItem ) { - $count++; - $idx++; - $currentItem = $items[$idx]; + foreach ( CollectionIterator::iterateCollection( $collection ) as $item ) { + $count += 1; } $collection = $this->objectsService->update( $collection['id'], array( 'totalItems' => strval( $count ) ) ); return $count;