-
Notifications
You must be signed in to change notification settings - Fork 1
/
queueit.install
76 lines (70 loc) · 2.61 KB
/
queueit.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* @file
* Module's installation file.
*/
/**
* Implements hook_requirements().
*/
function queueit_requirements($phase) {
$requirements = array();
// Load integration method either from POST or variable.
// Reading from POST is used during form validation.
// @see: queueit_settings_form_validate().
$int_method = filter_input(INPUT_POST, 'queueit_mode') ?:
variable_get('queueit_mode', 'integration');
$customer_id = filter_input(INPUT_POST, 'queueit_customer_id') ?:
variable_get('queueit_customer_id');
$api_key = filter_input(INPUT_POST, 'queueit_api_key') ?:
variable_get('queueit_api_key');
$secret_key = filter_input(INPUT_POST, 'queueit_secret_key') ?:
variable_get('queueit_secret_key');
if ($phase == 'runtime') {
$t = get_t();
$description = '';
$severity = REQUIREMENT_OK;
$value = '';
switch ($int_method) {
case 'js':
$known_user = new QueueitBase();
$js_exists = $known_user->validateJsEndpoints();
$severity = $js_exists
? REQUIREMENT_OK
: REQUIREMENT_ERROR;
$value = $js_exists
? $t("JavaScript integration: JS files validated.")
: $t("Problem accessing external JS files.");
break;
case 'code':
case 'integration':
$known_user_lib = drupal_get_library('queueit', 'queueit/KnownUser');
$known_user_exists = file_exists(libraries_get_path('composer') . '/queueit/knownuserv3' . '/KnownUser.php');
$exists = $known_user_lib && $known_user_exists;
$severity = $exists ? REQUIREMENT_OK : REQUIREMENT_ERROR;
$value = $t('Backend integration. %lib library %state.',
[
'%lib' => 'KnownUser.V3.PHP',
'%state' => $exists ? 'installed' : 'not installed',
]);
module_load_include('php', 'queueit', 'src/classes/QueueitBase');
if ($exists && class_exists('QueueitBase') && !((new QueueitBase)->validateConfig())) {
$value .= ' ' . $t("But not configured correctly. Check the configuration page.");
$severity = REQUIREMENT_WARNING;
}
else {
$queueit = new QueueitKnownUser($int_method, $customer_id, $secret_key, $api_key);
$config = $queueit->getIntegrationConfig();
$severity = $config ? REQUIREMENT_OK : REQUIREMENT_WARNING;
$description = json_encode(json_decode($config), TRUE);
}
break;
}
$requirements['queueit'] = array(
'title' => $t('Queue-it'),
'description' => $description,
'severity' => $severity,
'value' => $value,
);
}
return $requirements;
}