|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gameap\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Gameap\Repositories\NodeRepository; |
|
6
|
|
|
use Knik\Gameap\GdaemonStatus; |
|
7
|
|
|
|
|
8
|
|
|
class ProblemFinderService |
|
9
|
|
|
{ |
|
10
|
|
|
private const REQUIRED_EXTENSIONS = [ |
|
11
|
|
|
'bz2', |
|
12
|
|
|
'curl', |
|
13
|
|
|
'gd', |
|
14
|
|
|
'gmp', |
|
15
|
|
|
'intl', |
|
16
|
|
|
'json', |
|
17
|
|
|
'mbstring', |
|
18
|
|
|
'openssl', |
|
19
|
|
|
'xml', |
|
20
|
|
|
'zip', |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
/** @var array */ |
|
24
|
|
|
private $writableStorageDirectories = []; |
|
25
|
|
|
|
|
26
|
|
|
/** @var GdaemonStatus */ |
|
27
|
|
|
private $gdaemonStatus; |
|
28
|
|
|
|
|
29
|
|
|
/** @var NodeRepository */ |
|
30
|
|
|
private $nodeRepository; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(GdaemonStatus $gdaemonStatus, NodeRepository $nodeRepository) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->gdaemonStatus = $gdaemonStatus; |
|
35
|
|
|
$this->nodeRepository = $nodeRepository; |
|
36
|
|
|
|
|
37
|
|
|
$this->writableStorageDirectories = [ |
|
38
|
|
|
storage_path('app'), |
|
39
|
|
|
storage_path('app/certs'), |
|
40
|
|
|
storage_path('app/certs/client'), |
|
41
|
|
|
storage_path('app/public'), |
|
42
|
|
|
storage_path('framework'), |
|
43
|
|
|
storage_path('framework/cache'), |
|
44
|
|
|
storage_path('framework/sessions'), |
|
45
|
|
|
storage_path('framework/views'), |
|
46
|
|
|
storage_path('logs'), |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function find(): array |
|
51
|
|
|
{ |
|
52
|
|
|
$problems = []; |
|
53
|
|
|
$missedExtensions = $this->findMissedExtensions(); |
|
54
|
|
|
if (!empty($missedExtensions)) { |
|
55
|
|
|
$problems[] = __('home.problems_list.required_extenstions_are_missed', [ |
|
56
|
|
|
'extensions' => implode(', ', $missedExtensions), |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$inconnectableNodes = $this->findInconnectableNodes(); |
|
61
|
|
|
if (!empty($inconnectableNodes)) { |
|
62
|
|
|
$problems[] = __('home.problems_list.nodes_is_not_available', [ |
|
63
|
|
|
'nodes' => implode(', ', $inconnectableNodes), |
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$writeless = $this->findInsufficientFilePermissions(); |
|
68
|
|
|
if (!empty($writeless)) { |
|
69
|
|
|
$problems[] = __('home.problems_list.not_writable_directories', [ |
|
70
|
|
|
'paths' => implode(', ', $writeless), |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $problems; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
private function findMissedExtensions(): array |
|
78
|
|
|
{ |
|
79
|
|
|
$extensions = array_map(function(string $value): string { |
|
80
|
|
|
return strtolower($value); |
|
81
|
|
|
}, get_loaded_extensions()); |
|
82
|
|
|
|
|
83
|
|
|
return array_diff(self::REQUIRED_EXTENSIONS, $extensions); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private function findInconnectableNodes(): array |
|
87
|
|
|
{ |
|
88
|
|
|
$problemNodeNames = []; |
|
89
|
|
|
$nodes = $this->nodeRepository->find(); |
|
90
|
|
|
|
|
91
|
|
|
foreach ($nodes as $node) { |
|
92
|
|
|
$this->gdaemonStatus->setConfig($node->gdaemonSettings()); |
|
93
|
|
|
|
|
94
|
|
|
try { |
|
95
|
|
|
$this->gdaemonStatus->connect(); |
|
96
|
|
|
} catch (\RuntimeException $exception) { |
|
97
|
|
|
$problemNodeNames[] = $node->name . "(id={$node->id})"; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->gdaemonStatus->disconnect(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $problemNodeNames; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
private function findInsufficientFilePermissions(): array |
|
107
|
|
|
{ |
|
108
|
|
|
$problemDirectories = []; |
|
109
|
|
|
|
|
110
|
|
|
foreach ($this->writableStorageDirectories as $directory) { |
|
111
|
|
|
if (!is_writable($directory)) { |
|
112
|
|
|
$problemDirectories[] = $directory; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $problemDirectories; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|