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

handle SonataAdminBundle Pager::nbresults deprecation #1257

Merged
merged 2 commits into from
Jan 10, 2021

Conversation

dmaicher
Copy link
Contributor

@dmaicher dmaicher commented Jan 6, 2021

Subject

I am targeting this branch, because its BC.

Changelog

### Added
- implemented `Sonata\AdminBundle\Datagrid\PagerInterface::countResults()`

### Deprecated
- `Sonata\DoctrineORMAdminBundle\Datagrid\Pager::computeNbResult()`
- `Sonata\DoctrineORMAdminBundle\Datagrid\Pager::getNbResults()`
- `Sonata\DoctrineORMAdminBundle\Datagrid\Pager::setNbResults()`

@dmaicher
Copy link
Contributor Author

dmaicher commented Jan 6, 2021

@VincentLanglet before I continue: The Pager here is marked final via annotation. Do we keep BC then for people who extended this class? What's the policy there?

https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/3.x/src/Datagrid/Pager.php#L25

@VincentLanglet
Copy link
Member

Yes, I think we still keep BC for method with @final

Be careful, your implementation of countResults is wrong.
getResults is returning the results of the current page !

private $resultsCount;

public function setResultsCount($count) {
    $this->resultsCount = $count;
    // NEXT_MAJOR: Remove this line.
    $this->setNbResults($count, 'sonata_deprecation_mute'); // You need to override this method or make a new PR to sonataAdmin to allow to avoid the deprecation.
}

public function countResults() {
    $deprecatedCount = $this->getNbResults('sonata_deprecation_mute'); // You need to override this method or make a new PR to sonataAdmin to allow to avoid the deprecation.

    if ($deprecatedCount !== $this->resultsCount) {
        // trigger deprecation

        return $deprecatedCount;
    }

    return $this->resultsCount;
}

Maybe we can do something like this ?

I think it would be good to deprecate getResults in favor of getPageResults in SonataAdmin too.
cc @sonata-project/contributors

And if we're changing nbResult, we should rename computeNbResult.
But after rereading, the computeNbResult method should be private. So you should just

  • Add a comment NEXT_MAJOR: restrict visibility to private and rename to computeResultsCount`
  • Add a deprecation in this method.
  • Making the call in init with sonata_deprecation_mute.

@dmaicher
Copy link
Contributor Author

dmaicher commented Jan 6, 2021

Be careful, your implementation of countResults is wrong.
getResults is returning the results of the current page !

I don't follow. Currently I just call getNbResults (which will trigger a deprecation though).

Will look into it then with keeping BC.

@VincentLanglet
Copy link
Member

Be careful, your implementation of countResults is wrong.
getResults is returning the results of the current page !

I don't follow. Currently I just call getNbResults (which will trigger a deprecation though).

Will look into it then with keeping BC.

My bad, i'm tired, I read

count($this->getResults())

But I just discovered that

count($this->getResults()) !== $this->countResults()

@dmaicher dmaicher force-pushed the nbresults_deprecation branch from e4f6877 to a4d85c8 Compare January 6, 2021 20:37
@dmaicher dmaicher force-pushed the nbresults_deprecation branch 5 times, most recently from 1ee0313 to 12a19d3 Compare January 6, 2021 20:52
@dmaicher dmaicher force-pushed the nbresults_deprecation branch from 64c188c to 3e49f97 Compare January 9, 2021 11:57
@dmaicher
Copy link
Contributor Author

dmaicher commented Jan 9, 2021

Once SonataAdminBundle 3.86 was released we need to bump the minimum in composer.json here before we release 3.27

@dmaicher dmaicher marked this pull request as ready for review January 9, 2021 11:59
VincentLanglet
VincentLanglet previously approved these changes Jan 9, 2021
@OskarStark
Copy link
Member

Can you bump it in this PR?

@VincentLanglet
Copy link
Member

Can you bump it in this PR?

Need sonata-project/SonataAdminBundle#6756

@VincentLanglet
Copy link
Member

3.86 is released :)

@OskarStark
Copy link
Member

@phansys I merged this, because your suggestion was merged 👍🏻

@dmaicher dmaicher deleted the nbresults_deprecation branch January 10, 2021 10:24
@franmomu franmomu added the minor label Jan 10, 2021
@phansys
Copy link
Member

phansys commented Jan 10, 2021

@phansys I merged this, because your suggestion was merged 👍🏻

Thank you!

VincentLanglet added a commit that referenced this pull request Jan 16, 2021
* Add functional tests (#1242)

This adds some functional tests using symfony/panther to test
CRUD operations as well as some embedded and many to one mapping.

* DevKit updates (#1252)

* DevKit updates (#1253)

* Set the correct fieldName to get the correct value

* Remove tests already made in SonataAdmin

These methods are coming from the BaseFieldDescription
which is already tested

* Add test

* Fix param name in doc (#1256)

* Fix param name in doc

* Fix

* Changing access checking in views (isGranted to hasAccess)

* handle SonataAdminBundle Pager::nbresults deprecation (#1257)

* handle SonataAdminBundle Pager::nbresults deprecation

* bump sonata admin version

* Avoid Pager deprecation (#1248)

* Delete button is independent of the ability to delete an object (#1254)

* DevKit updates (#1260)

* fixes after merging

Co-authored-by: Fran Moreno <[email protected]>
Co-authored-by: Sonata CI <[email protected]>
Co-authored-by: Vincent Langlet <[email protected]>
Co-authored-by: Vincent Langlet <[email protected]>
Co-authored-by: Adam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants