This repository was archived by the owner on Nov 4, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +43
-23
lines changed Expand file tree Collapse file tree 4 files changed +43
-23
lines changed Original file line number Diff line number Diff line change 8
8
use ScoutElastic \Console \Features \requiresIndexConfiguratorArgument ;
9
9
use ScoutElastic \Facades \ElasticClient ;
10
10
use ScoutElastic \Payloads \IndexPayload ;
11
+ use ScoutElastic \Payloads \RawPayload ;
11
12
12
13
class ElasticIndexUpdateCommand extends Command
13
14
{
@@ -75,15 +76,19 @@ protected function createWriteAlias()
75
76
76
77
$ indices = ElasticClient::indices ();
77
78
78
- if ($ indices ->existsAlias (['name ' => $ configurator ->getWriteAlias ()])) {
79
+ $ existsPayload = (new RawPayload ())
80
+ ->set ('name ' , $ configurator ->getWriteAlias ())
81
+ ->get ();
82
+
83
+ if ($ indices ->existsAlias ($ existsPayload )) {
79
84
return ;
80
85
}
81
86
82
- $ payload = (new IndexPayload ($ configurator ))
87
+ $ putPayload = (new IndexPayload ($ configurator ))
83
88
->set ('name ' , $ configurator ->getWriteAlias ())
84
89
->get ();
85
90
86
- $ indices ->putAlias ($ payload );
91
+ $ indices ->putAlias ($ putPayload );
87
92
88
93
$ this ->info (sprintf (
89
94
'The %s alias for the %s index was created! ' ,
Original file line number Diff line number Diff line change 5
5
use Exception ;
6
6
use ScoutElastic \IndexConfigurator ;
7
7
8
- class IndexPayload
8
+ class IndexPayload extends RawPayload
9
9
{
10
- protected $ payload = [];
11
-
12
10
protected $ protectedKeys = [
13
11
'index '
14
12
];
@@ -41,24 +39,10 @@ public function useAlias($alias)
41
39
42
40
public function set ($ key , $ value )
43
41
{
44
- if (!is_null ($ key ) && !in_array ($ key , $ this ->protectedKeys )) {
45
- array_set ($ this ->payload , $ key , $ value );
46
- }
47
-
48
- return $ this ;
49
- }
50
-
51
- public function setIfNotEmpty ($ key , $ value )
52
- {
53
- if (empty ($ value )) {
42
+ if (in_array ($ key , $ this ->protectedKeys )) {
54
43
return $ this ;
55
44
}
56
45
57
- return $ this ->set ($ key , $ value );
58
- }
59
-
60
- public function get ($ key = null )
61
- {
62
- return array_get ($ this ->payload , $ key );
46
+ return parent ::set ($ key , $ value );
63
47
}
64
48
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace ScoutElastic \Payloads ;
4
+
5
+ class RawPayload
6
+ {
7
+ protected $ payload = [];
8
+
9
+ public function set ($ key , $ value )
10
+ {
11
+ if (!is_null ($ key )) {
12
+ array_set ($ this ->payload , $ key , $ value );
13
+ }
14
+
15
+ return $ this ;
16
+ }
17
+
18
+ public function setIfNotEmpty ($ key , $ value )
19
+ {
20
+ if (empty ($ value )) {
21
+ return $ this ;
22
+ }
23
+
24
+ return $ this ->set ($ key , $ value );
25
+ }
26
+
27
+ public function get ($ key = null )
28
+ {
29
+ return array_get ($ this ->payload , $ key );
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ public function test_if_the_update_method_builds_correct_payload()
24
24
$ this ->mockClient ()
25
25
->shouldReceive ('index ' )
26
26
->with ([
27
- 'index ' => 'test_index ' ,
27
+ 'index ' => 'test_index_write ' ,
28
28
'type ' => 'test_table ' ,
29
29
'id ' => 1 ,
30
30
'body ' => [
You can’t perform that action at this time.
0 commit comments