Commit b47734b0 authored by Son Nguyen's avatar Son Nguyen

Bug #1613478: Update Elastica library to 2.3.1

behatnotneeded

Change-Id: Ieff16099da370e60c3b695c48e65c8282d5aa3c3
parent a669346b
This diff is collapsed.
Contributing
============
Help is very welcomed. Code contributions must be done in respect of [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).
More details on how to contribute and guidelines for [pull requests](http://elastica.io/contribute/pull-request.html) can be found [here](http://elastica.io/contribute/).
See [Coding guidelines](http://elastica.io/contribute/coding-guidelines.html) for tips on how to do so.
All changes must be documented in the [CHANGELOG.md](https://github.com/ruflin/Elastica/blob/master/CHANGELOG.md).
Issues
------
* Bugs & Feature requests: If you found a bug, open an issue on [Github](https://github.com/ruflin/Elastica/issues). Please search for already reported similary issues before opening a new one. You should include code examples (with dependencies if needed) and your Elastica version to the issue description.
* Questions & Problems: If you have questions or a specific problem, use the [Elastica Gitter](https://gitter.im/ruflin/Elastica) Chat or open an issue on [Stackoverflow](http://stackoverflow.com/questions/tagged/elastica). Make sure to assign the tag Elastica.
Setup
-----
Elastica currently allows two setups for development. Either through vagrant or docker-compose. To use the vagrant environment, run `vagrant up`. To use the docker environment, check out the Makefile for the necessary commands.
* Run your changes / tests in the virtual environment to make sure it is reproducible.
* Run the tests before creating the pull request using vagrant or docker-compose locally.
Commands
--------
To run the commands below, you must have docker-compose [installed](https://docs.docker.com/compose/install/). The first time the commands are run it takes some time to download all the partial images. From then on the commands should run very fast. The advantage in using the commands below is that no local tools and libraries have to be installed and it is guaranteed that everytone is using the same tools.
## Run Tests
To run all tests inside the docker environment, run the following command:
```
make run RUN="make phpunit"
```
If you want to run just a specific test or a one specific file, run the following command by replacing your file with the existingpath:
```
make run RUN="phpunit -c ./test lib/Elastica/Test/SearchTest.php"
```
## Check style of your code
This command will call php-cs-fixer with the predefined settings for the elastica project. No local setup of the tools is needed as everything will happen directly in the container.
```
make run RUN="make lint"
```
Coding
------
### Rules
* Pull requests are made to master. Changes are never pushed directly (without pull request) into master.
* We use the Forking Workflow. https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
* Follow the coding guidelines.
* Use a feature branch for every pull request. Don't open a pull request from your master branch.
### Pull Requests
* One change per pull requests: Keep your pull requests as small as possible. Only one change should happen per pull request. This makes it easier to review and provided feedback. If you have a large pull request, try to split it up in multiple smaller requests.
* Commit messages: Make sure that your commit messages have meaning and provide an understanding on what was changed without looking at the code.
* Pull requests should be opened as early as possible as pull requests are also here for communication / discussing changes. Add a comment when your pull request is ready to be merged.
* Tests: Your addition / change must be tested and the builds must be green. Test your changes locally. Add unit tests and if possible functional tests. Don't forget to add the group to your tests. The 4 available groups are @functional, @unit, @shutdown, @benchmark
* Update the CHANGELOG.md file with your changes
* Backward Compatibility breaks: In case you break backward compatibility, provide details on why this is needed.
* Merge: No one should ever merge his own pull request
### Name Spaces & Classes
Most name spaces and classes are self explanotary and use cases can be taken from classes which already exist.
#### Tool Namespace
The namespace Tool is used for making more complex functionality of Elastica available to the users. In general it maps existing functionality of Elastica and offers simplified functions.
#### Util Class
The util class is used for all static functions which are used in the Elastica library but don't access the library itself.
......@@ -2,12 +2,13 @@ Elastica in Mahara
======================
Website: http://elastica.io
Version: 2.0.0
Version: 2.3.1
This library is used for for interfacing with an elasticsearch server.
Dependencies:
* Elasticsearch 1.7.3
Changes:
* Removed build & test files not needed for Mahara.
* Added an option to do include the Elasticsearch Index in the URL for bulk addDocument calls
\ No newline at end of file
......@@ -3,28 +3,29 @@ Elastica: elasticsearch PHP Client
[![Latest Stable Version](https://poser.pugx.org/ruflin/Elastica/v/stable.png)](https://packagist.org/packages/ruflin/elastica)
[![Build Status](https://secure.travis-ci.org/ruflin/Elastica.png?branch=master)](http://travis-ci.org/ruflin/Elastica)
[![Coverage Status](https://coveralls.io/repos/ruflin/Elastica/badge.png)](https://coveralls.io/r/ruflin/Elastica)
[![Dependency Status](https://www.versioneye.com/php/ruflin:Elastica/master/badge.png)](https://www.versioneye.com/php/ruflin:elastica/)
[![codecov.io](http://codecov.io/github/ruflin/Elastica/coverage.svg?branch=master)](http://codecov.io/github/ruflin/Elastica?branch=master)
[![Dependency Status](https://www.versioneye.com/php/ruflin:elastica/dev-master/badge.svg)](https://www.versioneye.com/php/ruflin:elastica/dev-master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ruflin/Elastica/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ruflin/Elastica/?branch=master)
[![Total Downloads](https://poser.pugx.org/ruflin/Elastica/downloads.png)](https://packagist.org/packages/ruflin/elastica)
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=ruflin&url=https://github.com/ruflin/Elastica&title=Elastica&language=PHP&tags=github&category=software)
[![Join the chat at https://gitter.im/ruflin/Elastica](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ruflin/Elastica?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
All documentation for Elastica can be found under [Elastica.io](http://Elastica.io/). If you have questions, don't hesitate to ask them in the [Elastica google group](https://groups.google.com/group/elastica-php-client). All library issues should go to the [issue tracker from github](https://github.com/ruflin/Elastica/issues).
All documentation for Elastica can be found under [Elastica.io](http://Elastica.io/).
If you have questions, don't hesitate to ask them on [Stackoverflow](http://stackoverflow.com/questions/tagged/elastica) and add the Tag "Elastica" or
in our [Gitter](https://gitter.im/ruflin/Elastica) channel.
All library issues should go to the [issue tracker from github](https://github.com/ruflin/Elastica/issues).
Contributing
------------
Help is very welcomed, but code contributions must be done in respect of [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). More details on how to contribute and guidelines for [pull requests](http://elastica.io/contribute/pull-request.html) can be found [here](http://elastica.io/contribute/).
See [Coding guidelines](http://elastica.io/contribute/coding-guidelines.html) for tips on how to do so. All changes which are made to the project are added to the [changes.txt](https://github.com/ruflin/Elastica/blob/master/changes.txt).
Contributions are always welcome. For details on how to contribute, check the [CONTRIBUTING](https://github.com/ruflin/Elastica/blob/master/CONTRIBUTING.md) file.
Dependencies
------------
| Project | Version | Required |
|---------|---------|----------|
|[Elasticsearch](https://github.com/elasticsearch/elasticsearch/tree/v1.5.2)|1.5.2|yes|
|[Elasticsearch mapper attachments plugin](https://github.com/elasticsearch/elasticsearch-mapper-attachments/tree/v2.5.0)|2.5.0|no|
|[Elasticsearch thrift transport plugin](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/v2.5.0)|2.5.0|no|
|[Elasticsearch memcached transport plugin](https://github.com/elasticsearch/elasticsearch-transport-memcached/tree/v2.5.0)|2.5.0|no|
|[Elasticsearch](https://github.com/elasticsearch/elasticsearch/tree/v1.7.2)|1.7.2|yes|
|[Elasticsearch mapper attachments plugin](https://github.com/elasticsearch/elasticsearch-mapper-attachments/tree/v2.7.0)|2.7.0|no|
|[Elasticsearch thrift transport plugin](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/v2.7.0)|2.7.0|no|
|[Elasticsearch memcached transport plugin](https://github.com/elastic/elasticsearch-transport-memcached/tree/v2.7.0)|2.7.0|no|
|[Elasticsearch geocluster facet plugin](https://github.com/zenobase/geocluster-facet/tree/0.0.12)|0.0.12|no|
|[Elasticsearch image plugin](https://github.com/SibaTokyo/elasticsearch-image/tree/1.4.0)|1.4.0|no|
|[Elasticsearch image plugin](https://github.com/Jmoati/elasticsearch-image/releases/tag/1.7.1)|1.7.1|no|
<?php
namespace Elastica;
/**
* Base class for Script object.
*
* @author Nicolas Assing <nicolas.assing@gmail.com>
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
*/
abstract class AbstractScript extends AbstractUpdateAction
{
/**
* @param array|null $params
* @param string $id
*/
public function __construct(array $params = null, $id = null)
{
if ($params) {
$this->setParams($params);
}
if ($id) {
$this->setId($id);
}
}
}
<?php
namespace Elastica;
/**
* Base class for things that can be sent to the update api (Document and
* Script).
*
* @category Xodoa
* @package Elastica
* @author Nik Everett <nik9000@gmail.com>
*/
class AbstractUpdateAction extends Param
......@@ -20,7 +17,8 @@ class AbstractUpdateAction extends Param
/**
* Sets the id of the document.
*
* @param string $id
* @param string $id
*
* @return $this
*/
public function setId($id)
......@@ -29,7 +27,7 @@ class AbstractUpdateAction extends Param
}
/**
* Returns document id
* Returns document id.
*
* @return string|int Document id
*/
......@@ -47,9 +45,10 @@ class AbstractUpdateAction extends Param
}
/**
* Sets lifetime of document
* Sets lifetime of document.
*
* @param string $ttl
*
* @param string $ttl
* @return $this
*/
public function setTtl($ttl)
......@@ -74,9 +73,10 @@ class AbstractUpdateAction extends Param
}
/**
* Sets the document type name
* Sets the document type name.
*
* @param string $type Type name
*
* @param string $type Type name
* @return $this
*/
public function setType($type)
......@@ -90,7 +90,7 @@ class AbstractUpdateAction extends Param
}
/**
* Return document type name
* Return document type name.
*
* @throws \Elastica\Exception\InvalidException
*
......@@ -102,9 +102,10 @@ class AbstractUpdateAction extends Param
}
/**
* Sets the document index name
* Sets the document index name.
*
* @param string $index Index name
*
* @param string $index Index name
* @return $this
*/
public function setIndex($index)
......@@ -117,7 +118,7 @@ class AbstractUpdateAction extends Param
}
/**
* Get the document index name
* Get the document index name.
*
* @throws \Elastica\Exception\InvalidException
*
......@@ -129,10 +130,12 @@ class AbstractUpdateAction extends Param
}
/**
* Sets the version of a document for use with optimistic concurrency control
* Sets the version of a document for use with optimistic concurrency control.
*
* @param int $version Document version
*
* @param int $version Document version
* @return $this
*
* @link https://www.elastic.co/blog/versioning
*/
public function setVersion($version)
......@@ -141,7 +144,7 @@ class AbstractUpdateAction extends Param
}
/**
* Returns document version
* Returns document version.
*
* @return string|int Document version
*/
......@@ -160,9 +163,10 @@ class AbstractUpdateAction extends Param
/**
* Sets the version_type of a document
* Default in ES is internal, but you can set to external to use custom versioning
* Default in ES is internal, but you can set to external to use custom versioning.
*
* @param int $versionType Document version type
*
* @param int $versionType Document version type
* @return $this
*/
public function setVersionType($versionType)
......@@ -171,7 +175,7 @@ class AbstractUpdateAction extends Param
}
/**
* Returns document version type
* Returns document version type.
*
* @return string|int Document version type
*/
......@@ -189,10 +193,12 @@ class AbstractUpdateAction extends Param
}
/**
* Sets parent document id
* Sets parent document id.
*
* @param string|int $parent Parent document id
*
* @param string|int $parent Parent document id
* @return $this
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html
*/
public function setParent($parent)
......@@ -201,7 +207,7 @@ class AbstractUpdateAction extends Param
}
/**
* Returns the parent document id
* Returns the parent document id.
*
* @return string|int Parent document id
*/
......@@ -219,9 +225,10 @@ class AbstractUpdateAction extends Param
}
/**
* Set operation type
* Set operation type.
*
* @param string $opType Only accept create
*
* @param string $opType Only accept create
* @return $this
*/
public function setOpType($opType)
......@@ -230,7 +237,8 @@ class AbstractUpdateAction extends Param
}
/**
* Get operation type
* Get operation type.
*
* @return string
*/
public function getOpType()
......@@ -247,9 +255,10 @@ class AbstractUpdateAction extends Param
}
/**
* Set percolate query param
* Set percolate query param.
*
* @param string $value percolator filter
*
* @param string $value percolator filter
* @return $this
*/
public function setPercolate($value = '*')
......@@ -258,7 +267,7 @@ class AbstractUpdateAction extends Param
}
/**
* Get percolate parameter
* Get percolate parameter.
*
* @return string
*/
......@@ -276,9 +285,10 @@ class AbstractUpdateAction extends Param
}
/**
* Set routing query param
* Set routing query param.
*
* @param string $value routing
*
* @param string $value routing
* @return $this
*/
public function setRouting($value)
......@@ -287,7 +297,7 @@ class AbstractUpdateAction extends Param
}
/**
* Get routing parameter
* Get routing parameter.
*
* @return string
*/
......@@ -305,7 +315,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param array|string $fields
* @param array|string $fields
*
* @return $this
*/
public function setFields($fields)
......@@ -342,7 +353,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param int $num
* @param int $num
*
* @return $this
*/
public function setRetryOnConflict($num)
......@@ -367,7 +379,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param string $timestamp
* @param string $timestamp
*
* @return $this
*/
public function setTimestamp($timestamp)
......@@ -392,7 +405,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param bool $refresh
* @param bool $refresh
*
* @return $this
*/
public function setRefresh($refresh = true)
......@@ -417,7 +431,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param string $timeout
* @param string $timeout
*
* @return $this
*/
public function setTimeout($timeout)
......@@ -442,7 +457,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param string $timeout
* @param string $timeout
*
* @return $this
*/
public function setConsistency($timeout)
......@@ -467,7 +483,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param string $timeout
* @param string $timeout
*
* @return $this
*/
public function setReplication($timeout)
......@@ -492,7 +509,8 @@ class AbstractUpdateAction extends Param
}
/**
* @param \Elastica\Document|array $data
* @param \Elastica\Document|array $data
*
* @return $this
*/
public function setUpsert($data)
......@@ -520,8 +538,9 @@ class AbstractUpdateAction extends Param
}
/**
* @param array $fields if empty array all options will be returned, field names can be either with underscored either without, i.e. _percolate, routing
* @param bool $withUnderscore should option keys contain underscore prefix
* @param array $fields if empty array all options will be returned, field names can be either with underscored either without, i.e. _percolate, routing
* @param bool $withUnderscore should option keys contain underscore prefix
*
* @return array
*/
public function getOptions(array $fields = array(), $withUnderscore = false)
......
<?php
namespace Elastica\Aggregation;
use Elastica\Exception\InvalidException;
use Elastica\NameableInterface;
use Elastica\Param;
abstract class AbstractAggregation extends Param
abstract class AbstractAggregation extends Param implements NameableInterface
{
/**
* @var string The name of this aggregation
......@@ -26,8 +26,11 @@ abstract class AbstractAggregation extends Param
}
/**
* Set the name of this aggregation
* Set the name of this aggregation.
*
* @param string $name
*
* @return $this
*/
public function setName($name)
{
......@@ -37,7 +40,8 @@ abstract class AbstractAggregation extends Param
}
/**
* Retrieve the name of this aggregation
* Retrieve the name of this aggregation.
*
* @return string
*/
public function getName()
......@@ -46,7 +50,8 @@ abstract class AbstractAggregation extends Param
}
/**
* Retrieve all subaggregations belonging to this aggregation
* Retrieve all subaggregations belonging to this aggregation.
*
* @return array
*/
public function getAggs()
......@@ -55,10 +60,12 @@ abstract class AbstractAggregation extends Param
}
/**
* Add a sub-aggregation
* Add a sub-aggregation.
*
* @param AbstractAggregation $aggregation
*
* @throws \Elastica\Exception\InvalidException
*
* @param AbstractAggregation $aggregation
* @return $this
*/
public function addAggregation(AbstractAggregation $aggregation)
......@@ -67,7 +74,7 @@ abstract class AbstractAggregation extends Param
throw new InvalidException('Global aggregators can only be placed as top level aggregators');
}
$this->_aggs[$aggregation->getName()] = $aggregation->toArray();
$this->_aggs[] = $aggregation;
return $this;
}
......@@ -78,12 +85,13 @@ abstract class AbstractAggregation extends Param
public function toArray()
{
$array = parent::toArray();
if (array_key_exists('global_aggregation', $array)) {
// compensate for class name GlobalAggregation
$array = array('global' => new \stdClass());
}
if (sizeof($this->_aggs)) {
$array['aggs'] = $this->_aggs;
$array['aggs'] = $this->_convertArrayable($this->_aggs);
}
return $array;
......
<?php
namespace Elastica\Aggregation;
use Elastica\Script;
......@@ -7,8 +6,10 @@ use Elastica\Script;
abstract class AbstractSimpleAggregation extends AbstractAggregation
{
/**
* Set the field for this aggregation
* @param string $field the name of the document field on which to perform this aggregation
* Set the field for this aggregation.
*
* @param string $field the name of the document field on which to perform this aggregation
*
* @return $this
*/
public function setField($field)
......@@ -17,18 +18,34 @@ abstract class AbstractSimpleAggregation extends AbstractAggregation
}
/**
* Set a script for this aggregation
* @param string|Script $script
* Set a script for this aggregation.
*
* @param string|Script $script
*
* @return $this
*/
public function setScript($script)
{
if ($script instanceof Script) {
$params = array_merge($this->getParams(), $script->toArray());
return $this->setParam('script', $script);
}
return $this->setParams($params);
/**
* {@inheritdoc}
*/
public function toArray()
{
$array = parent::toArray();
$baseName = $this->_getBaseName();
if (isset($array[$baseName]['script']) && is_array($array[$baseName]['script'])) {
$script = $array[$baseName]['script'];
unset($array[$baseName]['script']);
$array[$baseName] = array_merge($array[$baseName], $script);
}
return $this->setParam('script', $script);
return $array;
}
}