Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4.0' into use_php_cs_fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
blankse committed Apr 26, 2024
2 parents 2a5784b + 3bc2cbe commit 67a1121
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 112 deletions.
55 changes: 0 additions & 55 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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\\<Pimcore\\\\Model\\\\DataObject\\\\CustomerSegment\\>, array\\<int\\<0, max\\>, CustomerManagementFrameworkBundle\\\\Model\\\\CustomerSegmentInterface\\> given\\.$#"
reportUnmatched: false
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/ActionTrigger/EventHandler/DefaultEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Admin/ActivitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
]
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Admin/CustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
use CustomerManagementFrameworkBundle\Model\CustomerSegmentInterface;
use CustomerManagementFrameworkBundle\Model\CustomerView\FilterDefinition;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Pimcore\Db;
use Pimcore\Model\DataObject\AbstractObject;
use Pimcore\Model\DataObject\Concrete;
Expand Down Expand Up @@ -96,7 +97,7 @@ public function listAction(Request $request): Response
if ($request->isXmlHttpRequest()) {
return $this->render($customerView->getOverviewWrapperTemplate(), [
'paginator' => $paginator,
'paginationVariables' => $paginator->getPaginationData(),
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
'customerView' => $customerView,
'idField' => Service::getVersionDependentDatabaseColumnName('id')
]);
Expand All @@ -108,7 +109,7 @@ public function listAction(Request $request): Response
'filters' => $filters,
'errors' => $errors,
'paginator' => $paginator,
'paginationVariables' => $paginator->getPaginationData(),
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
'customerView' => $customerView,
'searchBarFields' => $this->getSearchHelper()->getConfiguredSearchBarFields(),
'request' => $request,
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Admin/DuplicatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CustomerManagementFrameworkBundle\Controller\Admin;
use CustomerManagementFrameworkBundle\CustomerList\SearchHelper;
use CustomerManagementFrameworkBundle\DuplicatesIndex\DuplicatesIndexInterface;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Pimcore\Model\DataObject\AbstractObject;
use Pimcore\Model\DataObject\Service;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function listAction(Request $request, DuplicatesIndexInterface $duplicate
'@PimcoreCustomerManagementFramework/admin/duplicates/list.html.twig',
[
'paginator' => $paginator,
'paginationVariables' => $paginator->getPaginationData(),
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
'duplicates' => $paginator->getItems(),
'duplicatesView' => \Pimcore::getContainer()->get('cmf.customer_duplicates_view'),
'searchBarFields' => $this->getSearchHelper()->getConfiguredSearchBarFields(),
Expand Down
21 changes: 12 additions & 9 deletions src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}

Expand Down
57 changes: 31 additions & 26 deletions src/Newsletter/Queue/DefaultNewsletterQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];

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;
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;
}
}
}

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();
}
}
}

Expand All @@ -249,20 +252,22 @@ protected function processItemsFromQueue(array $newsletterProviderHandlers, $for
$rows = $db->fetchAllAssociative((string)$select);

$paginator = $this->paginator->paginate($rows, 1, $this->maxItemsPerRound);
$pageCount = $paginator->getPaginationData()['pageCount'];

for ($i = 1; $i <= $pageCount; $i++) {
$paginator = $this->paginator->paginate($rows, $i, $this->maxItemsPerRound);
$items = [];
foreach ($paginator as $row) {
if ($item = $this->createItemFromData($row)) {
$items[] = $item;
if ($paginator instanceof SlidingPaginationInterface) {
$pageCount = $paginator->getPaginationData()['pageCount'];

for ($i = 1; $i <= $pageCount; $i++) {
$paginator = $this->paginator->paginate($rows, $i, $this->maxItemsPerRound);
$items = [];
foreach ($paginator as $row) {
if ($item = $this->createItemFromData($row)) {
$items[] = $item;
}
}
}

$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);
$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);

\Pimcore::collectGarbage();
\Pimcore::collectGarbage();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/RESTApi/ActivitiesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator;
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Symfony\Component\HttpFoundation\Request;

class ActivitiesHandler extends AbstractHandler implements CrudHandlerInterface
Expand Down Expand Up @@ -56,7 +57,7 @@ public function listRecords(Request $request)

$result = [
'page' => $page,
'totalPages' => $paginator->getPaginationData()['pageCount'],
'totalPages' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData()['pageCount'] : 0,
'timestamp' => $timestamp,
'data' => [],
];
Expand Down
3 changes: 2 additions & 1 deletion src/RESTApi/CustomersHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator;
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Model\DataObject\Customer;
use Pimcore\Model\DataObject\Service;
Expand Down Expand Up @@ -89,7 +90,7 @@ public function listRecords(Request $request)
return new Response(
[
'page' => $paginator->getCurrentPageNumber(),
'totalPages' => $paginator->getPaginationData()['pageCount'],
'totalPages' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData()['pageCount'] : 0,
'timestamp' => $timestamp,
'data' => $result,
]
Expand Down
3 changes: 2 additions & 1 deletion src/RESTApi/SegmentGroupsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator;
use CustomerManagementFrameworkBundle\Service\ObjectToArray;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Pimcore\Model\DataObject\CustomerSegmentGroup;
use Pimcore\Model\DataObject\Service;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function listRecords(Request $request)
return new Response(
[
'page' => $paginator->getCurrentPageNumber(),
'totalPages' => $paginator->getPaginationData()['pageCount'],
'totalPages' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData()['pageCount'] : 0,
'timestamp' => $timestamp,
'data' => $result,
]
Expand Down
3 changes: 2 additions & 1 deletion src/RESTApi/SegmentsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator;
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\DataObject\CustomerSegment;
use Pimcore\Model\DataObject\CustomerSegmentGroup;
Expand Down Expand Up @@ -59,7 +60,7 @@ public function listRecords(Request $request)
return new Response(
[
'page' => $paginator->getCurrentPageNumber(),
'totalPages' => $paginator->getPaginationData()['pageCount'],
'totalPages' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData()['pageCount'] : 0,
'timestamp' => $timestamp,
'data' => $result,
]
Expand Down
15 changes: 9 additions & 6 deletions src/SegmentBuilder/AgeSegmentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down

0 comments on commit 67a1121

Please sign in to comment.