Skip to content

Commit

Permalink
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
Browse files Browse the repository at this point in the history
…n: Added BookmarkId sort clause
  • Loading branch information
vidarl committed Jun 6, 2024
1 parent 598fc41 commit 3503fcd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace eZ\Publish\API\Repository\Values\Content\Query\SortClause;

use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use eZ\Publish\SPI\Repository\Values\Filter\FilteringSortClause;

/**
* Sets sort direction on the bookmark id for a location query containing a Bookmark criterion.
*/
class BookmarkId extends SortClause implements FilteringSortClause
{
/**
* Constructs a new BookmarkId SortClause.
*
* @param string $sortDirection
*/
public function __construct(string $sortDirection = Query::SORT_ASC)
{
parent::__construct('id', $sortDirection);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace eZ\Publish\Core\Persistence\Legacy\Filter\SortClauseQueryBuilder\Bookmark;

use eZ\Publish\API\Repository\Values\Content\Query\SortClause\BookmarkId;
use eZ\Publish\SPI\Persistence\Filter\Doctrine\FilteringQueryBuilder;
use eZ\Publish\SPI\Repository\Values\Filter\FilteringSortClause;
use eZ\Publish\SPI\Repository\Values\Filter\SortClauseQueryBuilder;

class IdSortClauseQueryBuilder implements SortClauseQueryBuilder
{
public function accepts(FilteringSortClause $sortClause): bool
{
return $sortClause instanceof BookmarkId;
}

public function buildQuery(
FilteringQueryBuilder $queryBuilder,
FilteringSortClause $sortClause
): void {
/** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause */
$queryBuilder->addOrderBy('bookmark.id', $sortClause->direction);
}
}
2 changes: 1 addition & 1 deletion eZ/Publish/Core/Repository/BookmarkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function loadBookmarks(int $offset = 0, int $limit = 25): BookmarkList
try {
$filter
->withCriterion(new Criterion\Bookmark($currentUserId))
->withSortClause(new SortClause\DatePublished(Query::SORT_DESC))
->withSortClause(new SortClause\BookmarkId(Query::SORT_DESC))
->sliceBy($limit, $offset);

$result = $this->repository->getlocationService()->find($filter, []);
Expand Down

0 comments on commit 3503fcd

Please sign in to comment.