Skip to content

Commit 752d5a2

Browse files
committed
Tasks/List and Tasks/Get are now separate endpoints
1 parent 9eb573a commit 752d5a2

File tree

4 files changed

+81
-15
lines changed

4 files changed

+81
-15
lines changed

src/Elasticsearch/Endpoints/Tasks/Get.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function setTaskId($taskId)
4141
*/
4242
public function getURI()
4343
{
44-
if (isset($this->id) === true) {
44+
if (isset($this->taskId) === true) {
4545
return "/_tasks/{$this->taskId}";
4646
}
4747

@@ -54,14 +54,7 @@ public function getURI()
5454
public function getParamWhitelist()
5555
{
5656
return array(
57-
'node_id',
58-
'actions',
59-
'detailed',
60-
'parent_node',
61-
'parent_task',
62-
'wait_for_completion',
63-
'group_by',
64-
'task_id'
57+
'wait_for_completion'
6558
);
6659
}
6760

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Elasticsearch\Endpoints\Tasks;
4+
5+
use Elasticsearch\Common\Exceptions;
6+
use Elasticsearch\Endpoints\AbstractEndpoint;
7+
8+
/**
9+
* Class TasksLists
10+
*
11+
* @category Elasticsearch
12+
* @package Elasticsearch\Endpoints\Tasks
13+
* @author Zachary Tong <zach@elastic.co>
14+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
15+
* @link http://elastic.co
16+
*/
17+
class TasksList extends AbstractEndpoint
18+
{
19+
20+
/**
21+
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
22+
* @return string
23+
*/
24+
public function getURI()
25+
{
26+
return "/_tasks";
27+
}
28+
29+
/**
30+
* @return string[]
31+
*/
32+
public function getParamWhitelist()
33+
{
34+
return array(
35+
'node_id',
36+
'actions',
37+
'detailed',
38+
'parent_node',
39+
'parent_task',
40+
'wait_for_completion',
41+
'group_by',
42+
'task_id'
43+
);
44+
}
45+
46+
/**
47+
* @return string
48+
*/
49+
public function getMethod()
50+
{
51+
return 'GET';
52+
}
53+
}

src/Elasticsearch/Namespaces/TasksNamespace.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@
1616
*/
1717
class TasksNamespace extends AbstractNamespace
1818
{
19+
/**
20+
* $params['wait_for_completion'] = (bool) Wait for the matching tasks to complete (default: false)
21+
*
22+
* @param $params array Associative array of parameters
23+
*
24+
* @return array
25+
*/
26+
public function get($params = array())
27+
{
28+
$id = $this->extractArgument($params, 'task_id');
29+
30+
/** @var callback $endpointBuilder */
31+
$endpointBuilder = $this->endpoints;
32+
33+
/** @var Get $endpoint */
34+
$endpoint = $endpointBuilder('Tasks\Get');
35+
$endpoint->setTaskId($id)
36+
->setParams($params);
37+
38+
return $this->performRequest($endpoint);
39+
}
40+
1941
/**
2042
* $params['node_id'] = (list) A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes
2143
* ['actions'] = (list) A comma-separated list of actions that should be cancelled. Leave empty to cancel all.
@@ -29,17 +51,15 @@ class TasksNamespace extends AbstractNamespace
2951
*
3052
* @return array
3153
*/
32-
public function get($params = array())
54+
public function tasksList($params = array())
3355
{
34-
$id = $this->extractArgument($params, 'id');
3556

3657
/** @var callback $endpointBuilder */
3758
$endpointBuilder = $this->endpoints;
3859

3960
/** @var Get $endpoint */
40-
$endpoint = $endpointBuilder('Tasks\Get');
41-
$endpoint->setTaskId($id)
42-
->setParams($params);
61+
$endpoint = $endpointBuilder('Tasks\TasksList');
62+
$endpoint->setParams($params);
4363

4464
return $this->performRequest($endpoint);
4565
}

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
4848
/** @var array A mapping for endpoint when there is a reserved keywords for the method / namespace name */
4949
private static $endpointMapping = [
5050
'tasks' => [
51-
'list' => ['get', 'tasks'],
51+
'list' => ['tasksList', 'tasks'],
5252
],
5353
];
5454

0 commit comments

Comments
 (0)