diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index b36e8b1131c..ccf64beb58f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -18,6 +18,9 @@ Yii Framework 2 Change Log - Bug #17181: Improved `BaseUrl::isRelative($url)` performance (sammousa, bizley, rob006) - Bug #17191: Fixed `BaseUrl::isRelative($url)` method in `yii\helpers\BaseUrl` (ggh2e3) - Bug #18469: Fixed `Link::serialize(array $links)` method in `yii\web\Link` (ggh2e3) +- Bug #19691: Allow using custom class to style error summary (skepticspriggan) +- Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw) +- Bug #20005: Fix `yii\console\controllers\ServeController` to specify the router script (terabytesoftw) - Bug #19060: Fix `yii\widgets\Menu` bug when using Closure for active item and adding additional tests in `tests\framework\widgets\MenuTest` (atrandafir) - Bug #19691: Allow using custom class to style error summary (skepticspriggan) - Bug #19817: Add MySQL Query `addCheck()` and `dropCheck()` (@bobonov) diff --git a/framework/data/ActiveDataProvider.php b/framework/data/ActiveDataProvider.php index 1a098cd6474..600e7f9e104 100644 --- a/framework/data/ActiveDataProvider.php +++ b/framework/data/ActiveDataProvider.php @@ -102,6 +102,7 @@ protected function prepareModels() } $query = clone $this->query; if (($pagination = $this->getPagination()) !== false) { + $pagination->totalCount = $this->getTotalCount(); if ($pagination->totalCount === 0) { return []; } diff --git a/framework/data/ArrayDataProvider.php b/framework/data/ArrayDataProvider.php index feddc16ab11..657bcd2a1c3 100644 --- a/framework/data/ArrayDataProvider.php +++ b/framework/data/ArrayDataProvider.php @@ -86,10 +86,14 @@ protected function prepareModels() $models = $this->sortModels($models, $sort); } - $pagination = $this->getPagination(); - if ($pagination !== false && $pagination->getPageSize() > 0) { - $models = array_slice($models, $pagination->getOffset(), $pagination->getLimit(), true); + if (($pagination = $this->getPagination()) !== false) { + $pagination->totalCount = $this->getTotalCount(); + + if ($pagination->getPageSize() > 0) { + $models = array_slice($models, $pagination->getOffset(), $pagination->getLimit(), true); + } } + return $models; } diff --git a/framework/data/BaseDataProvider.php b/framework/data/BaseDataProvider.php index 22fa1a0ad4f..944e4289c4a 100644 --- a/framework/data/BaseDataProvider.php +++ b/framework/data/BaseDataProvider.php @@ -164,13 +164,13 @@ public function getCount() */ public function getTotalCount() { - if ($this->_pagination === false) { + if ($this->getPagination() === false) { return $this->getCount(); + } elseif ($this->_totalCount === null) { + $this->_totalCount = $this->prepareTotalCount(); } - if ($this->_totalCount !== null) { - return (int)$this->_totalCount; - } - return $this->prepareTotalCount(); + + return $this->_totalCount; } /** @@ -193,6 +193,7 @@ public function getPagination() if ($this->_pagination === null) { $this->setPagination([]); } + return $this->_pagination; } @@ -216,15 +217,9 @@ public function setPagination($value) $config['pageParam'] = $this->id . '-page'; $config['pageSizeParam'] = $this->id . '-per-page'; } - $value = Yii::createObject(array_merge($config, $value)); - } - if ($value instanceof Pagination) { - $value->setTotalCount(function () { - return $this->getTotalCount(); - }); + $this->_pagination = Yii::createObject(array_merge($config, $value)); + } elseif ($value instanceof Pagination || $value === false) { $this->_pagination = $value; - } elseif ($value === false) { - $this->_pagination = false; } else { throw new InvalidArgumentException('Only Pagination instance, configuration array or false is allowed.'); } diff --git a/framework/data/SqlDataProvider.php b/framework/data/SqlDataProvider.php index c173a23d973..3b612de5c70 100644 --- a/framework/data/SqlDataProvider.php +++ b/framework/data/SqlDataProvider.php @@ -126,6 +126,7 @@ protected function prepareModels() } if ($pagination !== false) { + $pagination->totalCount = $this->getTotalCount(); $limit = $pagination->getLimit(); $offset = $pagination->getOffset(); } diff --git a/tests/framework/data/ActiveDataProviderTest.php b/tests/framework/data/ActiveDataProviderTest.php index da3e70df945..815002d9dbe 100644 --- a/tests/framework/data/ActiveDataProviderTest.php +++ b/tests/framework/data/ActiveDataProviderTest.php @@ -170,8 +170,9 @@ public function testPaginationBeforeModels() 'query' => $query->from('order')->orderBy('id'), ]); $pagination = $provider->getPagination(); - $this->assertEquals(1, $pagination->getPageCount()); + $this->assertEquals(0, $pagination->getPageCount()); $this->assertCount(3, $provider->getModels()); + $this->assertEquals(1, $pagination->getPageCount()); $provider->getPagination()->pageSize = 2; $this->assertCount(3, $provider->getModels()); diff --git a/tests/framework/rest/SerializerTest.php b/tests/framework/rest/SerializerTest.php index f2e0ed72e5e..91b627b8f8e 100644 --- a/tests/framework/rest/SerializerTest.php +++ b/tests/framework/rest/SerializerTest.php @@ -439,30 +439,6 @@ public function testHeadSerializeDataProvider($dataProvider, $expectedResult, $s ]); $serializer->preserveKeys = $saveKeys; $this->assertEmpty($serializer->serialize($dataProvider)); - $this->assertNotEmpty($serializer->response->getHeaders()->get($serializer->totalCountHeader)); - - $arrayDataProviderMock = $this->getMockBuilder(ArrayDataProvider::className()) - ->disableOriginalConstructor() - ->getMock(); - - // stub getModels to prevent empty - $arrayDataProviderMock - ->method('getModels') - ->willReturn($expectedResult); - - // stub getPagination for header - $arrayDataProviderMock - ->method('getPagination') - ->willReturn($dataProvider->getPagination()); - - // assert normal HEAD is empty response - $this->assertEmpty($serializer->serialize($arrayDataProviderMock)); - - // Test #20002: Set up the expectation for the getModels method - $arrayDataProviderMock->expects($this->never()) - ->method('getModels'); - - // reset Method unset($_POST[$request->methodParam], $_SERVER['REQUEST_METHOD']); }