Skip to content

Commit

Permalink
Fixed broken scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
phamviet committed Nov 30, 2020
1 parent 9cf859f commit 91e9082
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 31 deletions.
6 changes: 3 additions & 3 deletions lib/Elastica/Filter/Ids.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Webonyx\Elastica3x\Filter;

use Webonyx\Elastica3x\Type as Webonyx\Elastica3xType;
use Webonyx\Elastica3x\Type;

trigger_error('Deprecated: Filters are deprecated. Use queries in filter context. See https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-filters.html', E_USER_DEPRECATED);

Expand Down Expand Up @@ -48,7 +48,7 @@ public function addId($id)
*/
public function addType($type)
{
if ($type instanceof Webonyx\Elastica3xType) {
if ($type instanceof Type) {
$type = $type->getName();
} elseif (empty($type) && !is_numeric($type)) {
// TODO: Shouldn't this throw an exception?
Expand All @@ -68,7 +68,7 @@ public function addType($type)
*/
public function setType($type)
{
if ($type instanceof Webonyx\Elastica3xType) {
if ($type instanceof Type) {
$type = $type->getName();
} elseif (empty($type) && !is_numeric($type)) {
// TODO: Shouldn't this throw an exception or let handling of invalid params to ES?
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Filter/Indices.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Webonyx\Elastica3x\Filter;

use Webonyx\Elastica3x\Index as Webonyx\Elastica3xIndex;
use Webonyx\Elastica3x\Index;

trigger_error('Deprecated: Filters are deprecated. Use queries in filter context. See https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-filters.html', E_USER_DEPRECATED);

Expand Down Expand Up @@ -48,7 +48,7 @@ public function setIndices(array $indices)
*/
public function addIndex($index)
{
if ($index instanceof Webonyx\Elastica3xIndex) {
if ($index instanceof Index) {
$index = $index->getName();
}

Expand Down
4 changes: 1 addition & 3 deletions lib/Elastica/Filter/Script.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace Webonyx\Elastica3x\Filter;

use Webonyx\Elastica3x;

trigger_error('Deprecated: Filters are deprecated. Use queries in filter context. See https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-filters.html', E_USER_DEPRECATED);

/**
Expand Down Expand Up @@ -43,7 +41,7 @@ public function __construct($script = null)
*/
public function setScript($script)
{
return $this->setParam('script', Webonyx\Elastica3x\Script\Script::create($script));
return $this->setParam('script', \Webonyx\Elastica3x\Script\Script::create($script));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Elastica/Query/Ids.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Webonyx\Elastica3x\Query;

use Webonyx\Elastica3x\Type as Webonyx\Elastica3xType;
use Webonyx\Elastica3x\Type;

/**
* Ids Query.
Expand Down Expand Up @@ -49,7 +49,7 @@ public function addId($id)
*/
public function addType($type)
{
if ($type instanceof Webonyx\Elastica3xType) {
if ($type instanceof Type) {
$type = $type->getName();
} elseif (empty($type) && !is_numeric($type)) {
// A type can be 0, but cannot be empty
Expand All @@ -70,7 +70,7 @@ public function addType($type)
*/
public function setType($type)
{
if ($type instanceof Webonyx\Elastica3xType) {
if ($type instanceof Type) {
$type = $type->getName();
} elseif (empty($type) && !is_numeric($type)) {
// A type can be 0, but cannot be empty
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Query/Indices.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Webonyx\Elastica3x\Query;

use Webonyx\Elastica3x\Index as Webonyx\Elastica3xIndex;
use Webonyx\Elastica3x\Index;

/**
* Class Indices.
Expand Down Expand Up @@ -45,7 +45,7 @@ public function setIndices(array $indices)
*/
public function addIndex($index)
{
if ($index instanceof Webonyx\Elastica3xIndex) {
if ($index instanceof Index) {
$index = $index->getName();
}

Expand Down
4 changes: 1 addition & 3 deletions lib/Elastica/Query/Script.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace Webonyx\Elastica3x\Query;

use Webonyx\Elastica3x;

/**
* Script query.
*
Expand Down Expand Up @@ -33,7 +31,7 @@ public function __construct($script = null)
*/
public function setScript($script)
{
return $this->setParam('script', Webonyx\Elastica3x\Script\Script::create($script));
return $this->setParam('script', \Webonyx\Elastica3x\Script\Script::create($script));
}

/**
Expand Down
30 changes: 15 additions & 15 deletions lib/Elastica/Transport/HttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Webonyx\Elastica3x\Exception\PartialShardFailureException;
use Webonyx\Elastica3x\Exception\ResponseException;
use Webonyx\Elastica3x\JSON;
use Webonyx\Elastica3x\Request as Webonyx\Elastica3xRequest;
use Webonyx\Elastica3x\Response as Webonyx\Elastica3xResponse;
use Webonyx\Elastica3x\Request;
use Webonyx\Elastica3x\Response;
use Ivory\HttpAdapter\HttpAdapterInterface;
use Ivory\HttpAdapter\Message\Request as HttpAdapterRequest;
use Ivory\HttpAdapter\Message\Response as HttpAdapterResponse;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function __construct(Connection $connection = null, HttpAdapterInterface
*
* @return \Webonyx\Elastica3x\Response Response object
*/
public function exec(Webonyx\Elastica3xRequest $elasticaRequest, array $params)
public function exec(Request $elasticaRequest, array $params)
{
$connection = $this->getConnection();

Expand All @@ -64,7 +64,7 @@ public function exec(Webonyx\Elastica3xRequest $elasticaRequest, array $params)
$httpAdapterResponse = $this->httpAdapter->sendRequest($httpAdapterRequest);
$end = microtime(true);

$elasticaResponse = $this->_createWebonyx\Elastica3xResponse($httpAdapterResponse);
$elasticaResponse = $this->_createResponse($httpAdapterResponse);
$elasticaResponse->setQueryTime($end - $start);

$elasticaResponse->setTransferInfo(
Expand All @@ -88,33 +88,33 @@ public function exec(Webonyx\Elastica3xRequest $elasticaRequest, array $params)
/**
* @param HttpAdapterResponse $httpAdapterResponse
*
* @return Webonyx\Elastica3xResponse
* @return Response
*/
protected function _createWebonyx\Elastica3xResponse(HttpAdapterResponse $httpAdapterResponse)
protected function _createResponse(HttpAdapterResponse $httpAdapterResponse)
{
return new Webonyx\Elastica3xResponse((string) $httpAdapterResponse->getBody(), $httpAdapterResponse->getStatusCode());
return new Response((string) $httpAdapterResponse->getBody(), $httpAdapterResponse->getStatusCode());
}

/**
* @param Webonyx\Elastica3xRequest $elasticaRequest
* @param Request $elasticaRequest
* @param Connection $connection
*
* @return HttpAdapterRequest
*/
protected function _createHttpAdapterRequest(Webonyx\Elastica3xRequest $elasticaRequest, Connection $connection)
protected function _createHttpAdapterRequest(Request $elasticaRequest, Connection $connection)
{
$data = $elasticaRequest->getData();
$body = null;
$method = $elasticaRequest->getMethod();
$headers = $connection->hasConfig('headers') ?: [];
if (!empty($data) || '0' === $data) {
if ($method == Webonyx\Elastica3xRequest::GET) {
$method = Webonyx\Elastica3xRequest::POST;
if ($method == Request::GET) {
$method = Request::POST;
}

if ($this->hasParam('postWithRequestBody') && $this->getParam('postWithRequestBody') == true) {
$elasticaRequest->setMethod(Webonyx\Elastica3xRequest::POST);
$method = Webonyx\Elastica3xRequest::POST;
$elasticaRequest->setMethod(Request::POST);
$method = Request::POST;
}

if (is_array($data)) {
Expand All @@ -131,12 +131,12 @@ protected function _createHttpAdapterRequest(Webonyx\Elastica3xRequest $elastica
}

/**
* @param Webonyx\Elastica3xRequest $request
* @param Request $request
* @param \Webonyx\Elastica3x\Connection $connection
*
* @return string
*/
protected function _getUri(Webonyx\Elastica3xRequest $request, Connection $connection)
protected function _getUri(Request $request, Connection $connection)
{
$url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';

Expand Down

0 comments on commit 91e9082

Please sign in to comment.