-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathAboutController.php
More file actions
177 lines (152 loc) · 5.58 KB
/
Copy pathAboutController.php
File metadata and controls
177 lines (152 loc) · 5.58 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
namespace ProcessMaker\Http\Controllers;
use Exception;
use Illuminate\Foundation\PackageManifest;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use ProcessMaker\Facades\MessageBrokerService;
use ProcessMaker\Models\Setting;
use Throwable;
class AboutController extends Controller
{
/**
* Get the list of users.
*
* @return \Illuminate\View\View|\Illuminate\Contracts\View
*/
public function index()
{
$root = base_path('');
$vendor_path = base_path('vendor/processmaker');
// version from composer
$composer_json_path = json_decode(file_get_contents($root . '/composer.json'));
$versionTitle = $composer_json_path->extra->processmaker->release ?? '';
$versionNumber = $composer_json_path->version ?? '4.0.0';
$package_json_path = json_decode(file_get_contents($root . '/package.json'));
$dependencies = $package_json_path->dependencies;
$vendor_directories = \File::directories($vendor_path);
$string = '@processmaker';
$setting = Setting::byKey('indexed-search');
if ($setting && $setting->config['enabled'] === true) {
$indexedSearch = true;
} else {
$indexedSearch = false;
}
$packages = [];
foreach ($vendor_directories as $directory) {
$content = json_decode(file_get_contents($vendor_path . '/' . basename($directory) . '/composer.json'));
array_push($packages, $content);
}
foreach ($dependencies as $key => $value) {
if (strpos($key, $string) !== false) {
$value = str_replace('^', '', $value);
$content = new \stdClass();
$content->name = $key;
$content->version = $value;
array_push($packages, $content);
}
}
$commit_hash = false;
try {
if (is_string($composer_json_path->extra->processmaker->build)) {
$commit_hash = $composer_json_path->extra->processmaker->build;
}
} catch (Exception $exception) {
Log::warning('Commit hash missing from composer.json', [
'composer.json' => $composer_json_path,
]);
}
$microServices = [];
$aiMicroService = $this->getAiMicroService();
if ($aiMicroService) {
$microServices = [$aiMicroService];
}
$microServices[] = $this->getScriptMicroService();
$nayraMicroService = $this->getNayraMicroServiceAbout();
if ($nayraMicroService) {
$microServices[] = $nayraMicroService;
}
$installed = app(PackageManifest::class)->list();
$packages = array_filter($packages, function ($package) use ($installed) {
return in_array($package->name, $installed);
});
$view = request()->get('partial') === 'ms' ? 'about.microservices' : 'about.index';
return view($view,
compact(
'packages',
'indexedSearch',
'versionTitle',
'versionNumber',
'commit_hash',
'microServices'
)
);
}
private function getScriptMicroService()
{
$info = [
'name' => 'Script Microservice',
'description' => 'Execute scripts in ProcessMaker',
'status' => 'Disabled',
];
if (config('script-runner-microservice.enabled')) {
$baseUrl = config('script-runner-microservice.base_url');
try {
$response = Http::timeout(3)
->get($baseUrl . '/accept-traffic')
->throw();
$info['status'] = $response->json()['message'] . ". Microservice is running at $baseUrl";
} catch (Exception $e) {
$info['status'] = "Error connecting to $baseUrl: " . $e->getMessage();
}
}
return $info;
}
private function getAiMicroService()
{
if (hasPackage('package-ai')) {
$url = config('app.ai_microservice_host') . '/pm/getVersion';
try {
$response = Http::post($url, []);
} catch (Throwable $th) {
return [
'name' => 'Pmai microservice',
'waiting' => true,
];
}
return $response->json();
}
return null;
}
/**
* Get the Nayra microservice about information from cache or send about message to receive it.
*
* @return array|null
*/
private function getNayraMicroServiceAbout(): ?array
{
if (config('app.message_broker_driver') !== 'default') {
$about = Cache::get('nayra.about', null);
if (!$about) {
// Send about message to receive about information from nayra service
try {
MessageBrokerService::sendAboutMessage();
} catch (Throwable $e) {
return [
'name' => 'processmaker/nayra-service',
'description' => __('Nayra microservice is not available at this moment.'),
'waiting' => true,
];
}
$about = [
'name' => 'processmaker/nayra-service',
'waiting' => true,
];
}
return $about;
}
return null;
}
}