| Conditions | 2 |
| Paths | 2 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 3 | function es_doc_delete($request, $args) |
||
| 4 | { |
||
| 5 | global $esConn; |
||
| 6 | $params = [ |
||
| 7 | 'index'=>$args['index'], |
||
| 8 | 'type'=>$args['type'], |
||
| 9 | 'id'=>$args['id'], |
||
| 10 | ]; |
||
| 11 | try { |
||
| 12 | $result = $esConn->delete($params); |
||
| 13 | } catch (Exception $e) { |
||
| 14 | /* |
||
| 15 | If you try to delete a document with an _id that does not exist, $ES->delete throws an Exception. |
||
| 16 | B/c of default behaviour of reformo/rslim, it bypasses all Exceptions and it returns Exception message. |
||
| 17 | In this case it returns this message as a plain text json that elasticsearch-php returns. |
||
| 18 | */ |
||
| 19 | $result = json_decode($e->getMessage(), true); |
||
| 20 | } |
||
| 21 | $found = (int) $result['found']; |
||
| 22 | sleep(1); |
||
| 23 | return ['redirect'=>BASE_HREF . '/' . $args['index'] . '/' . $args['type'] |
||
| 24 | . '?res=success&req=delete&f=' . $found . "&" . http_build_query($request->getParams())]; |
||
| 25 | } |
||
| 26 |