Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ on:
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

push:
paths-ignore:
Expand All @@ -16,8 +14,6 @@ on:
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: build

Expand All @@ -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
Expand All @@ -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
Expand All @@ -86,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
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
Expand All @@ -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"
}
}
}
16 changes: 5 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/bootstrap.php"
colors="true" convertErrorsToExceptions="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
>

<php>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Yii2-ElasticSearch">
<directory>./tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src</directory>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>

14 changes: 14 additions & 0 deletions src/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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([]);
Expand Down
6 changes: 3 additions & 3 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
$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();
}
Expand Down Expand Up @@ -230,7 +230,7 @@
if ($this->activeNode === null) {
return;
}
Yii::trace('Closing connection to Elasticsearch. Active node was: '
Yii::debug('Closing connection to Elasticsearch. Active node was: '

Check warning on line 233 in src/Connection.php

View check run for this annotation

Codecov / codecov/patch

src/Connection.php#L233

Added line #L233 was not covered by tests
. $this->nodes[$this->activeNode]['http']['publish_address'], __CLASS__);
$this->activeNode = null;
if ($this->_curl) {
Expand Down Expand Up @@ -506,7 +506,7 @@
$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__);
}
Expand Down
1 change: 1 addition & 0 deletions src/ElasticsearchTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions tests/ActiveDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}