|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Install file for the MongoDB module. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
use Drupal\Core\Site\Settings; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Requirements check: MongoDB extension. |
|
12
|
|
|
* |
|
13
|
|
|
* @param array $ret |
|
14
|
|
|
* The running requirements array |
|
|
|
|
|
|
15
|
|
|
* @param $extension_name |
|
|
|
|
|
|
16
|
|
|
* The name of the extension to check. |
|
17
|
|
|
* |
|
18
|
|
|
* @return bool |
|
19
|
|
|
* Did requirements check succeed ? |
|
20
|
|
|
*/ |
|
21
|
|
|
function _mongodb_requirements_extension(array &$ret, $extension_name) { |
|
22
|
|
|
$success = extension_loaded($extension_name); |
|
23
|
|
View Code Duplication |
if (!$success) { |
|
|
|
|
|
|
24
|
|
|
$ret['mongodb'] += array( |
|
25
|
|
|
'value' => t('Extension not loaded'), |
|
26
|
|
|
'description' => t('Mongodb requires the non-legacy PHP MongoDB extension (@name) to be installed.', [ |
|
27
|
|
|
'@name' => $extension_name, |
|
28
|
|
|
]), |
|
29
|
|
|
'severity' => REQUIREMENT_ERROR, |
|
30
|
|
|
); |
|
31
|
|
|
} |
|
32
|
|
|
return $success; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Requirements check: extension version. |
|
37
|
|
|
* |
|
38
|
|
|
* @param array $ret |
|
39
|
|
|
* The running requirements array. |
|
40
|
|
|
* @param $description |
|
|
|
|
|
|
41
|
|
|
* The running description array. |
|
42
|
|
|
* @param $extension_name |
|
|
|
|
|
|
43
|
|
|
* The name of the extension to check. |
|
44
|
|
|
* |
|
45
|
|
|
* @return bool |
|
46
|
|
|
* Did requirements check succeed ? |
|
47
|
|
|
*/ |
|
48
|
|
|
function _mongodb_requirements_extension_version(array &$ret, array &$description, $extension_name) { |
|
49
|
|
|
$minimum_version = '1.1.7'; |
|
50
|
|
|
$extension_version = phpversion($extension_name); |
|
51
|
|
|
$version_status = version_compare($extension_version, $minimum_version); |
|
52
|
|
|
$success = $version_status >= 0; |
|
53
|
|
|
if ($success) { |
|
54
|
|
|
$description[] = t('Extension version @version found.', ['@version' => $extension_version]); |
|
55
|
|
|
} |
|
56
|
|
View Code Duplication |
else { |
|
|
|
|
|
|
57
|
|
|
$ret['mongodb'] += [ |
|
58
|
|
|
'severity' => REQUIREMENT_ERROR, |
|
59
|
|
|
'description' => t('Module needs extension @name @minimum_version or later, found @version.', [ |
|
60
|
|
|
'@name' => $extension_name, |
|
61
|
|
|
'@minimum_version' => $minimum_version, |
|
62
|
|
|
'@version' => $extension_version, |
|
63
|
|
|
]), |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $success; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Requirements check: existence of the client aliases. |
|
72
|
|
|
* |
|
73
|
|
|
* @param array $ret |
|
74
|
|
|
* The running requirements array. |
|
75
|
|
|
* @param $description |
|
|
|
|
|
|
76
|
|
|
* The running description array. |
|
77
|
|
|
* @param array $databases |
|
78
|
|
|
* The databases array, sanitized from settings. |
|
79
|
|
|
* |
|
80
|
|
|
* @return bool |
|
81
|
|
|
* Did requirements check succeed ? |
|
82
|
|
|
*/ |
|
83
|
|
|
function _mongodb_requirements_aliases(array &$ret, array &$description, array $databases) { |
|
84
|
|
|
$success = !empty($databases); |
|
85
|
|
|
if (!$success) { |
|
86
|
|
|
$ret['mongodb'] += [ |
|
87
|
|
|
'severity' => REQUIREMENT_WARNING, |
|
88
|
|
|
'value' => t('No database aliases found in settings. Did you actually configure your settings ?'), |
|
89
|
|
|
'description' => [ |
|
90
|
|
|
'#theme' => 'item_list', |
|
91
|
|
|
'#items' => $description, |
|
92
|
|
|
], |
|
93
|
|
|
]; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $success; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Requirements check: database vs clients consistency. |
|
101
|
|
|
* |
|
102
|
|
|
* @param array $settings |
|
103
|
|
|
* The mongodb settings. |
|
104
|
|
|
* @param array $databases |
|
105
|
|
|
* The databases, sanitized from settings. |
|
106
|
|
|
* @param array $description |
|
107
|
|
|
* The running description array. |
|
108
|
|
|
* |
|
109
|
|
|
* @return bool |
|
110
|
|
|
* Did requirements check succeed ? |
|
111
|
|
|
*/ |
|
112
|
|
|
function _mongodb_requirements_databases($settings, $databases, &$description) { |
|
|
|
|
|
|
113
|
|
|
$client_aliases = isset($settings['clients']) ? $settings['clients'] : []; |
|
114
|
|
|
$warnings = []; |
|
115
|
|
|
$success = TRUE; |
|
116
|
|
|
foreach ($databases as $database => list($client, $name)) { |
|
|
|
|
|
|
117
|
|
|
if (empty($client_aliases[$client])) { |
|
|
|
|
|
|
118
|
|
|
$success = FALSE; |
|
119
|
|
|
$warnings[] = t('Database "@db" references undefined client "@client".', [ |
|
120
|
|
|
'@db' => $database, |
|
121
|
|
|
'@client' => $client, |
|
|
|
|
|
|
122
|
|
|
]); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if ($success) { |
|
127
|
|
|
$warnings = [t('Databases and clients are consistent.')]; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$description = [ |
|
131
|
|
|
'#theme' => 'item_list', |
|
132
|
|
|
'#items' => array_merge($description, $warnings), |
|
133
|
|
|
]; |
|
134
|
|
|
|
|
135
|
|
|
return $success; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Implements hook_requirements(). |
|
140
|
|
|
*/ |
|
141
|
|
|
function mongodb_requirements() { |
|
142
|
|
|
$extension_name = 'mongodb'; |
|
143
|
|
|
|
|
144
|
|
|
$ret = []; |
|
145
|
|
|
$ret['mongodb'] = [ |
|
146
|
|
|
'title' => t('Mongodb'), |
|
147
|
|
|
'severity' => REQUIREMENT_OK, |
|
148
|
|
|
]; |
|
149
|
|
|
$description = []; |
|
150
|
|
|
|
|
151
|
|
|
if (!_mongodb_requirements_extension($ret, $extension_name)) { |
|
152
|
|
|
return $ret; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
if (!_mongodb_requirements_extension_version($ret, $description, $extension_name)) { |
|
156
|
|
|
return $ret; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$settings = Settings::get('mongodb'); |
|
160
|
|
|
$databases = isset($settings['databases']) ? $settings['databases'] : []; |
|
161
|
|
|
|
|
162
|
|
|
if (!_mongodb_requirements_aliases($ret, $description, $databases)) { |
|
163
|
|
|
return $ret; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
if (!_mongodb_requirements_databases($settings, $databases, $description)) { |
|
167
|
|
|
$ret['mongodb'] += [ |
|
168
|
|
|
'value' => t('Inconsistent database/client settings.'), |
|
169
|
|
|
'severity' => REQUIREMENT_ERROR, |
|
170
|
|
|
'description' => $description, |
|
171
|
|
|
]; |
|
172
|
|
|
return $ret; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
$ret['mongodb'] += [ |
|
176
|
|
|
'value' => t('Valid configuration'), |
|
177
|
|
|
'description' => $description, |
|
178
|
|
|
]; |
|
179
|
|
|
return $ret; |
|
180
|
|
|
} |
|
|
|
|
|
|
181
|
|
|
|