Skip to content

Commit

Permalink
IBX-8470: Upgraded Pagerfanta to v3 for Symfony 6 (#462)
Browse files Browse the repository at this point in the history
For the list of Pagerfanta changes see #462


---------

Co-Authored-By: Dawid Parafiński <ViniTou@users.noreply.github.com>
  • Loading branch information
alongosz and ViniTou committed Dec 27, 2024
1 parent 525c4a2 commit 58f2bfb
Show file tree
Hide file tree
Showing 53 changed files with 1,241 additions and 1,202 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"liip/imagine-bundle": "^2.3",
"nelmio/cors-bundle": "^2.0",
"oneup/flysystem-bundle": "^4.4.2",
"pagerfanta/pagerfanta": "^2.1",
"pagerfanta/pagerfanta": "^3.6.2",
"psr/event-dispatcher": "^1.0",
"sensio/framework-extra-bundle": "^6.1",
"symfony-cmf/routing": "^3.0",
Expand Down
561 changes: 3 additions & 558 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

241 changes: 241 additions & 0 deletions phpstan-baseline.pagerfanta.neon

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- phpstan-baseline.neon
- phpstan-baseline.pagerfanta.neon

parameters:
level: 8
Expand Down
39 changes: 13 additions & 26 deletions src/bundle/Core/Command/CopySubtreeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,15 @@ class CopySubtreeCommand extends Command

protected static $defaultDescription = 'Copies a subtree from one Location to another';

/** @var \Ibexa\Contracts\Core\Repository\LocationService */
private $locationService;
private LocationService $locationService;

/** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */
private $permissionResolver;
private PermissionResolver $permissionResolver;

/** @var \Ibexa\Contracts\Core\Repository\UserService */
private $userService;
private UserService $userService;

/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
private $contentTypeService;
private ContentTypeService $contentTypeService;

/** @var \Ibexa\Contracts\Core\Repository\SearchService */
private $searchService;
private SearchService $searchService;

/**
* @param \Ibexa\Contracts\Core\Repository\LocationService $locationService
Expand All @@ -69,7 +64,7 @@ public function __construct(
$this->searchService = $searchService;
}

protected function configure()
protected function configure(): void
{
$this
->addArgument(
Expand All @@ -95,9 +90,10 @@ protected function configure()
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);
$this->permissionResolver->setCurrentUserReference(
Expand All @@ -106,11 +102,6 @@ protected function initialize(InputInterface $input, OutputInterface $output)
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @return int|null
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException
Expand Down Expand Up @@ -144,9 +135,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$questionHelper = $this->getHelper('question');
$question = new ConfirmationQuestion(
sprintf(
'Are you sure you want to copy `%s` subtree (no. of children: %d) into `%s`? This may take a while for a big number of nested children [Y/n]? ',
'Are you sure you want to copy `%s` subtree (no. of children: %s) into `%s`? This may take a while for a big number of nested children [Y/n]? ',
$sourceLocation->contentInfo->name,
$this->getAllChildrenCount($sourceLocation),
$this->getAllChildrenCountExpr($sourceLocation),
$targetLocation->contentInfo->name
)
);
Expand All @@ -168,20 +159,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location
*
* @return int
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function getAllChildrenCount(Location $location): int
protected function getAllChildrenCountExpr(Location $location): string
{
$query = new LocationQuery([
'filter' => new Criterion\Subtree($location->pathString),
]);

$searchResults = $this->searchService->findLocations($query);
$totalCount = $this->searchService->findLocations($query)->totalCount;

return $searchResults->totalCount;
return $totalCount !== null ? (string) $totalCount : '~';
}
}
7 changes: 2 additions & 5 deletions src/bundle/Core/Command/ResizeOriginalImagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
while ($query->offset <= $totalCount) {
$results = $this->searchService->findContent($query);

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit $hit */
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content> $hit */
foreach ($results->searchHits as $hit) {
$this->resize($output, $hit, $imageFieldIdentifier, $filter);
$progressBar->advance();
Expand All @@ -232,10 +232,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/**
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit $hit
* @param string $imageFieldIdentifier
* @param string $filter
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content> $hit
*/
private function resize(OutputInterface $output, SearchHit $hit, string $imageFieldIdentifier, string $filter): void
{
Expand Down
15 changes: 8 additions & 7 deletions src/bundle/Core/Features/Context/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,27 @@ public function searchUserByLogin($username, $parentGroupId = null)
* Search User Groups with given name.
*
* @param string $name name of User Group to search for
* @param string $parentLocationId (optional) parent location id to search in
* @param int|null $parentLocationId (optional) parent location id to search in
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit[] search results
* @phpstan-return list<\Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content>>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function searchUserGroups($name, $parentLocationId = null)
public function searchUserGroups(string $name, ?int $parentLocationId = null): array
{
$criterionArray = [
new Criterion\Subtree(self::USERGROUP_ROOT_SUBTREE),
new Criterion\ContentTypeIdentifier(self::USERGROUP_CONTENT_IDENTIFIER),
new Criterion\Field('name', Criterion\Operator::EQ, $name),
];
if ($parentLocationId) {
if (null !== $parentLocationId) {
$criterionArray[] = new Criterion\ParentLocationId($parentLocationId);
}
$query = new Query();
$query->filter = new Criterion\LogicalAnd($criterionArray);

$result = $this->searchService->findContent($query, [], false);

return $result->searchHits;
return $this->searchService->findContent($query, [], false)->searchHits;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/contracts/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

/**
* This class provides service methods for managing content.
*
* @phpstan-type TFilteringLanguageFilter array<int, string>
*/
interface ContentService
{
Expand Down Expand Up @@ -511,7 +513,7 @@ public function validate(ValueObject $object, array $context, ?array $fieldIdent
/**
* Fetches Content items from the Repository filtered by the given conditions.
*
* @param array<int, string> $languages A list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages A list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*/
Expand All @@ -522,9 +524,11 @@ public function find(Filter $filter, ?array $languages = null): ContentList;
*
* Counts total number of items returned by {@see ContentService::find()} with the same parameters.
*
* @param array<int, string> $languages A list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages $languages A list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*
* @phpstan-return int<0, max>
*/
public function count(Filter $filter, ?array $languages = null): int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;
use Iterator;

/**
* @template TSearchHitValueObject of \Ibexa\Contracts\Core\Repository\Values\ValueObject
*
* @phpstan-import-type TSearchLanguageFilter from \Ibexa\Contracts\Core\Repository\SearchService
*/
abstract class AbstractSearchAdapter implements BatchIteratorAdapter
{
/** @var \Ibexa\Contracts\Core\Repository\SearchService */
protected $searchService;
protected SearchService $searchService;

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query */
protected $query;
protected Query $query;

/** @var string[] */
protected $languageFilter;
/** @phpstan-var TSearchLanguageFilter */
protected array $languageFilter;

/** @var bool */
protected $filterOnUserPermissions;
protected bool $filterOnUserPermissions;

/**
* @phpstan-param TSearchLanguageFilter $languageFilter
*/
public function __construct(
SearchService $searchService,
Query $query,
Expand All @@ -49,5 +55,10 @@ final public function fetch(int $offset, int $limit): Iterator
return $this->executeSearch($query)->getIterator();
}

/**
* @phpstan-return \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult<TSearchHitValueObject>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
abstract protected function executeSearch(Query $query): SearchResult;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;

/**
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo>
*/
final class ContentInfoSearchAdapter extends AbstractSearchAdapter
{
/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function executeSearch(Query $query): SearchResult
{
return $this->searchService->findContentInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;

/**
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\Content>
*/
final class ContentSearchAdapter extends AbstractSearchAdapter
{
protected function executeSearch(Query $query): SearchResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

namespace Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter;

use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;

/**
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\Location>
*/
final class LocationSearchAdapter extends AbstractSearchAdapter
{
public function __construct(
Expand All @@ -26,6 +30,17 @@ public function __construct(

protected function executeSearch(Query $query): SearchResult
{
if (!$query instanceof LocationQuery) {
throw new InvalidArgumentException(
'$query',
sprintf(
'Expected an instance of %s, got %s',
LocationQuery::class,
get_class($query)
)
);
}

return $this->searchService->findLocations(
$query,
$this->languageFilter,
Expand Down
6 changes: 4 additions & 2 deletions src/contracts/Repository/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

/**
* Location service, used for complex subtree operations.
*
* @phpstan-type TFilteringLanguageFilter array<int, string>
*/
interface LocationService
{
Expand Down Expand Up @@ -260,7 +262,7 @@ public function loadAllLocations(int $offset = 0, int $limit = 25): array;
/**
* Fetch a LocationList from the Repository filtered by the given conditions.
*
* @param string[] $languages a list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages a list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*/
Expand All @@ -269,7 +271,7 @@ public function find(Filter $filter, ?array $languages = null): LocationList;
/**
* Count total number of items returned by {@see find} method.
*
* @param string[] $languages a list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages a list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*/
Expand Down
Loading

0 comments on commit 58f2bfb

Please sign in to comment.