|
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); |
|
|
|
|
|
|
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
|
|
|
|
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.