diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a5487955..308a2078 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,25 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/ActionTrigger/EventHandler/DefaultEventHandler.php - - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/Controller/Admin/ActivitiesController.php - - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 2 - path: src/Controller/Admin/CustomersController.php - - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/Controller/Admin/DuplicatesController.php - - message: "#^Parameter \\#1 \\$segments of class CustomerManagementFrameworkBundle\\\\CustomerList\\\\Filter\\\\CustomerSegment constructor expects array\\, array\\, CustomerManagementFrameworkBundle\\\\Model\\\\CustomerSegmentInterface\\> given\\.$#" reportUnmatched: false @@ -37,11 +17,6 @@ parameters: count: 1 path: src/CustomerView/DefaultCustomerView.php - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php - - message: "#^Result of && is always false\\.$#" count: 1 @@ -107,41 +82,11 @@ parameters: count: 1 path: src/Newsletter/ProviderHandler/Mailchimp/CliSyncProcessor.php - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 2 - path: src/Newsletter/Queue/DefaultNewsletterQueue.php - - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/RESTApi/CustomersHandler.php - - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/RESTApi/SegmentGroupsHandler.php - - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/RESTApi/SegmentsHandler.php - - message: "#^Call to an undefined method CustomerManagementFrameworkBundle\\\\RESTApi\\\\SegmentsOfCustomerHandler\\:\\:createRoute\\(\\)\\.$#" count: 1 path: src/RESTApi/SegmentsOfCustomerHandler.php - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/SegmentBuilder/AgeSegmentBuilder.php - - - - message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#" - count: 1 - path: src/SegmentManager/SegmentBuilderExecutor/DefaultSegmentBuilderExecutor.php - - message: "#^If condition is always false\\.$#" count: 1 diff --git a/src/ActionTrigger/EventHandler/DefaultEventHandler.php b/src/ActionTrigger/EventHandler/DefaultEventHandler.php index 2d3bd6bc..b4551b86 100644 --- a/src/ActionTrigger/EventHandler/DefaultEventHandler.php +++ b/src/ActionTrigger/EventHandler/DefaultEventHandler.php @@ -26,6 +26,7 @@ use CustomerManagementFrameworkBundle\Model\ActionTrigger\Rule; use CustomerManagementFrameworkBundle\Model\CustomerInterface; use CustomerManagementFrameworkBundle\Traits\LoggerAware; +use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface; use Knp\Component\Pager\PaginatorInterface; use Pimcore; use Pimcore\Model\DataObject\Service; @@ -114,15 +115,17 @@ public function handleCustomerListEvent(CustomerListEventInterface $event, RuleE sprintf('handleCustomerListEvent: found %s matching customers', $paginator->getTotalItemCount()) ); - $totalPages = $paginator->getPaginationData()['totalCount']; - for ($i = 1; $i <= $totalPages; $i++) { - $paginator = $this->paginator->paginate($listing, $i, 100); + if ($paginator instanceof SlidingPaginationInterface) { + $totalPages = $paginator->getPaginationData()['totalCount']; + for ($i = 1; $i <= $totalPages; $i++) { + $paginator = $this->paginator->paginate($listing, $i, 100); - foreach ($paginator as $customer) { - $this->handleActionsForCustomer($rule, $customer, $environment); - } + foreach ($paginator as $customer) { + $this->handleActionsForCustomer($rule, $customer, $environment); + } - Pimcore::collectGarbage(); + Pimcore::collectGarbage(); + } } } } diff --git a/src/Controller/Admin/ActivitiesController.php b/src/Controller/Admin/ActivitiesController.php index 05835754..47ab299a 100644 --- a/src/Controller/Admin/ActivitiesController.php +++ b/src/Controller/Admin/ActivitiesController.php @@ -17,6 +17,7 @@ use CustomerManagementFrameworkBundle\ActivityStore\MariaDb; use CustomerManagementFrameworkBundle\CustomerProvider\CustomerProviderInterface; +use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface; use Knp\Component\Pager\PaginatorInterface; use Pimcore\Controller\KernelControllerEventInterface; use Pimcore\Controller\UserAwareController; @@ -78,7 +79,7 @@ public function listAction(Request $request, CustomerProviderInterface $customer 'types' => $types, 'selectedType' => $type, 'activities' => $paginator, - 'paginationVariables' => $paginator->getPaginationData(), + 'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [], 'customer' => $customer, 'activityView' => \Pimcore::getContainer()->get('cmf.activity_view'), ] diff --git a/src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php b/src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php index f1bc3b83..6d508071 100644 --- a/src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php +++ b/src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php @@ -21,6 +21,7 @@ use CustomerManagementFrameworkBundle\Factory; use CustomerManagementFrameworkBundle\Model\CustomerInterface; use CustomerManagementFrameworkBundle\Traits\LoggerAware; +use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface; use Knp\Component\Pager\PaginatorInterface; use Pimcore\Db; use Pimcore\Logger; @@ -107,18 +108,20 @@ public function recreateIndex() $paginator = $this->paginator->paginate($customerList); $paginator->setItemNumberPerPage(200); - $totalPages = $paginator->getPaginationData()['pageCount']; - for ($pageNumber = 1; $pageNumber <= $totalPages; $pageNumber++) { - $logger->notice(sprintf('execute page %s of %s', $pageNumber, $totalPages)); - $paginator = $this->paginator->paginate($customerList, $pageNumber, 200); + if ($paginator instanceof SlidingPaginationInterface) { + $totalPages = $paginator->getPaginationData()['pageCount']; + for ($pageNumber = 1; $pageNumber <= $totalPages; $pageNumber++) { + $logger->notice(sprintf('execute page %s of %s', $pageNumber, $totalPages)); + $paginator = $this->paginator->paginate($customerList, $pageNumber, 200); - foreach ($paginator as $customer) { - $logger->notice(sprintf('update index for %s', (string)$customer)); + foreach ($paginator as $customer) { + $logger->notice(sprintf('update index for %s', (string)$customer)); - $this->updateDuplicateIndexForCustomer($customer, true); - } + $this->updateDuplicateIndexForCustomer($customer, true); + } - \Pimcore::collectGarbage(); + \Pimcore::collectGarbage(); + } } } diff --git a/src/Newsletter/Queue/DefaultNewsletterQueue.php b/src/Newsletter/Queue/DefaultNewsletterQueue.php index af80cc2a..e81c95a5 100644 --- a/src/Newsletter/Queue/DefaultNewsletterQueue.php +++ b/src/Newsletter/Queue/DefaultNewsletterQueue.php @@ -22,6 +22,7 @@ use CustomerManagementFrameworkBundle\Newsletter\Queue\Item\DefaultNewsletterQueueItem; use CustomerManagementFrameworkBundle\Newsletter\Queue\Item\NewsletterQueueItemInterface; use CustomerManagementFrameworkBundle\Traits\ApplicationLoggerAware; +use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface; use Knp\Component\Pager\PaginatorInterface; use Pimcore\Db; use Pimcore\Model\DataObject\Service; @@ -213,24 +214,26 @@ protected function processAllItems(array $newsletterProviderHandlers, $forceUpda $list = $customerProvider->getList(); $paginator = $this->paginator->paginate($list, 1, $this->maxItemsPerRound); - $pageCount = $paginator->getPaginationData()['pageCount']; + if ($paginator instanceof SlidingPaginationInterface) { + $pageCount = $paginator->getPaginationData()['pageCount']; + + for ($i = 1; $i <= $pageCount; $i++) { + $paginator = $this->paginator->paginate($list, $i, $this->maxItemsPerRound); + $items = []; + foreach ($paginator as $customer) { + if ($item = $this->createUpdateItem($customer)) { + $items[] = $item; + } + } - for ($i = 1; $i <= $pageCount; $i++) { - $paginator = $this->paginator->paginate($list, $i, $this->maxItemsPerRound); - $items = []; - foreach ($paginator as $customer) { - if ($item = $this->createUpdateItem($customer)) { - $items[] = $item; + try { + $this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate); + } catch (\Exception $e) { + $this->getLogger()->error('newsletter queue processing exception: ' . $e->getMessage()); } - } - try { - $this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate); - } catch (\Exception $e) { - $this->getLogger()->error('newsletter queue processing exception: ' . $e->getMessage()); + \Pimcore::collectGarbage(); } - - \Pimcore::collectGarbage(); } } diff --git a/src/SegmentBuilder/AgeSegmentBuilder.php b/src/SegmentBuilder/AgeSegmentBuilder.php index 34c3b97f..581da06e 100644 --- a/src/SegmentBuilder/AgeSegmentBuilder.php +++ b/src/SegmentBuilder/AgeSegmentBuilder.php @@ -19,6 +19,7 @@ use CustomerManagementFrameworkBundle\Model\CustomerInterface; use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface; use CustomerManagementFrameworkBundle\Traits\LoggerAware; +use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface; use Pimcore\Model\Tool\TmpStore; class AgeSegmentBuilder extends AbstractSegmentBuilder @@ -143,13 +144,15 @@ public function maintenance(SegmentManagerInterface $segmentManager) $paginator = $this->paginator->paginate($list, 1, 100); - $pageCount = $paginator->getPaginationData()['pageCount']; - for ($i = 1; $i <= $pageCount; $i++) { - $paginator = $this->paginator->paginate($list, $i, 100); + if ($paginator instanceof SlidingPaginationInterface) { + $pageCount = $paginator->getPaginationData()['pageCount']; + for ($i = 1; $i <= $pageCount; $i++) { + $paginator = $this->paginator->paginate($list, $i, 100); - foreach ($paginator as $customer) { - $this->calculateSegments($customer, $segmentManager); - $segmentManager->saveMergedSegments($customer); + foreach ($paginator as $customer) { + $this->calculateSegments($customer, $segmentManager); + $segmentManager->saveMergedSegments($customer); + } } } } diff --git a/src/SegmentManager/SegmentBuilderExecutor/DefaultSegmentBuilderExecutor.php b/src/SegmentManager/SegmentBuilderExecutor/DefaultSegmentBuilderExecutor.php index 043ca76a..d75a40a9 100644 --- a/src/SegmentManager/SegmentBuilderExecutor/DefaultSegmentBuilderExecutor.php +++ b/src/SegmentManager/SegmentBuilderExecutor/DefaultSegmentBuilderExecutor.php @@ -21,6 +21,7 @@ use CustomerManagementFrameworkBundle\SegmentBuilder\SegmentBuilderInterface; use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface; use CustomerManagementFrameworkBundle\Traits\LoggerAware; +use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface; use Knp\Component\Pager\PaginatorInterface; use Pimcore\Db; use Pimcore\Model\DataObject\Concrete; @@ -166,7 +167,10 @@ public function buildCalculatedSegments( $paginator = $this->paginator->paginate($idList, 1, $pageSize); $totalAmount = $paginator->getTotalItemCount(); - $totalPages = $paginator->getPaginationData()['pageCount']; + $totalPages = 0; + if ($paginator instanceof SlidingPaginationInterface) { + $totalPages = $paginator->getPaginationData()['pageCount']; + } $startPage = $desiredStartPage !== null && $desiredStartPage > 0 ? min($totalPages, $desiredStartPage) : 1; $endPage = $totalPages;