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 +81
-1
lines changed Expand file tree Collapse file tree 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)
1919 $ model ->pushSoftDeleteMetadata ();
2020 }
2121
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+
2232 $ modelData = array_merge (
2333 $ model ->toSearchableArray (),
24- $ model -> scoutMetadata ()
34+ $ scoutMetaBody
2535 );
2636
2737 if (empty ($ modelData )) {
@@ -32,6 +42,9 @@ public function update(Collection $models)
3242
3343 $ payload = (new DocumentPayload ($ model ))
3444 ->set ('body ' , $ modelData );
45+ foreach ($ scoutMetaOther as $ k => $ v ) {
46+ $ payload ->set ($ k , $ v );
47+ }
3548
3649 if (in_array (Migratable::class, class_uses_recursive ($ indexConfigurator ))) {
3750 $ payload ->useAlias ('write ' );
Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ public function mockModel(array $params = [])
5252 ->method ('toSearchableArray ' )
5353 ->willReturn ($ params ['searchable_array ' ] ?? []);
5454
55+ $ mock
56+ ->method ('scoutMetadata ' )
57+ ->willReturn ($ params ['scoutMetadata ' ] ?? []);
58+
5559 $ mock
5660 ->method ('getIndexConfigurator ' )
5761 ->willReturn ($ params ['index_configurator ' ] ?? $ this ->mockIndexConfigurator ());
Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ protected function setUp()
3737 'trashed ' => false ,
3838 'searchable_array ' => [],
3939 ]),
40+ $ this ->mockModel ([
41+ 'key ' => 4 ,
42+ 'trashed ' => false ,
43+ 'scoutMetadata ' => [
44+ 'name ' => 'bar ' ,
45+ '_routing ' => 'woo ' ,
46+ ],
47+ ]),
4048 ]);
4149 }
4250}
Original file line number Diff line number Diff line change @@ -32,6 +32,17 @@ public function testUpdateWithDisabledSoftDelete()
3232 'body ' => [
3333 'name ' => 'bar ' ,
3434 ],
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 ' ,
3546 ]);
3647
3748 (new SingleIndexer )
@@ -76,6 +87,18 @@ public function testUpdateWithEnabledSoftDelete()
7687 'body ' => [
7788 '__soft_deleted ' => 0 ,
7889 ],
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 ' ,
79102 ]);
80103
81104 (new SingleIndexer )
@@ -110,6 +133,17 @@ public function testUpdateWithSpecifiedDocumentRefreshOption()
110133 'body ' => [
111134 'name ' => 'bar ' ,
112135 ],
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 ' ,
113147 ]);
114148
115149 (new SingleIndexer )
@@ -150,6 +184,16 @@ public function testDelete()
150184 'client ' => [
151185 'ignore ' => 404 ,
152186 ],
187+ ])
188+ ->shouldReceive ('delete ' )
189+ ->once ()
190+ ->with ([
191+ 'index ' => 'test ' ,
192+ 'type ' => 'test ' ,
193+ 'id ' => 4 ,
194+ 'client ' => [
195+ 'ignore ' => 404 ,
196+ ],
153197 ]);
154198
155199 (new SingleIndexer )
@@ -195,6 +239,17 @@ public function testDeleteWithSpecifiedDocumentRefreshOption()
195239 'client ' => [
196240 'ignore ' => 404 ,
197241 ],
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+ ],
198253 ]);
199254
200255 (new SingleIndexer ())
You can’t perform that action at this time.
0 commit comments