-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsm_appdashboard_apigee.install
90 lines (77 loc) · 3.29 KB
/
sm_appdashboard_apigee.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @file
* Copyright (C) 2020 Stratus Meridian LLC.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* @file
* Contains sm_appdashboard_apigee.install.
*/
use Drupal\Core\Link;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Implements hook_requirements().
*/
function sm_appdashboard_apigee_requirements($phase) {
$requirements = [];
if ($phase === 'install' || $phase === 'runtime') {
/* @var \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector */
$sdk_connector = \Drupal::service('apigee_edge.sdk_connector');
try {
$sdk_connector->testConnection();
}
catch (\Exception $exception) {
$requirements['apigee_edge_connection_error'] = [
'title' => t('Apigee Edge'),
'value' => $exception->getMessage(),
'description' => t('Cannot connect to Apigee Edge server. You have either given wrong credential details or the Apigee Edge server is unreachable. Visit the <a href=":url">Apigee Edge general settings</a> page to get more information.', [
':url' => Url::fromRoute('apigee_edge.settings', ['destination' => 'admin/reports/status'])->toString(),
]),
'severity' => REQUIREMENT_WARNING,
];
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
function sm_appdashboard_apigee_install() {
/* @var \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector */
$sdk_connector = \Drupal::service('apigee_edge.sdk_connector');
$sdk_connector->testConnection();
try {
$path = Url::fromRoute('apps_dashboard.list', [])->toString();
$sync_path = Url::fromRoute('apigee_edge.settings.developer.sync', []);
$sync_text = t('Apigee Edge Developer Sync');
$sync_link = Link::fromTextAndUrl($sync_text, $sync_path)->toString();
\Drupal::messenger()->addWarning(\Drupal::translation()->translate("You need to run the Developer Sync from the Apigee Edge developer settings page. To do this, please click: @link!", ['@link!' => $sync_link]));
$response = new RedirectResponse($path);
$response->send();
}
catch (\Exception $exception) {
$requirements['apigee_edge_connection_error'] = [
'title' => t('Apigee Edge'),
'value' => $exception->getMessage(),
'description' => t('Cannot connect to Apigee Edge server. You have either given wrong credential details or the Apigee Edge server is unreachable. Visit the <a href=":url">Apigee Edge general settings</a> page to get more information.', [
':url' => Url::fromRoute('apigee_edge.settings', ['destination' => 'admin/reports/status'])->toString(),
]),
'severity' => REQUIREMENT_WARNING,
];
}
}