@@ -213,30 +213,39 @@ public function processToDslForSearch($searchParams, $searchOptions, $wheres, $o
213213 /**
214214 * @throws QueryException
215215 */
216- public function processGetId ($ id , $ columns)
216+ public function processGetId ($ id , $ columns, $ softDeleteColumn ): Results
217217 {
218218 $ params = [
219219 'index ' => $ this ->index ,
220220 'id ' => $ id ,
221221 ];
222- if ($ columns && $ columns != ' * ' ) {
223- $ params [ ' _source ' ] = $ columns ;
222+ if (empty ( $ columns) ) {
223+ $ columns = [ ' * ' ] ;
224224 }
225+ if (! is_array ($ columns )) {
226+ $ columns = [$ columns ];
227+ }
228+ $ allColumns = $ columns [0 ] == '* ' ;
229+
230+ if ($ softDeleteColumn && ! $ allColumns && ! in_array ($ softDeleteColumn , $ columns )) {
231+ $ columns [] = $ softDeleteColumn ;
232+ }
233+ $ params ['_source ' ] = $ columns ;
225234 $ process = [];
226235 try {
227236 $ process = $ this ->client ->get ($ params );
228237 } catch (ClientResponseException $ e ) {
229238 //if the error is a 404 continue, else throw it
230239 if ($ e ->getCode () !== 404 ) {
231- return $ this ->_throwError ($ e , $ params , $ this ->_queryTag (__FUNCTION__ ));
240+ $ this ->_throwError ($ e , $ params , $ this ->_queryTag (__FUNCTION__ ));
232241 }
233242
234243 } catch (Exception $ e ) {
235244 //Something else went wrong, throw it
236- return $ this ->_throwError ($ e , $ params , $ this ->_queryTag (__FUNCTION__ ));
245+ $ this ->_throwError ($ e , $ params , $ this ->_queryTag (__FUNCTION__ ));
237246 }
238247
239- return $ this ->_sanitizeGetResponse ($ process , $ params , $ this ->_queryTag (__FUNCTION__ ));
248+ return $ this ->_sanitizeGetResponse ($ process , $ params , $ softDeleteColumn , $ this ->_queryTag (__FUNCTION__ ));
240249 }
241250
242251 /**
@@ -1126,21 +1135,30 @@ private function _queryTag($function): string
11261135 return str_replace ('process ' , '' , $ function );
11271136 }
11281137
1129- public function _sanitizeGetResponse ($ response , $ params , $ queryTag )
1138+ public function _sanitizeGetResponse ($ response , $ params , $ softDeleteColumn , $ queryTag )
11301139 {
11311140 $ data ['_id ' ] = $ params ['id ' ];
1132- if (! $ response ) {
1141+ $ softDeleted = false ;
1142+ if ($ softDeleteColumn ) {
1143+ $ softDeleted = ! empty ($ response ['_source ' ][$ softDeleteColumn ]);
1144+ }
1145+
1146+ if (! $ response || $ softDeleted ) {
11331147 //Was not found
11341148 $ result = $ this ->_return ($ data , [], $ params , $ queryTag );
11351149 $ result ->setError ($ data ['_id ' ].' not found ' , 404 );
11361150
11371151 return $ result ;
11381152 }
1153+
11391154 if (! empty ($ response ['_source ' ])) {
11401155 foreach ($ response ['_source ' ] as $ key => $ value ) {
11411156 $ data [$ key ] = $ value ;
11421157 }
11431158 }
1159+ if ($ softDeleteColumn ) {
1160+ unset($ data [$ softDeleteColumn ]);
1161+ }
11441162
11451163 return $ this ->_return ($ data , [], $ params , $ queryTag );
11461164 }
0 commit comments