Completed
Push — master ( b12ce1...ca7f0c )
by Mehmet
02:06
created

doc_delete.php ➔ es_doc_delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
cc 2
eloc 9
c 5
b 1
f 0
nc 2
nop 2
dl 0
loc 17
rs 9.4285
1
<?php
2
3
function es_doc_delete($request, $args)
4
{
5
    global $ESConn;
6
    try {
7
        $result = $ESConn->delete($args);
8
    } catch (Exception $e) {
9
        /*
10
        If you try to delete a document with an _id that does not exist, $ES->delete throws an Exception.
11
        B/c of default behaviour of reformo/rslim, it bypasses all Exceptions and it returns Exception message.
12
        In this case it returns this message as a plain text json that elasticsearch-php returns.
13
        */
14
        $result = json_decode($e->getMessage(), true);
15
    }
16
    $found = (int) $result['found'];
17
    sleep(1);
18
    return ['redirect'=>BASE_HREF . '/' . $args['index'] . '/' . $args['type'] . '?res=success&req=delete&f=' . $found];
19
}
20