Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre 7.2 endpoint class name with aliases + reapply fix #947 #968

Merged
merged 5 commits into from
Nov 26, 2019
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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"monolog/monolog": "Allows for client-level logging and tracing"
},
"autoload": {
"files": [
"src/autoload.php"
],
"psr-4": {
"Elasticsearch\\": "src/Elasticsearch/"
}
Expand Down
16 changes: 14 additions & 2 deletions src/Elasticsearch/Namespaces/IndicesNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,20 @@ public function getAlias(array $params = [])
$endpoint->setIndex($index);

return $this->performRequest($endpoint);
} /**
}

/**
* Alias function to getAlias()
*
* @deprecated added to prevent BC break introduced in 7.2.0
* @see https://github.com/elastic/elasticsearch-php/issues/940
*/
public function getAliases(array $params = [])
{
return $this->getAlias($params);
}

/**
* $params['fields'] = (list) A comma-separated list of fields (Required)
* $params['index'] = (list) A comma-separated list of index names
* $params['type'] = DEPRECATED (list) A comma-separated list of document types
Expand All @@ -450,7 +463,6 @@ public function getAlias(array $params = [])
* @return array
* @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html
*/

public function getFieldMapping(array $params = [])
{
$fields = $this->extractArgument($params, 'fields');
Expand Down
49 changes: 49 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* File required since elasticsearch-php 7.4.1 for aliasing
* to the previous endpoint class names.
*
* @see https://github.com/elastic/elasticsearch-php/issues/967
*
* NOTE: This file will be removed with elasticsearch-php 8.0.0
*/

class_alias('\Elasticsearch\Endpoints\Cat\Nodeattrs', '\Elasticsearch\Endpoints\Cat\NodeAttrs');
class_alias('\Elasticsearch\Endpoints\Cluster\GetSettings', '\Elasticsearch\Endpoints\Cluster\Settings\Get');
class_alias('\Elasticsearch\Endpoints\Cluster\PutSettings', '\Elasticsearch\Endpoints\Cluster\Settings\Put');
class_alias('\Elasticsearch\Endpoints\Indices\DeleteAlias', '\Elasticsearch\Endpoints\Indices\Alias\Delete');
class_alias('\Elasticsearch\Endpoints\Indices\ExistsAlias', '\Elasticsearch\Endpoints\Indices\Alias\Exists');
class_alias('\Elasticsearch\Endpoints\Indices\GetAlias', '\Elasticsearch\Endpoints\Indices\Alias\Get');
class_alias('\Elasticsearch\Endpoints\Indices\PutAlias', '\Elasticsearch\Endpoints\Indices\Alias\Put');
class_alias('\Elasticsearch\Endpoints\Indices\UpdateAliases', '\Elasticsearch\Endpoints\Indices\Aliases\Update');
class_alias('\Elasticsearch\Endpoints\Indices\ClearCache', '\Elasticsearch\Endpoints\Indices\Cache\Clear');
class_alias('\Elasticsearch\Endpoints\Indices\Forcemerge', '\Elasticsearch\Endpoints\Indices\ForceMerge');
class_alias('\Elasticsearch\Endpoints\Indices\GetMapping', '\Elasticsearch\Endpoints\Indices\Mapping\Get');
class_alias('\Elasticsearch\Endpoints\Indices\GetFieldMapping', '\Elasticsearch\Endpoints\Indices\Mapping\GetField');
class_alias('\Elasticsearch\Endpoints\Indices\PutMapping', '\Elasticsearch\Endpoints\Indices\Mapping\Put');
class_alias('\Elasticsearch\Endpoints\Indices\GetSettings', '\Elasticsearch\Endpoints\Indices\Settings\Get');
class_alias('\Elasticsearch\Endpoints\Indices\PutSettings', '\Elasticsearch\Endpoints\Indices\Settings\Put');
class_alias('\Elasticsearch\Endpoints\Indices\GetTemplate', '\Elasticsearch\Endpoints\Indices\Template\Get');
class_alias('\Elasticsearch\Endpoints\Indices\PutTemplate', '\Elasticsearch\Endpoints\Indices\Template\Put');
class_alias('\Elasticsearch\Endpoints\Indices\ExistsTemplate', '\Elasticsearch\Endpoints\Indices\Template\Exists');
class_alias('\Elasticsearch\Endpoints\Indices\DeleteTemplate', '\Elasticsearch\Endpoints\Indices\Template\Delete');
class_alias('\Elasticsearch\Endpoints\Indices\ExistsType', '\Elasticsearch\Endpoints\Indices\Type\Exists');
class_alias('\Elasticsearch\Endpoints\Indices\GetUpgrade', '\Elasticsearch\Endpoints\Indices\Upgrade\Get');
class_alias('\Elasticsearch\Endpoints\Indices\Upgrade', '\Elasticsearch\Endpoints\Indices\Upgrade\Post');
class_alias('\Elasticsearch\Endpoints\Indices\ValidateQuery', '\Elasticsearch\Endpoints\Indices\Validate\Query');
class_alias('\Elasticsearch\Endpoints\Ingest\DeletePipeline', '\Elasticsearch\Endpoints\Ingest\Pipeline\Delete');
class_alias('\Elasticsearch\Endpoints\Ingest\GetPipeline', '\Elasticsearch\Endpoints\Ingest\Pipeline\Get');
class_alias('\Elasticsearch\Endpoints\Ingest\PutPipeline', '\Elasticsearch\Endpoints\Ingest\Pipeline\Put');
class_alias('\Elasticsearch\Endpoints\Ingest\ProcessorGrok', '\Elasticsearch\Endpoints\Ingest\Pipeline\ProcessorGrok');
class_alias('\Elasticsearch\Endpoints\Mtermvectors', '\Elasticsearch\Endpoints\MTermVectors');
class_alias('\Elasticsearch\Endpoints\GetScript', '\Elasticsearch\Endpoints\Script\Get');
class_alias('\Elasticsearch\Endpoints\PutScript', '\Elasticsearch\Endpoints\Script\Put');
class_alias('\Elasticsearch\Endpoints\DeleteScript', '\Elasticsearch\Endpoints\Script\Delete');
class_alias('\Elasticsearch\Endpoints\Snapshot\CreateRepository', '\Elasticsearch\Endpoints\Snapshot\Repository\Create');
class_alias('\Elasticsearch\Endpoints\Snapshot\DeleteRepository', '\Elasticsearch\Endpoints\Snapshot\Repository\Delete');
class_alias('\Elasticsearch\Endpoints\Snapshot\GetRepository', '\Elasticsearch\Endpoints\Snapshot\Repository\Get');
class_alias('\Elasticsearch\Endpoints\Snapshot\VerifyRepository', '\Elasticsearch\Endpoints\Snapshot\Repository\Verify');
class_alias('\Elasticsearch\Endpoints\GetSource', '\Elasticsearch\Endpoints\Source\Get');
class_alias('\Elasticsearch\Endpoints\ExistsSource', '\Elasticsearch\Endpoints\Source\Exists');
class_alias('\Elasticsearch\Endpoints\Tasks\ListTasks', '\Elasticsearch\Endpoints\Tasks\TasksList');
class_alias('\Elasticsearch\Endpoints\Termvectors', '\Elasticsearch\Endpoints\TermVectors');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alias is not needed, same name on both sides

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case has changed. But I'm not sure if class names are case sensitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thePanz is right here. The alias cannot be done for case sensitive, since classes are case insensitive in PHP (even if the autoloading of composer is case sensitive). I'll just reuse the old class naming convention here.

154 changes: 154 additions & 0 deletions tests/Elasticsearch/BackwardCompatibleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
declare(strict_types = 1);

namespace Elasticsearch\Tests;

/**
* Class BackwardCompatibleTest
*
* @category Tests
* @package Elasticsearch
* @subpackage Tests
* @author Enrico Zimuel <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/
class BackwardCompatibleTest extends \PHPUnit\Framework\TestCase
{
/**
* List of endpoints in elasticsearch-php 7.2 branch
*/
public function getClasses()
{
return [
['Elasticsearch\Endpoints\MTermVectors'],
['Elasticsearch\Endpoints\Tasks\Get'],
['Elasticsearch\Endpoints\Tasks\Cancel'],
['Elasticsearch\Endpoints\Tasks\TasksList'],
['Elasticsearch\Endpoints\Ping'],
['Elasticsearch\Endpoints\ScriptsPainlessExecute'],
['Elasticsearch\Endpoints\DeleteByQuery'],
['Elasticsearch\Endpoints\Scroll'],
['Elasticsearch\Endpoints\Explain'],
['Elasticsearch\Endpoints\Get'],
['Elasticsearch\Endpoints\UpdateByQueryRethrottle'],
['Elasticsearch\Endpoints\Delete'],
['Elasticsearch\Endpoints\SearchShards'],
['Elasticsearch\Endpoints\Mget'],
['Elasticsearch\Endpoints\Source\Get'],
['Elasticsearch\Endpoints\Source\Exists'],
['Elasticsearch\Endpoints\Bulk'],
['Elasticsearch\Endpoints\Cluster\PendingTasks'],
['Elasticsearch\Endpoints\Cluster\Health'],
['Elasticsearch\Endpoints\Cluster\Settings\Get'],
['Elasticsearch\Endpoints\Cluster\Settings\Put'],
['Elasticsearch\Endpoints\Cluster\Reroute'],
['Elasticsearch\Endpoints\Cluster\State'],
['Elasticsearch\Endpoints\Cluster\RemoteInfo'],
['Elasticsearch\Endpoints\Cluster\Stats'],
['Elasticsearch\Endpoints\Cluster\AllocationExplain'],
['Elasticsearch\Endpoints\ClearScroll'],
['Elasticsearch\Endpoints\Script\Get'],
['Elasticsearch\Endpoints\Script\Delete'],
['Elasticsearch\Endpoints\Script\Put'],
['Elasticsearch\Endpoints\Exists'],
['Elasticsearch\Endpoints\Index'],
['Elasticsearch\Endpoints\UpdateByQuery'],
['Elasticsearch\Endpoints\Ingest\Pipeline\Get'],
['Elasticsearch\Endpoints\Ingest\Pipeline\Delete'],
['Elasticsearch\Endpoints\Ingest\Pipeline\Put'],
['Elasticsearch\Endpoints\Ingest\Pipeline\ProcessorGrok'],
['Elasticsearch\Endpoints\Ingest\Simulate'],
['Elasticsearch\Endpoints\SearchTemplate'],
['Elasticsearch\Endpoints\FieldCaps'],
['Elasticsearch\Endpoints\Snapshot\Get'],
['Elasticsearch\Endpoints\Snapshot\Delete'],
['Elasticsearch\Endpoints\Snapshot\Restore'],
['Elasticsearch\Endpoints\Snapshot\Create'],
['Elasticsearch\Endpoints\Snapshot\Status'],
['Elasticsearch\Endpoints\Snapshot\Repository\Verify'],
['Elasticsearch\Endpoints\Snapshot\Repository\Get'],
['Elasticsearch\Endpoints\Snapshot\Repository\Delete'],
['Elasticsearch\Endpoints\Snapshot\Repository\Create'],
['Elasticsearch\Endpoints\Count'],
['Elasticsearch\Endpoints\Create'],
['Elasticsearch\Endpoints\Info'],
['Elasticsearch\Endpoints\Indices\Type\Exists'],
['Elasticsearch\Endpoints\Indices\ForceMerge'],
['Elasticsearch\Endpoints\Indices\Flush'],
['Elasticsearch\Endpoints\Indices\Analyze'],
['Elasticsearch\Endpoints\Indices\Rollover'],
['Elasticsearch\Endpoints\Indices\Get'],
['Elasticsearch\Endpoints\Indices\Template\Get'],
['Elasticsearch\Endpoints\Indices\Template\Delete'],
['Elasticsearch\Endpoints\Indices\Template\Exists'],
['Elasticsearch\Endpoints\Indices\Template\Put'],
['Elasticsearch\Endpoints\Indices\Delete'],
['Elasticsearch\Endpoints\Indices\FlushSynced'],
['Elasticsearch\Endpoints\Indices\Refresh'],
['Elasticsearch\Endpoints\Indices\Exists'],
['Elasticsearch\Endpoints\Indices\Cache\Clear'],
['Elasticsearch\Endpoints\Indices\Settings\Get'],
['Elasticsearch\Endpoints\Indices\Settings\Put'],
['Elasticsearch\Endpoints\Indices\Create'],
['Elasticsearch\Endpoints\Indices\Close'],
['Elasticsearch\Endpoints\Indices\ShardStores'],
['Elasticsearch\Endpoints\Indices\Stats'],
['Elasticsearch\Endpoints\Indices\Validate\Query'],
['Elasticsearch\Endpoints\Indices\Alias\Get'],
['Elasticsearch\Endpoints\Indices\Alias\Delete'],
['Elasticsearch\Endpoints\Indices\Alias\Exists'],
['Elasticsearch\Endpoints\Indices\Alias\Put'],
['Elasticsearch\Endpoints\Indices\Open'],
['Elasticsearch\Endpoints\Indices\Segments'],
['Elasticsearch\Endpoints\Indices\Upgrade\Get'],
['Elasticsearch\Endpoints\Indices\Upgrade\Post'],
['Elasticsearch\Endpoints\Indices\Aliases\Update'],
['Elasticsearch\Endpoints\Indices\Recovery'],
['Elasticsearch\Endpoints\Indices\Shrink'],
['Elasticsearch\Endpoints\Indices\Split'],
['Elasticsearch\Endpoints\Indices\Mapping\Get'],
['Elasticsearch\Endpoints\Indices\Mapping\Put'],
['Elasticsearch\Endpoints\Indices\Mapping\GetField'],
['Elasticsearch\Endpoints\Reindex'],
['Elasticsearch\Endpoints\DeleteByQueryRethrottle'],
['Elasticsearch\Endpoints\MsearchTemplate'],
['Elasticsearch\Endpoints\TermVectors'],
['Elasticsearch\Endpoints\AbstractEndpoint'],
['Elasticsearch\Endpoints\RenderSearchTemplate'],
['Elasticsearch\Endpoints\Update'],
['Elasticsearch\Endpoints\Search'],
['Elasticsearch\Endpoints\ReindexRethrottle'],
['Elasticsearch\Endpoints\RankEval'],
['Elasticsearch\Endpoints\Msearch'],
['Elasticsearch\Endpoints\Cat\ThreadPool'],
['Elasticsearch\Endpoints\Cat\Fielddata'],
['Elasticsearch\Endpoints\Cat\Master'],
['Elasticsearch\Endpoints\Cat\NodeAttrs'],
['Elasticsearch\Endpoints\Cat\Aliases'],
['Elasticsearch\Endpoints\Cat\PendingTasks'],
['Elasticsearch\Endpoints\Cat\Templates'],
['Elasticsearch\Endpoints\Cat\Allocation'],
['Elasticsearch\Endpoints\Cat\Plugins'],
['Elasticsearch\Endpoints\Cat\Health'],
['Elasticsearch\Endpoints\Cat\Count'],
['Elasticsearch\Endpoints\Cat\Shards'],
['Elasticsearch\Endpoints\Cat\Repositories'],
['Elasticsearch\Endpoints\Cat\Nodes'],
['Elasticsearch\Endpoints\Cat\Tasks'],
['Elasticsearch\Endpoints\Cat\Segments'],
['Elasticsearch\Endpoints\Cat\Help'],
['Elasticsearch\Endpoints\Cat\Recovery'],
['Elasticsearch\Endpoints\Cat\Snapshots'],
['Elasticsearch\Endpoints\Cat\Indices']
];
}

/**
* @dataProvider getClasses
*/
public function testOldClassNamespacesPreviousTo72($class)
{
$this->assertTrue(class_exists($class), sprintf("Class %s does not exist", $class));
}
}