This repository was archived by the owner on Nov 4, 2021. It is now read-only.
File tree 4 files changed +81
-1
lines changed
4 files changed +81
-1
lines changed Original file line number Diff line number Diff line change @@ -19,9 +19,19 @@ public function update(Collection $models)
19
19
$ model ->pushSoftDeleteMetadata ();
20
20
}
21
21
22
+ $ scoutMetaBody = [];
23
+ $ scoutMetaOther = [];
24
+ foreach ($ model ->scoutMetadata () as $ k => $ v ) {
25
+ if (is_string ($ k ) && substr ($ k , 0 , 1 ) === '_ ' ) {
26
+ $ scoutMetaOther [substr ($ k , 1 )] = $ v ;
27
+ } else {
28
+ $ scoutMetaBody [$ k ] = $ v ;
29
+ }
30
+ }
31
+
22
32
$ modelData = array_merge (
23
33
$ model ->toSearchableArray (),
24
- $ model -> scoutMetadata ()
34
+ $ scoutMetaBody
25
35
);
26
36
27
37
if (empty ($ modelData )) {
@@ -32,6 +42,9 @@ public function update(Collection $models)
32
42
33
43
$ payload = (new DocumentPayload ($ model ))
34
44
->set ('body ' , $ modelData );
45
+ foreach ($ scoutMetaOther as $ k => $ v ) {
46
+ $ payload ->set ($ k , $ v );
47
+ }
35
48
36
49
if (in_array (Migratable::class, class_uses_recursive ($ indexConfigurator ))) {
37
50
$ payload ->useAlias ('write ' );
Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ public function mockModel(array $params = [])
52
52
->method ('toSearchableArray ' )
53
53
->willReturn ($ params ['searchable_array ' ] ?? []);
54
54
55
+ $ mock
56
+ ->method ('scoutMetadata ' )
57
+ ->willReturn ($ params ['scoutMetadata ' ] ?? []);
58
+
55
59
$ mock
56
60
->method ('getIndexConfigurator ' )
57
61
->willReturn ($ params ['index_configurator ' ] ?? $ this ->mockIndexConfigurator ());
Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ protected function setUp()
37
37
'trashed ' => false ,
38
38
'searchable_array ' => [],
39
39
]),
40
+ $ this ->mockModel ([
41
+ 'key ' => 4 ,
42
+ 'trashed ' => false ,
43
+ 'scoutMetadata ' => [
44
+ 'name ' => 'bar ' ,
45
+ '_routing ' => 'woo ' ,
46
+ ],
47
+ ])
40
48
]);
41
49
}
42
50
}
Original file line number Diff line number Diff line change @@ -32,6 +32,17 @@ public function testUpdateWithDisabledSoftDelete()
32
32
'body ' => [
33
33
'name ' => 'bar ' ,
34
34
],
35
+ ])
36
+ ->shouldReceive ('index ' )
37
+ ->once ()
38
+ ->with ([
39
+ 'index ' => 'test ' ,
40
+ 'type ' => 'test ' ,
41
+ 'id ' => 4 ,
42
+ 'body ' => [
43
+ 'name ' => 'bar ' ,
44
+ ],
45
+ 'routing ' => 'woo ' ,
35
46
]);
36
47
37
48
(new SingleIndexer )
@@ -76,6 +87,18 @@ public function testUpdateWithEnabledSoftDelete()
76
87
'body ' => [
77
88
'__soft_deleted ' => 0 ,
78
89
],
90
+ ])
91
+ ->shouldReceive ('index ' )
92
+ ->once ()
93
+ ->with ([
94
+ 'index ' => 'test ' ,
95
+ 'type ' => 'test ' ,
96
+ 'id ' => 4 ,
97
+ 'body ' => [
98
+ 'name ' => 'bar ' ,
99
+ '__soft_deleted ' => 0 ,
100
+ ],
101
+ 'routing ' => 'woo ' ,
79
102
]);
80
103
81
104
(new SingleIndexer )
@@ -110,6 +133,17 @@ public function testUpdateWithSpecifiedDocumentRefreshOption()
110
133
'body ' => [
111
134
'name ' => 'bar ' ,
112
135
],
136
+ ])
137
+ ->shouldReceive ('index ' )
138
+ ->once ()
139
+ ->with ([
140
+ 'index ' => 'test ' ,
141
+ 'type ' => 'test ' ,
142
+ 'id ' => 4 ,
143
+ 'body ' => [
144
+ 'name ' => 'bar ' ,
145
+ ],
146
+ 'routing ' => 'woo ' ,
113
147
]);
114
148
115
149
(new SingleIndexer )
@@ -150,6 +184,16 @@ public function testDelete()
150
184
'client ' => [
151
185
'ignore ' => 404 ,
152
186
],
187
+ ])
188
+ ->shouldReceive ('delete ' )
189
+ ->once ()
190
+ ->with ([
191
+ 'index ' => 'test ' ,
192
+ 'type ' => 'test ' ,
193
+ 'id ' => 4 ,
194
+ 'client ' => [
195
+ 'ignore ' => 404 ,
196
+ ],
153
197
]);
154
198
155
199
(new SingleIndexer )
@@ -195,6 +239,17 @@ public function testDeleteWithSpecifiedDocumentRefreshOption()
195
239
'client ' => [
196
240
'ignore ' => 404 ,
197
241
],
242
+ ])
243
+ ->shouldReceive ('delete ' )
244
+ ->once ()
245
+ ->with ([
246
+ 'index ' => 'test ' ,
247
+ 'type ' => 'test ' ,
248
+ 'id ' => 2 ,
249
+ 'refresh ' => true ,
250
+ 'client ' => [
251
+ 'ignore ' => 404 ,
252
+ ],
198
253
]);
199
254
200
255
(new SingleIndexer ())
You can’t perform that action at this time.
0 commit comments