|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Elastification\Client\Request\Shared\Bulk; |
|
20
|
|
|
|
|
21
|
|
|
use Elastification\Client\Request\RequestMethods; |
|
22
|
|
|
use Elastification\Client\Request\Shared\AbstractBaseRequest; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class AbstractCreateIndexRequest |
|
26
|
|
|
* |
|
27
|
|
|
* @package Elastification\Client\Request\Shared\Index |
|
28
|
|
|
* @author Daniel Wendlandt |
|
29
|
|
|
*/ |
|
30
|
|
|
abstract class AbstractBulkDeleteRequest extends AbstractBaseRequest |
|
31
|
|
|
{ |
|
32
|
|
|
const LINE_BREAK = "\n"; |
|
33
|
|
|
const REQUEST_ACTION = '_bulk'; |
|
34
|
|
|
const BULK_ACTION = 'delete'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var null|mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
private $body = null; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* This will overwrite getIndex method for returning null. |
|
43
|
|
|
* The index property is only for internal use. |
|
44
|
|
|
* |
|
45
|
|
|
* @return null |
|
46
|
|
|
*/ |
|
47
|
3 |
|
public function getIndex() |
|
48
|
|
|
{ |
|
49
|
3 |
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* This will overwrite getType method for returning null. |
|
54
|
|
|
* The type property is only for internal use. |
|
55
|
|
|
* |
|
56
|
|
|
* @return null |
|
57
|
|
|
*/ |
|
58
|
3 |
|
public function getType() |
|
59
|
|
|
{ |
|
60
|
3 |
|
return null; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @inheritdoc |
|
65
|
|
|
*/ |
|
66
|
3 |
|
public function getMethod() |
|
67
|
|
|
{ |
|
68
|
3 |
|
return RequestMethods::POST; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @inheritdoc |
|
73
|
|
|
*/ |
|
74
|
3 |
|
public function getAction() |
|
75
|
|
|
{ |
|
76
|
3 |
|
return self::REQUEST_ACTION; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @inheritdoc |
|
81
|
|
|
*/ |
|
82
|
6 |
|
public function getBody() |
|
83
|
|
|
{ |
|
84
|
6 |
|
return $this->body; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @inheritdoc |
|
89
|
|
|
*/ |
|
90
|
3 |
|
public function setBody($body) |
|
91
|
|
|
{ |
|
92
|
|
|
//to nothing |
|
93
|
3 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* adds a document to the body and transforms it in the right format. |
|
97
|
|
|
* |
|
98
|
|
|
* @param array $idList |
|
99
|
|
|
* @author Daniel Wendlandt |
|
100
|
|
|
*/ |
|
101
|
3 |
|
public function add(array $idList) |
|
102
|
|
|
{ |
|
103
|
3 |
|
foreach ($idList as $id) { |
|
104
|
|
|
$action = array( |
|
105
|
3 |
|
self::BULK_ACTION => array( |
|
106
|
3 |
|
'_id' => $id, |
|
107
|
3 |
|
'_index' => $this->index, |
|
108
|
3 |
|
'_type' => $this->type |
|
109
|
3 |
|
) |
|
110
|
3 |
|
); |
|
111
|
|
|
|
|
112
|
3 |
|
$this->body .= json_encode($action) . self::LINE_BREAK; |
|
113
|
3 |
|
} |
|
114
|
3 |
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|