Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Pager::getResults in favor of getCurrentPageResults #509

Merged
merged 3 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ UPGRADE FROM 3.x to 3.x
Deprecated `computeNbResult()` method.
Deprecated `getNbResults()` method, you SHOULD use `countResults()` instead.
Deprecated `setNbResults()` method.
Deprecated `getResults()` method.

UPGRADE FROM 3.5 to 3.6
=======================
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"doctrine/mongodb-odm": "^2.1",
"doctrine/mongodb-odm-bundle": "^4.0",
"doctrine/persistence": "^1.3.4 || ^2.0",
"sonata-project/admin-bundle": "^3.86",
"sonata-project/admin-bundle": "^3.87",
"sonata-project/form-extensions": "^0.1 || ^1.4",
"symfony/config": "^4.4",
"symfony/dependency-injection": "^4.4",
Expand All @@ -53,7 +53,7 @@
"psalm/plugin-symfony": "^2.0",
"symfony/browser-kit": "^4.4 || ^5.1",
"symfony/css-selector": "^4.4 || ^5.1",
"symfony/panther": "^0.8.0",
"symfony/panther": "^0.9.0",
"symfony/phpunit-bridge": "^5.1.8",
"vimeo/psalm": "^4.1.1"
},
Expand Down
18 changes: 17 additions & 1 deletion src/Datagrid/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,27 @@ public function computeNbResult()
return $this->computeResultsCount();
}

public function getResults()
public function getCurrentPageResults(): iterable
{
return $this->getQuery()->execute();
}

/**
* NEXT_MAJOR: remove this method.
*
* @deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x.
*/
public function getResults()
{
@trigger_error(sprintf(
'Method "%s()" is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x and will'
.' be removed in 4.0. Use "getCurrentPageResults()" instead.',
__METHOD__,
), E_USER_DEPRECATED);

return $this->getCurrentPageResults();
}

/**
* @return void
*/
Expand Down
22 changes: 13 additions & 9 deletions src/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,12 @@ public function executeQuery($query)
*/
public function getModelIdentifier($class)
{
@trigger_error(sprintf(
'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.6 and will be removed in version 4.0.',
__METHOD__
), E_USER_DEPRECATED);
if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
@trigger_error(sprintf(
'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.6 and will be removed in version 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

return $this->getMetadata($class, 'sonata_deprecation_mute')->identifier;
}
Expand Down Expand Up @@ -532,14 +534,16 @@ public function getPaginationParameters(DatagridInterface $datagrid, $page)
*/
public function getDefaultSortValues($class)
{
@trigger_error(sprintf(
'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.6 and will be removed in version 4.0.',
__METHOD__
), E_USER_DEPRECATED);
if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
@trigger_error(sprintf(
'Method %s() is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.6 and will be removed in version 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

return [
'_sort_order' => 'ASC',
'_sort_by' => $this->getModelIdentifier($class),
'_sort_by' => $this->getModelIdentifier($class, 'sonata_deprecation_mute'),
'_page' => 1,
'_per_page' => 25,
];
Expand Down