Completed
Push — master ( 4d411b...368a33 )
by Mehmet
02:00
created

doc_delete.php ➔ es_doc_delete()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 17
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 26
rs 8.8571
1
<?php
2
3
function es_doc_delete($request, $args) {
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4
5
    global $ES;
6
7
    $index  = $args['index'];
8
    $type   = $args['type'];
9
    $id     = $args['id'];
10
    $params = [];
11
    $params['index'] = $index;
12
    $params['type'] = $type;
13
    $params['id'] = $id;
14
    try {
15
        $result = $ES->delete($params);
16
    } catch (Exception $e) {
17
        /*
18
        If you try to delete a document with an _id that does not exist, $ES->delete throws an Exception.
19
        B/c of default behaviour of reformo/rslim, it bypasses all Exceptions and it returns Exception message.
20
        In this case it returns this message as a plain text json that elasticsearch-php returns.
21
        */
22
        $result = json_decode($e->getMessage(), true);
23
    }
24
    $found = ($result['found'] === true) ? 1 : 0;
25
    sleep(1);
26
    header("location:" . BASE_HREF . "/" . $index . "/" . $type . "?res=success&req=delete&f=".$found);
27
    exit;
28
}