From da243eac35a4a0132a3eeebc412c5088d04d4c7a Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 27 May 2025 17:50:38 -0400 Subject: [PATCH 1/3] Use Yii2 `22`. --- .github/workflows/build.yml | 10 ++-------- composer.json | 21 +++++++++++---------- phpunit.xml.dist | 16 +++++----------- src/ActiveDataProvider.php | 14 ++++++++++++++ src/Connection.php | 6 +++--- src/ElasticsearchTarget.php | 1 + tests/ActiveDataProviderTest.php | 9 +++++++-- 7 files changed, 43 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8918cc6c..74dcff2e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,8 +6,6 @@ on: - 'CHANGELOG.md' - '.gitignore' - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' push: paths-ignore: @@ -16,8 +14,6 @@ on: - 'CHANGELOG.md' - '.gitignore' - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' name: build @@ -33,12 +29,10 @@ jobs: strategy: matrix: php: - - 7.3 - - 7.4 - - 8.0 - 8.1 - 8.2 - 8.3 + - 8.4 es: - 8.1.3 @@ -61,7 +55,7 @@ jobs: docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" elasticsearch:${{ matrix.es }} - name: Checkout. - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP with extensions. uses: shivammathur/setup-php@v2 diff --git a/composer.json b/composer.json index 2da5aee7..0db30c3b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,13 @@ { "name": "yiisoft/yii2-elasticsearch", "description": "Elasticsearch integration and ActiveRecord for the Yii framework", - "keywords": ["yii2", "elasticsearch", "active-record", "search", "fulltext"], + "keywords": [ + "yii2", + "elasticsearch", + "active-record", + "search", + "fulltext" + ], "type": "yii2-extension", "license": "BSD-3-Clause", "support": { @@ -17,12 +23,13 @@ "email": "mail@cebe.cc" } ], + "minimum-stability": "dev", "require": { - "php": ">=7.3", + "php": ">=8.1", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "yiisoft/yii2": "~2.0.14" + "yiisoft/yii2": "22.0.x-dev" }, "require-dev": { "phpunit/phpunit": "^9.6" @@ -35,15 +42,9 @@ "yiisoft/yii2-composer": true } }, - "repositories": [ - { - "type": "composer", - "url": "https://asset-packagist.org" - } - ], "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "22.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bda5353e..f2d5f06d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,22 @@ - - - - - ./tests - - ./src + src - diff --git a/src/ActiveDataProvider.php b/src/ActiveDataProvider.php index bb89f649..74271f09 100644 --- a/src/ActiveDataProvider.php +++ b/src/ActiveDataProvider.php @@ -53,6 +53,17 @@ public function getQueryResults() return $this->_queryResults; } + /** + * @inheritdoc + */ + public function prepare($forcePrepare = false) + { + if ($forcePrepare) { + $this->setTotalCount(null); + } + parent::prepare($forcePrepare); + } + /** * @return array all aggregations results */ @@ -122,6 +133,9 @@ protected function prepareModels() if (is_array(($results = $query->search($this->db)))) { $this->setQueryResults($results); + if ($pagination !== false) { + $pagination->totalCount = $this->getTotalCount(); + } return $results['hits']['hits']; } $this->setQueryResults([]); diff --git a/src/Connection.php b/src/Connection.php index 485dcc0c..c2e518e4 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -166,7 +166,7 @@ public function open() $this->populateNodes(); } $this->selectActiveNode(); - Yii::trace('Opening connection to Elasticsearch. Nodes in cluster: ' . count($this->nodes) + Yii::debug('Opening connection to Elasticsearch. Nodes in cluster: ' . count($this->nodes) . ', active node: ' . $this->nodes[$this->activeNode]['http_address'], __CLASS__); $this->initConnection(); } @@ -230,7 +230,7 @@ public function close() if ($this->activeNode === null) { return; } - Yii::trace('Closing connection to Elasticsearch. Active node was: ' + Yii::debug('Closing connection to Elasticsearch. Active node was: ' . $this->nodes[$this->activeNode]['http']['publish_address'], __CLASS__); $this->activeNode = null; if ($this->_curl) { @@ -506,7 +506,7 @@ protected function httpRequest($method, $url, $requestBody = null, $raw = false) $profile = false; } - Yii::trace("Sending request to Elasticsearch node: $method $url\n$requestBody", __METHOD__); + Yii::debug("Sending request to Elasticsearch node: $method $url\n$requestBody", __METHOD__); if ($profile !== false) { Yii::beginProfile($profile, __METHOD__); } diff --git a/src/ElasticsearchTarget.php b/src/ElasticsearchTarget.php index 3113668f..fb540b3d 100644 --- a/src/ElasticsearchTarget.php +++ b/src/ElasticsearchTarget.php @@ -139,6 +139,7 @@ public function collect($messages, $final) public function prepareMessage($message) { list($text, $level, $category, $timestamp) = $message; + $timestamp = (int) round($timestamp); $result = [ 'category' => $category, diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 806daca7..dc9cfb91 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -150,11 +150,16 @@ public function testTotalCountAfterSearch() ]); $pagination = $provider->getPagination(); + $this->assertEquals(0, $pagination->getPageCount()); + $this->assertCount(2, $provider->getModels()); $this->assertEquals(2, $pagination->getPageCount()); - $this->assertEquals(3, $pagination->getTotalCount()); + $this->assertEquals(3, $provider->getTotalCount()); $query->andWhere(['name' => 'user2']); + $provider->prepare(true); + + $this->assertCount(1, $provider->getModels()); $this->assertEquals(1, $pagination->getPageCount()); - $this->assertEquals(1, $pagination->getTotalCount()); + $this->assertEquals(1, $provider->getTotalCount()); } } From ba6b8740e4ec114948b29b5bca67e82b2e9f44cb Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 27 May 2025 17:55:39 -0400 Subject: [PATCH 2/3] Update Codecov action to version `4` in build workflow. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74dcff2e..8f7ba4f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,7 +80,7 @@ jobs: - name: Upload coverage to Codecov. if: matrix.php == '8.1' - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.xml From 5e37af805014e565244ebd40cc75cc74298f0cf0 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 28 May 2025 10:17:55 -0400 Subject: [PATCH 3/3] Remove unnecessary extra configuration from `composer.json`. --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index 0db30c3b..a142bc6d 100644 --- a/composer.json +++ b/composer.json @@ -41,10 +41,5 @@ "allow-plugins": { "yiisoft/yii2-composer": true } - }, - "extra": { - "branch-alias": { - "dev-master": "22.0.x-dev" - } } }