Skip to content

Commit

Permalink
Merge master into 2.1 (#229)
Browse files Browse the repository at this point in the history
* Update Query.php (#131)

* PHPUnit compatibility, provide token for github auth

* token update

* yet another update

* Fix #134 infinite query loop when the index does not exist

* improved error message for cluster auto detection

issue #137

* updated docs about cluster autodetection

fixes #137

* Elasticsearch logo added to README.md

* Composer json change

* Added alias actions to Command

* Fix for desirialization of plain response from elasticsearch

* Bring back old name for package

* Fix for php 5.4

* Added phpdocs, fixes and tests

* CHANGELOG.md

* clarify version compatibility

* Fixing broken elasticsearch doc links (#144) [skip ci]

* Fixes #149: Changed `yii\base\Object` to `yii\base\BaseObject`

* since elasticsearch 6, content type is mandatory (#150)

since elasticsearch 6, content type is mandatory. Otherwise, requests will all fail.

https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests

* added CHANGELOG for #150

* Reset query results after calling refresh() method

close #125

* Fixes case (#153) [skip ci]

* Fix spelling (#165) [skip ci]

* fix findAll and findOne to filter input to avoid passing manipulated condition

* release version 2.0.5

* prepare for next release

* Update README.md

* docs/guide-ja updated [ci skip] (#178)

* Removed redundant line from license [skip ci]

* guide-ja revised [ci skip]

* Fixed `count()` compatibility with PHP 7.2

do not call it on scalar values.

fixes #180

* Translate into Russian (#194) [skip ci]

* Improve Russian docs (#200) [skip ci]

* Bug #201: Fixed infinite loop

* Updated issue template [skip ci]

* Made tests running again (#210)

* Revert "Bug #201: Fixed infinite loop"

This reverts commit aa22ffd.

* Fixes #218: Comment out invalid syntax in sample [skip ci] (#219)

* docs/guide-ja/mapping-indexing.md updated [ci skip] (#221)

* Fixes #227: Fixed `Bad Request (#400): Unable to verify your data submission.` in debug details panel 'run query'

* Travis adjustments (#228)

* Use assertCount() in tests

* Add missing relations to Order test model

* Add note delete-by-query plugin (#158)

* Fixes #117: Add support for `QueryInterface::emulateExecution()`

* Specified versions that work
  • Loading branch information
samdark authored May 1, 2019
1 parent 203652a commit bc5f1c4
Show file tree
Hide file tree
Showing 35 changed files with 811 additions and 190 deletions.
8 changes: 6 additions & 2 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<!--
Please use this issue tracker for bugs and feature requests only. In case you need support please use one of
Yii communities listed at https://github.com/yiisoft/yii2/wiki/communities
-->

### What steps will reproduce the problem?

### What's expected?

### What do you get instead?


### Additional info

| Q | A
| ---------------- | ---
| Yii vesion |
| Yii version |
| PHP version |
| Operating system |
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
env:
global:
secure: cIGYsPd8OZ3X/ugDZyySmlMl/6gMcMMZQupTgPzHeq24mx+NR7gbVfQmTVnBjmXIpEemQFSe1KwQA2xdvkJ+rhObs8e1tldWFxjXd95Drlf1rKx1oy1LehPmXN4IpbY7PqEbncoSJywb7aLe18u+/2NFA27JsMh83y2xv6YfTQE=

language: php

php:
Expand All @@ -7,8 +11,7 @@ php:
- 7.0
- 7.1
- 7.2
- nightly
- hhvm
- 7.3

services:
- docker
Expand Down
32 changes: 21 additions & 11 deletions ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* count will be fetched after pagination limit applying, which eliminates ability to verify if requested page number
* actually exist. Data provider disables [[yii\data\Pagination::validatePage]] automatically because of this.
*
* @property array $queryResults the query results.
* @property array $aggregations all aggregations results.
* @property array $aggregations All aggregations results. This property is read-only.
* @property array $queryResults Full query results.
*
* @author Paul Klimov <[email protected]>
* @since 2.0.5
Expand Down Expand Up @@ -95,14 +95,15 @@ protected function prepareModels()
$query->addOrderBy($sort->getOrders());
}

$results = $query->search($this->db);
$this->setQueryResults($results);

if ($pagination !== false) {
$pagination->totalCount = $this->getTotalCount();
if (is_array(($results = $query->search($this->db)))) {
$this->setQueryResults($results);
if ($pagination !== false) {
$pagination->totalCount = $this->getTotalCount();
}
return $results['hits']['hits'];
}

return $results['hits']['hits'];
$this->setQueryResults([]);
return [];
}

/**
Expand All @@ -115,7 +116,7 @@ protected function prepareTotalCount()
}

$results = $this->getQueryResults();
return (int)$results['hits']['total'];
return isset($results['hits']['total']) ? (int)$results['hits']['total'] : 0;
}

/**
Expand Down Expand Up @@ -157,4 +158,13 @@ protected function prepareKeys($models)
return array_keys($models);
}
}
}

/**
* @inheritdoc
*/
public function refresh()
{
parent::refresh();
$this->_queryResults = null;
}
}
9 changes: 9 additions & 0 deletions ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ public function one($db = null)
*/
public function search($db = null, $options = [])
{
if ($this->emulateExecution) {
return [
'hits' => [
'total' => 0,
'hits' => [],
],
];
}

$command = $this->createCommand($db);
$result = $command->search($options);
if ($result === false) {
Expand Down
19 changes: 10 additions & 9 deletions ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ActiveRecord extends BaseActiveRecord
private $_highlight;
private $_explanation;


/**
* Returns the database connection used by this AR class.
* By default, the "elasticsearch" application component is used as the database connection.
Expand Down Expand Up @@ -432,7 +433,7 @@ public static function instantiate($row)
* $customer->insert();
* ~~~
*
* @param boolean $runValidation whether to perform validation before saving the record.
* @param bool $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* meaning all attributes will be saved.
Expand All @@ -446,7 +447,7 @@ public static function instantiate($row)
* for more details on these options.
*
* By default the `op_type` is set to `create` if model primary key is present.
* @return boolean whether the attributes are valid and the record is inserted successfully.
* @return bool whether the attributes are valid and the record is inserted successfully.
*/
public function insert($runValidation = true, $attributes = null, $options = [ ])
{
Expand Down Expand Up @@ -488,7 +489,7 @@ public function insert($runValidation = true, $attributes = null, $options = [ ]
/**
* @inheritdoc
*
* @param boolean $runValidation whether to perform validation before saving the record.
* @param bool $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
Expand All @@ -515,7 +516,7 @@ public function insert($runValidation = true, $attributes = null, $options = [ ]
* Make sure the record has been fetched with a [[version]] before. This is only the case
* for records fetched via [[get()]] and [[mget()]] by default. For normal queries, the `_version` field has to be fetched explicitly.
*
* @return integer|boolean the number of rows affected, or false if validation fails
* @return int|bool the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
* @throws StaleObjectException if optimistic locking is enabled and the data being updated is outdated.
* @throws InvalidParamException if no [[version]] is available and optimistic locking is enabled.
Expand All @@ -534,7 +535,7 @@ public function update($runValidation = true, $attributeNames = null, $options =
* @param array $attributes attributes to update
* @param array $options options given in this parameter are passed to elasticsearch
* as request URI parameters. See [[update()]] for details.
* @return integer|false the number of rows affected, or false if [[beforeSave()]] stops the updating process.
* @return int|false the number of rows affected, or false if [[beforeSave()]] stops the updating process.
* @throws StaleObjectException if optimistic locking is enabled and the data being updated is outdated.
* @throws InvalidParamException if no [[version]] is available and optimistic locking is enabled.
* @throws Exception in case update failed.
Expand Down Expand Up @@ -632,7 +633,7 @@ protected static function primaryKeysByCondition($condition)
* @param array $condition the conditions that will be passed to the `where()` method when building the query.
* Please refer to [[ActiveQuery::where()]] on how to specify this parameter.
* @see [[ActiveRecord::primaryKeysByCondition()]]
* @return integer the number of rows updated
* @return int the number of rows updated
* @throws Exception on error.
*/
public static function updateAll($attributes, $condition = [])
Expand Down Expand Up @@ -680,7 +681,7 @@ public static function updateAll($attributes, $condition = [])
* @param array $condition the conditions that will be passed to the `where()` method when building the query.
* Please refer to [[ActiveQuery::where()]] on how to specify this parameter.
* @see [[ActiveRecord::primaryKeysByCondition()]]
* @return integer the number of rows updated
* @return int the number of rows updated
* @throws Exception on error.
*/
public static function updateAllCounters($counters, $condition = [])
Expand Down Expand Up @@ -750,7 +751,7 @@ public static function updateAllCounters($counters, $condition = [])
* Make sure the record has been fetched with a [[version]] before. This is only the case
* for records fetched via [[get()]] and [[mget()]] by default. For normal queries, the `_version` field has to be fetched explicitly.
*
* @return integer|boolean the number of rows deleted, or false if the deletion is unsuccessful for some reason.
* @return int|bool the number of rows deleted, or false if the deletion is unsuccessful for some reason.
* Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.
* @throws StaleObjectException if optimistic locking is enabled and the data being deleted is outdated.
* @throws Exception in case delete failed.
Expand Down Expand Up @@ -808,7 +809,7 @@ public function delete($options = [])
* @param array $condition the conditions that will be passed to the `where()` method when building the query.
* Please refer to [[ActiveQuery::where()]] on how to specify this parameter.
* @see [[ActiveRecord::primaryKeysByCondition()]]
* @return integer the number of rows deleted
* @return int the number of rows deleted
* @throws Exception on error.
*/
public static function deleteAll($condition = [])
Expand Down
4 changes: 2 additions & 2 deletions BatchQueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected function fetchData()
/**
* Returns the index of the current dataset.
* This method is required by the interface [[\Iterator]].
* @return integer the index of the current row.
* @return int the index of the current row.
*/
public function key()
{
Expand All @@ -201,7 +201,7 @@ public function current()
/**
* Returns whether there is a valid dataset at the current position.
* This method is required by the interface [[\Iterator]].
* @return boolean whether there is a valid dataset at the current position.
* @return bool whether there is a valid dataset at the current position.
*/
public function valid()
{
Expand Down
1 change: 1 addition & 0 deletions BulkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BulkCommand extends Component
*/
public $options = [];


/**
* Executes the bulk command.
* @return mixed
Expand Down
24 changes: 20 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,35 @@ Yii Framework 2 elasticsearch extension Change Log
- Enh #222: Added collapse support (walkskyer)

2.0.5 under development
2.0.6 under development
-----------------------

- Bug #180: Fixed `count()` compatibility with PHP 7.2 to not call it on scalar values (cebe)
- Bug #227: Fixed `Bad Request (#400): Unable to verify your data submission.` in debug details panel 'run query' (rhertogh)
- Enh #117: Add support for `QueryInterface::emulateExecution()` (cebe)


2.0.5 March 20, 2018
--------------------

- Bug #120: Fix debug panel markup to be compatible with Yii 2.0.10 (drdim)
- Bug #125: Fixed `ActiveDataProvider::refresh()` to also reset `$queryResults` data (sizeg)
- Bug #134: Fix infinite query loop "ActiveDataProvider" when the index does not exist (eolitich)
- Bug #149: Changed `yii\base\Object` to `yii\base\BaseObject` (dmirogin)
- Bug: (CVE-2018-8074): Fixed possibility of manipulated condition when unfiltered input is passed to `ActiveRecord::findOne()` or `findAll()` (cebe)
- Bug: Updated debug panel classes to be consistent with yii 2.0.7 (beowulfenator)
- Bug: Added accessor method for the default elasticsearch primary key (kyle-mccarthy)
- Enh #15: Special data provider `yii\elasticsearch\ActiveDataProvider` created (klimov-paul)
- Enh #43: Elasticsearch log target (trntv, beowulfenator)
- Enh #47: Added support for post_filter option in search queries (mxkh)
- Enh #60: Minor updates to guide (devypt, beowulfenator)
- Enh #83: Support for "gt", ">", "gte", ">=", "lt", "<", "lte", "<=" operators in query (i-lie, beowulfenator)
- Enh: Bulk API implemented and used in AR (tibee, beowulfenator)
- Enh #82: Support HTTPS protocol (dor-denis, beowulfenator)
- Enh #43: Elasticsearch log target (trntv, beowulfenator)
- Bug: Added accessor method for the default elasticsearch primary key (kyle-mccarthy)
- Enh #83: Support for "gt", ">", "gte", ">=", "lt", "<", "lte", "<=" operators in query (i-lie, beowulfenator)
- Enh #119: Added support for explanation on query (kyle-mccarthy)
- Enh #150: Explicitily send `Content-Type` header in HTTP requests to elasticsearch (lubobill1990)
- Enh: Bulk API implemented and used in AR (tibee, beowulfenator)
- Enh: Deserialization of raw response when text/plain is supported (Tezd)
- Enh: Added ability to work with aliases through Command class (Tezd)


2.0.4 March 17, 2016
Expand Down
Loading

0 comments on commit bc5f1c4

Please sign in to comment.