Skip to content

Commit 838c077

Browse files
committed
Fix compatibility check with GLPI < 9.2
1 parent 23c0380 commit 838c077

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

setup.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737

3838
define ('PLUGIN_GENERICOBJECT_VERSION', '2.5.1');
3939

40+
// Minimal GLPI version, inclusive
41+
define("PLUGIN_GENERICOBJECT_MIN_GLPI", "9.2");
42+
// Maximum GLPI version, exclusive
43+
define("PLUGIN_GENERICOBJECT_MAX_GLPI", "9.3");
44+
4045
if (!defined("GENERICOBJECT_DIR")) {
4146
define("GENERICOBJECT_DIR", GLPI_ROOT . "/plugins/genericobject");
4247
}
@@ -184,18 +189,20 @@ function plugin_post_init_genericobject() {
184189
* @return array
185190
*/
186191
function plugin_version_genericobject() {
187-
return array ('name' => __("Objects management", "genericobject"),
188-
'version' => PLUGIN_GENERICOBJECT_VERSION,
189-
'author' => "<a href=\"mailto:contact@teclib.com\">Teclib'</a> & siprossii",
190-
'homepage' => 'https://github.com/pluginsGLPI/genericobject',
191-
'license' => 'GPLv2+',
192-
'requirements' => [
193-
'glpi' => [
194-
'min' => '9.2',
195-
'dev' => true
196-
]
197-
]
198-
);
192+
return [
193+
'name' => __("Objects management", "genericobject"),
194+
'version' => PLUGIN_GENERICOBJECT_VERSION,
195+
'author' => "<a href=\"mailto:contact@teclib.com\">Teclib'</a> & siprossii",
196+
'homepage' => 'https://github.com/pluginsGLPI/genericobject',
197+
'license' => 'GPLv2+',
198+
'requirements' => [
199+
'glpi' => [
200+
'min' => PLUGIN_GENERICOBJECT_MIN_GLPI,
201+
'max' => PLUGIN_GENERICOBJECT_MAX_GLPI,
202+
'dev' => true, //Required to allow 9.2-dev
203+
]
204+
]
205+
];
199206
}
200207

201208
/**
@@ -205,11 +212,25 @@ function plugin_version_genericobject() {
205212
* @return boolean
206213
*/
207214
function plugin_genericobject_check_prerequisites() {
208-
$version = rtrim(GLPI_VERSION, '-dev');
209-
if (version_compare($version, '9.2', 'lt')) {
210-
echo "This plugin requires GLPI 9.2 or higher";
211-
return false;
215+
216+
//Version check is not done by core in GLPI < 9.2 but has to be delegated to core in GLPI >= 9.2.
217+
if (!method_exists('Plugin', 'checkGlpiVersion')) {
218+
$version = preg_replace('/^((\d+\.?)+).*$/', '$1', GLPI_VERSION);
219+
$matchMinGlpiReq = version_compare($version, PLUGIN_GENERICOBJECT_MIN_GLPI, '>=');
220+
$matchMaxGlpiReq = version_compare($version, PLUGIN_GENERICOBJECT_MAX_GLPI, '<');
221+
222+
if (!$matchMinGlpiReq || !$matchMaxGlpiReq) {
223+
echo vsprintf(
224+
'This plugin requires GLPI >= %1$s and < %2$s.',
225+
[
226+
PLUGIN_GENERICOBJECT_MIN_GLPI,
227+
PLUGIN_GENERICOBJECT_MAX_GLPI,
228+
]
229+
);
230+
return false;
231+
}
212232
}
233+
213234
return true;
214235
}
215236

0 commit comments

Comments
 (0)