Completed
Push — add-pleio-mod ( 6d68a5 )
by
unknown
28:07
created

background_tasks.php ➔ import_send_error()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 12
cp 0
crap 6
1
<?php
2
function import_process($input) {
3
    global $CONFIG, $site, $initiator;
4
5
    $site = elgg_get_site_entity();
6
7
    $initiator = get_entity($input["initiator_guid"]);
8
    if (!$initiator) {
9
        throw new Exception("Could not find initiator user");
10
    }
11
    set_exception_handler("import_exceptionhandler");
12
    register_shutdown_function("import_check_for_fatal");
13
14
    $ia = elgg_set_ignore_access(true);
15
    $stats = ModPleio\Import::run($input["csv_location"], $input["columns"], $initiator);
0 ignored issues
show
Compatibility introduced by
$initiator of type object<ElggEntity> is not a sub-type of object<ElggUser>. It seems like you assume a child class of the class ElggEntity to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
16
    elgg_set_ignore_access($ia);
17
18
    $from = $site->email ?: "noreply@" . get_site_domain($CONFIG->site_guid);
19
    elgg_send_email(
20
        $from,
21
        $initiator->email,
22
        elgg_echo("pleio:users_import:email:success:subject"),
23
        elgg_echo("pleio:users_import:email:success:body", [
24
            $initiator->name,
25
            $stats["created"],
26
            $stats["updated"],
27
            $stats["error"]
28
        ])
29
    );
30
}
31
32
function import_exceptionhandler($exception) {
33
    import_send_error($exception->getMessage());
34
}
35
36
function import_check_for_fatal() {
37
    $error = error_get_last();
38
    if ($error["type"] !== E_ERROR) {
39
        return;
40
    }
41
42
    import_send_error($error["message"]);
43
}
44
45
function import_send_error($message) {
46
    global $CONFIG, $site, $initiator;
47
48
    $from = $site->email ?: "noreply@" . get_site_domain($CONFIG->site_guid);
49
    elgg_send_email(
50
        $from,
51
        $initiator->email,
52
        elgg_echo("pleio:users_import:email:failed:subject"),
53
        elgg_echo("pleio:users_import:email:failed:body", [
54
            $initiator->name,
55
            $message
56
        ])
57
    );
58
}
59