From 9eb3ac347e6df2cc14adc1265aff0b9ef419d550 Mon Sep 17 00:00:00 2001 From: Bartosz Kubicki Date: Fri, 28 Oct 2022 13:02:11 +0200 Subject: [PATCH] Fix for pagination calculation error --- src/Source/Webapi.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Source/Webapi.php b/src/Source/Webapi.php index a7769a2..c61ecf3 100644 --- a/src/Source/Webapi.php +++ b/src/Source/Webapi.php @@ -44,7 +44,7 @@ public function __construct( ?FilterDecoratorInterface $dataRequestFilterDecorator = null ) { $this->idField = $idField; - $this->sourceId = $sourceId; + $this->sourceId = sprintf('%s_%s', $sourceId, date('Y_m_d H:i:s')); $this->pagingManager = $pagingManager; $this->countRequestFactory = $countRequestFactory; $this->countResponseHandler = $countResponseHandler; @@ -71,7 +71,7 @@ public function count(): int public function traverse(callable $onSuccess, callable $onError, Report $report): void { try { - $totalNumberOfItems = $this->count(); + $totalNumberOfItems = $this->countAll(); $pagesAmount = ceil($totalNumberOfItems / $this->dataRequestPageSize); for ( @@ -98,6 +98,12 @@ public function getSourceId(): string return $this->sourceId; } + private function countAll(): int + { + $response = $this->httpClient->sendRequest($this->countRequestFactory->create()); + return $this->countResponseHandler->handle($response); + } + private function getPageToStartFrom(): int { return $this->pagingManager->getValue() === null ? 1 : (int) $this->pagingManager->getValue();