sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Inconsistent return-type of SimplePager #5137

Closed oleg-andreyev closed 5 years ago

oleg-andreyev commented 6 years ago

Environment

Any

Sonata packages

$ composer show --latest 'sonata-project/*'
"sonata-project/doctrine-extensions":       "~1.0",
"sonata-project/cache-bundle":              "2.2.5",
"sonata-project/jquery-bundle":             "1.8.*",
"sonata-project/admin-bundle":              "3.0.0",
"sonata-project/user-bundle":               "3.0.0",
"sonata-project/doctrine-orm-admin-bundle": "3.0.0",
"sonata-project/easy-extends-bundle":       "~2.1",

Symfony packages

$ composer show --latest 'symfony/*'
sonata-project/admin-bundle              3.0.0 3.35.2 The missing Symfony Admin Generator
sonata-project/block-bundle              3.1.1 3.12.1 Symfony SonataBlockBundle
sonata-project/cache                     1.0.7 1.0.7  Cache library
sonata-project/cache-bundle              2.2.5 2.4.2  This bundle provides caching services
sonata-project/core-bundle               3.1.1 3.10.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2   2.3.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2 1.0.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.0.0 3.6.1  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.1.5 2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.3.3 1.9.0  Lightweight Exporter library
sonata-project/google-authenticator      1.0.1 2.0.0  Library to integrate Google Authenticator into a PHP project
sonata-project/jquery-bundle             1.8.3 1.10.2 Symfony SonatajQueryBundle
sonata-project/user-bundle               3.0.0 3.6.0  Symfony SonataUserBundle

PHP version

$ php -v
PHP 7.0.30 (cli) (built: Apr 24 2018 21:41:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.30, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
    with blackfire v1.20.1~linux-x64-non_zts70, https://blackfire.io, by Blackfire

Subject

Issue was moved with #2656 from SonataDoctrinePhpcrAdminBundle

covex-nn commented 6 years ago

DatagridInterface::getResults declare return type array PagerInterface::getResults declare return type array

I found, that Sonata\AdminBundle\Datagrid\Datagrid::getResults may return instance of Doctrine\ODM\MongoDB\Cursor when using DoctrineMongoDBAdminBundle, i.e. Datagrid::getResults recieves non-array (mixed) value from $this->pager->getResults()!

DoctrineMongoDBAdminBundle does not use SimplePager, but DoctrinePHPCRAdminBundle does. So, maybe pager for DoctrinePHPCRAdminBundle returns ArrayCollection? I cannot check it by myself =(

array will be returns if empty result

That condition is not about empty result:

if (count($this->results) > $this->getMaxPerPage()) {
    // ... skipped ...
} else {
    $this->haveToPaginate = false;
    // ^ it is not empty result, it is "result does not have to be paginated"
}
oleg-andreyev commented 6 years ago

@covex-nn thanks for your feedback, I'll investigate.

oleg-andreyev commented 6 years ago

@covex-nn SimplePager will never work with MongoDB, array_slice accepts array and does not work with \Iterator, which seems to as separate bug to fill.

I've investigated PHPCR, and yes it's returning ArrayCollection, so I've adjusted SimplePager to handle such cases

phansys commented 5 years ago

Closing since #5137 is already merged. Thank you!