Fix: Implement missing GLPI plugin registration functions

Adds the following mandatory functions to setup.php to ensure the plugin
can be correctly registered and identified by GLPI:

- `plugin_version()`: Parses plugin.xml to provide metadata such as name,
  version, author, and compatibility to GLPI.
- `plugin_init_options()`: Returns essential plugin identifiers like
  its key and display name.
- Stub functions `plugin_check_prerequisites()`, `plugin_check_config()`,
  and `plugin_display_config()`: Added to prevent potential errors and
  serve as placeholders for future functionality.

These changes address the issue of the plugin not appearing in the GLPI
plugin installation interface.
This commit is contained in:
google-labs-jules[bot]
2025-05-31 10:01:09 +00:00
parent 9ce90bfc5c
commit e461da61d7

114
setup.php
View File

@ -1,4 +1,118 @@
<?php
/**
* Get plugin version information
*
* @return array
*/
function plugin_version() {
$xml = simplexml_load_file(__DIR__ . '/plugin.xml');
if ($xml === false) {
// Handle error: plugin.xml not found or unreadable
return []; // Or throw an exception
}
$authors = [];
if (isset($xml->authors) && isset($xml->authors->author)) {
foreach ($xml->authors->author as $author) {
$authors[] = (string)$author->name . (isset($author->email) ? ' &lt;' . (string)$author->email . '&gt;' : '');
}
}
$versions = [];
if (isset($xml->versions) && isset($xml->versions->version)) {
foreach ($xml->versions->version as $version) {
$versions[] = [
'num' => (string)$version->num,
'minGlpiVersion' => (string)$version->compatibility, // GLPI expects minGlpiVersion
];
}
}
$langs = [];
if (isset($xml->langs) && isset($xml->langs->lang)) {
foreach ($xml->langs->lang as $lang) {
$langs[] = (string)$lang;
}
}
$tags = [];
if (isset($xml->tags)) {
foreach ($xml->tags->children() as $lang_code => $tag_list) {
$current_tags = [];
foreach ($tag_list->tag as $tag) {
$current_tags[] = (string)$tag;
}
$tags[$lang_code] = $current_tags;
}
}
return [
'name' => (string)$xml->name,
'key' => (string)$xml->key,
'state' => (string)$xml->state,
'logo' => (string)$xml->logo,
'shortdesc' => (string)$xml->description_short, // GLPI expects shortdesc
'longdesc' => (string)$xml->description_long, // GLPI expects longdesc
'homepage' => (string)$xml->homepage,
'download' => (string)$xml->download,
'issues_tracker' => (string)$xml->issues, // GLPI expects issues_tracker
'readme' => (string)$xml->readme,
'authors' => $authors,
'versions' => $versions,
'langs' => $langs,
'license' => (string)$xml->license,
'tags' => $tags,
'minGlpiVersion' => !empty($versions) ? $versions[count($versions)-1]['minGlpiVersion'] : '' // Default to last version's compatibility
];
}
/**
* Initialize plugin options
*
* @return array
*/
function plugin_init_options() {
return [
'name' => __('SOC Case Management', 'soc'),
'key' => 'soc',
'tooltip' => __('SOC Case Management integration plugin for security teams.', 'soc'),
];
}
/**
* Check plugin prerequisites.
*
* @return boolean
*/
function plugin_check_prerequisites() {
// For now, always return true
return true;
}
/**
* Check plugin configuration.
*
* @param boolean $verbose Enable verbose mode (default false)
*
* @return boolean
*/
function plugin_check_config($verbose = false) {
// For now, always return true
return true;
}
/**
* Display plugin configuration page.
*
* @return void
*/
function plugin_display_config() {
// Currently does nothing
}
/**
* Init the hooks of the plugin
*