doc_delete.php ➔ es_doc_delete()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 2
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
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