Skip to content

Commit 033c90c

Browse files
Use Yii2 22. (#357)
1 parent acfc056 commit 033c90c

File tree

7 files changed

+43
-39
lines changed

7 files changed

+43
-39
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ on:
66
- 'CHANGELOG.md'
77
- '.gitignore'
88
- '.gitattributes'
9-
- 'infection.json.dist'
10-
- 'psalm.xml'
119

1210
push:
1311
paths-ignore:
@@ -16,8 +14,6 @@ on:
1614
- 'CHANGELOG.md'
1715
- '.gitignore'
1816
- '.gitattributes'
19-
- 'infection.json.dist'
20-
- 'psalm.xml'
2117

2218
name: build
2319

@@ -33,12 +29,10 @@ jobs:
3329
strategy:
3430
matrix:
3531
php:
36-
- 7.3
37-
- 7.4
38-
- 8.0
3932
- 8.1
4033
- 8.2
4134
- 8.3
35+
- 8.4
4236

4337
es:
4438
- 8.1.3
@@ -61,7 +55,7 @@ jobs:
6155
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 }}
6256
6357
- name: Checkout.
64-
uses: actions/checkout@v3
58+
uses: actions/checkout@v4
6559

6660
- name: Install PHP with extensions.
6761
uses: shivammathur/setup-php@v2
@@ -86,7 +80,7 @@ jobs:
8680

8781
- name: Upload coverage to Codecov.
8882
if: matrix.php == '8.1'
89-
uses: codecov/codecov-action@v3
83+
uses: codecov/codecov-action@v4
9084
with:
9185
token: ${{ secrets.CODECOV_TOKEN }}
9286
file: ./coverage.xml

composer.json

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"name": "yiisoft/yii2-elasticsearch",
33
"description": "Elasticsearch integration and ActiveRecord for the Yii framework",
4-
"keywords": ["yii2", "elasticsearch", "active-record", "search", "fulltext"],
4+
"keywords": [
5+
"yii2",
6+
"elasticsearch",
7+
"active-record",
8+
"search",
9+
"fulltext"
10+
],
511
"type": "yii2-extension",
612
"license": "BSD-3-Clause",
713
"support": {
@@ -17,12 +23,13 @@
1723
"email": "mail@cebe.cc"
1824
}
1925
],
26+
"minimum-stability": "dev",
2027
"require": {
21-
"php": ">=7.3",
28+
"php": ">=8.1",
2229
"ext-curl": "*",
2330
"ext-json": "*",
2431
"ext-mbstring": "*",
25-
"yiisoft/yii2": "~2.0.14"
32+
"yiisoft/yii2": "22.0.x-dev"
2633
},
2734
"require-dev": {
2835
"phpunit/phpunit": "^9.6"
@@ -34,16 +41,5 @@
3441
"allow-plugins": {
3542
"yiisoft/yii2-composer": true
3643
}
37-
},
38-
"repositories": [
39-
{
40-
"type": "composer",
41-
"url": "https://asset-packagist.org"
42-
}
43-
],
44-
"extra": {
45-
"branch-alias": {
46-
"dev-master": "2.1.x-dev"
47-
}
4844
}
4945
}

phpunit.xml.dist

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
43
bootstrap="./tests/bootstrap.php"
5-
colors="true" convertErrorsToExceptions="true"
4+
colors="true"
5+
convertErrorsToExceptions="true"
66
convertNoticesToExceptions="true"
77
convertWarningsToExceptions="true"
88
stopOnFailure="false"
9-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
1011
>
11-
12-
<php>
13-
<ini name="error_reporting" value="-1"/>
14-
</php>
15-
1612
<testsuites>
1713
<testsuite name="Yii2-ElasticSearch">
1814
<directory>./tests</directory>
1915
</testsuite>
2016
</testsuites>
21-
2217
<coverage>
2318
<include>
24-
<directory>./src</directory>
19+
<directory suffix=".php">src</directory>
2520
</include>
2621
</coverage>
2722
</phpunit>
28-

src/ActiveDataProvider.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ public function getQueryResults()
5353
return $this->_queryResults;
5454
}
5555

56+
/**
57+
* @inheritdoc
58+
*/
59+
public function prepare($forcePrepare = false)
60+
{
61+
if ($forcePrepare) {
62+
$this->setTotalCount(null);
63+
}
64+
parent::prepare($forcePrepare);
65+
}
66+
5667
/**
5768
* @return array all aggregations results
5869
*/
@@ -122,6 +133,9 @@ protected function prepareModels()
122133

123134
if (is_array(($results = $query->search($this->db)))) {
124135
$this->setQueryResults($results);
136+
if ($pagination !== false) {
137+
$pagination->totalCount = $this->getTotalCount();
138+
}
125139
return $results['hits']['hits'];
126140
}
127141
$this->setQueryResults([]);

src/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function open()
166166
$this->populateNodes();
167167
}
168168
$this->selectActiveNode();
169-
Yii::trace('Opening connection to Elasticsearch. Nodes in cluster: ' . count($this->nodes)
169+
Yii::debug('Opening connection to Elasticsearch. Nodes in cluster: ' . count($this->nodes)
170170
. ', active node: ' . $this->nodes[$this->activeNode]['http_address'], __CLASS__);
171171
$this->initConnection();
172172
}
@@ -230,7 +230,7 @@ public function close()
230230
if ($this->activeNode === null) {
231231
return;
232232
}
233-
Yii::trace('Closing connection to Elasticsearch. Active node was: '
233+
Yii::debug('Closing connection to Elasticsearch. Active node was: '
234234
. $this->nodes[$this->activeNode]['http']['publish_address'], __CLASS__);
235235
$this->activeNode = null;
236236
if ($this->_curl) {
@@ -506,7 +506,7 @@ protected function httpRequest($method, $url, $requestBody = null, $raw = false)
506506
$profile = false;
507507
}
508508

509-
Yii::trace("Sending request to Elasticsearch node: $method $url\n$requestBody", __METHOD__);
509+
Yii::debug("Sending request to Elasticsearch node: $method $url\n$requestBody", __METHOD__);
510510
if ($profile !== false) {
511511
Yii::beginProfile($profile, __METHOD__);
512512
}

src/ElasticsearchTarget.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function collect($messages, $final)
139139
public function prepareMessage($message)
140140
{
141141
list($text, $level, $category, $timestamp) = $message;
142+
$timestamp = (int) round($timestamp);
142143

143144
$result = [
144145
'category' => $category,

tests/ActiveDataProviderTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,16 @@ public function testTotalCountAfterSearch()
150150
]);
151151

152152
$pagination = $provider->getPagination();
153+
$this->assertEquals(0, $pagination->getPageCount());
154+
$this->assertCount(2, $provider->getModels());
153155
$this->assertEquals(2, $pagination->getPageCount());
154-
$this->assertEquals(3, $pagination->getTotalCount());
156+
$this->assertEquals(3, $provider->getTotalCount());
155157

156158
$query->andWhere(['name' => 'user2']);
159+
$provider->prepare(true);
160+
161+
$this->assertCount(1, $provider->getModels());
157162
$this->assertEquals(1, $pagination->getPageCount());
158-
$this->assertEquals(1, $pagination->getTotalCount());
163+
$this->assertEquals(1, $provider->getTotalCount());
159164
}
160165
}

0 commit comments

Comments
 (0)