1
|
|
|
<?php |
2
|
|
|
require_once __DIR__ . '/vendor/autoload.php'; |
3
|
|
|
use EUAutomation\GraphQL\Client; |
4
|
|
|
|
5
|
|
|
elgg_register_event_handler('init', 'system', 'paas_integration_init'); |
6
|
|
|
|
7
|
|
|
function paas_integration_init() { |
8
|
|
|
|
9
|
|
|
elgg_register_action("avatar/upload", elgg_get_plugins_path() . "paas_integration/actions/avatar/upload.php"); |
10
|
|
|
elgg_register_plugin_hook_handler("action", "b_extended_profile/edit_profile", "edit_profile_paas_mutation"); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Send modifyProfile mutation to PaaS |
15
|
|
|
* |
16
|
|
|
* @return bool |
17
|
|
|
*/ |
18
|
|
|
function edit_profile_paas_mutation($hook, $entity_type, $returnvalue, $params) { |
19
|
|
|
$guid = get_input('guid'); |
20
|
|
|
$owner = get_entity($guid); |
21
|
|
|
|
22
|
|
|
$dbprefix = elgg_get_config("dbprefix"); |
23
|
|
|
$service_url = elgg_get_plugin_setting("graphql_client", "paas_integration"); |
24
|
|
|
$dev_url = elgg_get_plugin_setting("dev_url", "paas_integration"); |
25
|
|
|
|
26
|
|
|
$session = elgg_get_session(); |
27
|
|
|
$token = $session->get('token'); |
28
|
|
|
|
29
|
|
|
$result = get_data_row("SELECT pleio_guid FROM {$dbprefix}users_entity WHERE guid = $guid"); |
30
|
|
|
if ($result->pleio_guid) { |
31
|
|
|
$gcID = $result->pleio_guid; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if($dev_url){ |
35
|
|
|
$site_url = $dev_url; |
36
|
|
|
} else { |
37
|
|
|
$site_url = elgg_get_site_url(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$client = new Client($service_url); |
41
|
|
|
|
42
|
|
|
$headers = [ |
43
|
|
|
"Authorization" => "Bearer $token" |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$query = 'mutation ($gcID: ID!, $data: ModifyProfileInput!) { |
47
|
|
|
modifyProfile(gcID: $gcID, data: $data) { |
48
|
|
|
gcID |
49
|
|
|
name |
50
|
|
|
email |
51
|
|
|
titleEn |
52
|
|
|
titleFr |
53
|
|
|
avatar |
54
|
|
|
mobilePhone |
55
|
|
|
officePhone |
56
|
|
|
address { |
57
|
|
|
streetAddress |
58
|
|
|
city |
59
|
|
|
postalCode |
60
|
|
|
province |
61
|
|
|
country |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
}'; |
65
|
|
|
|
66
|
|
|
$profile_fields = get_input('profile'); |
67
|
|
|
|
68
|
|
|
$variables = array( |
69
|
|
|
'gcID' => $gcID, |
|
|
|
|
70
|
|
|
'data' => array( |
71
|
|
|
'name' => $profile_fields['name'], |
72
|
|
|
'titleEn' => copy_value_to_object_if_defined('job', $profile_fields['job']), |
73
|
|
|
'titleFr' => copy_value_to_object_if_defined('jobfr', $profile_fields['jobfr']), |
74
|
|
|
'mobilePhone' => copy_value_to_object_if_defined('mobile', $profile_fields['mobile']), |
75
|
|
|
'officePhone' => copy_value_to_object_if_defined('phone', $profile_fields['phone']), |
76
|
|
|
'address' => array( |
77
|
|
|
'streetAddress' => $profile_fields['streetaddress'], |
78
|
|
|
'city' => $profile_fields['city'], |
79
|
|
|
'province' => $profile_fields['province'], |
80
|
|
|
'postalCode' => $profile_fields['postalcode'], |
81
|
|
|
'country' => $profile_fields['country'], |
82
|
|
|
) |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
// Send data to PaaS |
87
|
|
|
$response = $client->response($query, $variables, $headers); |
88
|
|
|
|
89
|
|
|
// Error check |
90
|
|
|
if($response->errors()){ |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// Mutation has gone through |
95
|
|
|
return true; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
function copy_value_to_object_if_defined($field, $value){ |
99
|
|
|
if($value != null && $value != "undefined"){ |
100
|
|
|
return $value; |
101
|
|
|
} else { |
102
|
|
|
return null; |
103
|
|
|
} |
104
|
|
|
} |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: