Repository navigation
Expand file tree
/
Copy pathAboutController.php
More file actions
127 lines (109 loc) · 3.9 KB
/
Copy pathAboutController.php
File metadata and controls
127 lines (109 loc) · 3.9 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
<?php
namespace ProcessMaker\Http\Controllers;
use Exception;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use ProcessMaker\Facades\MessageBrokerService;
use ProcessMaker\Models\Setting;
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];
}
$nayraMicroService = $this->getNayraMicroServiceAbout();
if ($nayraMicroService) {
$microServices[] = $nayraMicroService;
}
$view = request()->get('partial') === 'ms' ? 'about.microservices' : 'about.index';
return view($view,
compact(
'packages',
'indexedSearch',
'versionTitle',
'versionNumber',
'commit_hash',
'microServices'
)
);
}
private function getAiMicroService()
{
if (hasPackage('package-ai')) {
$url = config('app.ai_microservice_host') . '/pm/getVersion';
$response = Http::post($url, []);
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
MessageBrokerService::sendAboutMessage();
$about = [
'name' => 'processmaker/nayra-service',
'waiting' => true,
];
}
return $about;
}
return null;
}
}