Files
google-labs-jules[bot] 10316e0c40 Fix: Correct PluginSocProfile registration and add activation functions
This commit addresses two issues:

1. Re-applies the fix for the `PluginSocProfile` registration.
   The extraneous 'classname' attribute, which caused a warning
   (Warning: Unknown attributes "classname" used in "PluginSocProfile" class
   registration in /var/www/glpi/src/Plugin.php on line 1667),
   has been removed. The registration is now correctly:
   `Plugin::registerClass('PluginSocProfile');`

2. Ensures plugin activation/deactivation functions are present.
   Adds the `plugin_enable_soc` and `plugin_disable_soc` functions
   to `setup.php`. These are required by GLPI to manage the plugin's
   lifecycle and display the enable/disable buttons in the plugin
   management interface.

These changes ensure the plugin registers correctly without warnings and
can be properly activated and deactivated within GLPI.
2025-05-31 13:10:23 +00:00

233 lines
7.7 KiB
PHP

<?php
/**
* Init the hooks of the SOC plugin
*/
use Glpi\Plugin\Hooks;
define('PLUGIN_SOC_VERSION', '1.0.0');
define('PLUGIN_SOC_MIN_GLPI', '10.0.0');
define('PLUGIN_SOC_MAX_GLPI', '10.1.0');
/**
* Plugin description
*
* @return array
*/
function plugin_version_soc() {
return [
'name' => 'SOC Case Management',
'version' => PLUGIN_SOC_VERSION,
'author' => 'Tips-Of-Mine',
'license' => 'GPL-3.0+',
'homepage' => 'https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management/',
'requirements' => [
'glpi' => [
'min' => PLUGIN_SOC_MIN_GLPI,
'max' => PLUGIN_SOC_MAX_GLPI,
],
'php' => [
'min' => '7.4.0',
]
]
];
}
/**
* Check plugin prerequisites before installation
*
* @return boolean
*/
function plugin_soc_check_prerequisites() {
if (version_compare(GLPI_VERSION, PLUGIN_SOC_MIN_GLPI, 'lt') || version_compare(GLPI_VERSION, PLUGIN_SOC_MAX_GLPI, 'gt')) {
echo "This plugin requires GLPI >= " . PLUGIN_SOC_MIN_GLPI . " and < " . PLUGIN_SOC_MAX_GLPI;
return false;
}
return true;
}
/**
* Check if plugin configuration is compatible with current GLPI status
*
* @return boolean
*/
function plugin_soc_check_config() {
return true;
}
/**
* Plugin initialization
*
* @global array $PLUGIN_HOOKS
* @return void
*/
function plugin_init_soc() {
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['soc'] = true;
// Add JavaScript and CSS
$PLUGIN_HOOKS['javascript']['soc'] = ['plugins/soc/js/soc.js'];
$PLUGIN_HOOKS['add_css']['soc'] = ['plugins/soc/css/soc.css'];
// Initialize translations
include_once(GLPI_ROOT . '/plugins/soc/inc/plugin_init_translations.php');
$PLUGIN_HOOKS['init_translations']['soc'] = 'plugin_init_soc_translations';
// Register plugin classes
Plugin::registerClass('PluginSocCase');
Plugin::registerClass('PluginSocProfile');
// Add menu items
if (Session::haveRight('plugin_soc_case', READ)) {
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
}
// Add tabs to items
$PLUGIN_HOOKS['add_tab']['soc'] = [
'Ticket' => ['PluginSocCase', 'displayTabContentForItem'],
'Change' => ['PluginSocCase', 'displayTabContentForItem']
];
// Add config page
if (Session::haveRight('config', UPDATE)) {
$PLUGIN_HOOKS['config_page']['soc'] = 'front/config.form.php';
}
// Hook for item actions
$PLUGIN_HOOKS['item_add']['soc'] = ['*' => 'plugin_soc_item_add'];
$PLUGIN_HOOKS['item_update']['soc'] = ['*' => 'plugin_soc_item_update'];
$PLUGIN_HOOKS['item_delete']['soc'] = ['*' => 'plugin_soc_item_delete'];
$PLUGIN_HOOKS['item_purge']['soc'] = ['*' => 'plugin_soc_item_purge'];
// Add standard hooks
$PLUGIN_HOOKS['headings']['soc'] = 'plugin_get_headings_soc';
$PLUGIN_HOOKS['headings_action']['soc'] = 'plugin_headings_actions_soc';
$PLUGIN_HOOKS['dropdown']['soc'] = 'plugin_soc_getDropdowns';
}
/**
* Install all necessary elements for the plugin
*
* @return boolean
*/
function plugin_soc_install() {
global $DB;
if (!$DB->tableExists('glpi_plugin_soc_cases')) {
$query = "CREATE TABLE `glpi_plugin_soc_cases` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`entities_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`is_recursive` tinyint(1) NOT NULL DEFAULT '0',
`severity` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`status` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`date_creation` timestamp NULL DEFAULT NULL,
`date_mod` timestamp NULL DEFAULT NULL,
`description` text COLLATE utf8mb4_unicode_ci,
`users_id_tech` int(11) UNSIGNED NOT NULL DEFAULT '0',
`groups_id_tech` int(11) UNSIGNED NOT NULL DEFAULT '0',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `entities_id` (`entities_id`),
KEY `is_recursive` (`is_recursive`),
KEY `severity` (`severity`),
KEY `status` (`status`),
KEY `users_id_tech` (`users_id_tech`),
KEY `groups_id_tech` (`groups_id_tech`),
KEY `is_deleted` (`is_deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$DB->query($query) or die("Error creating glpi_plugin_soc_cases table " . $DB->error());
}
if (!$DB->tableExists('glpi_plugin_soc_case_tickets')) {
$query = "CREATE TABLE `glpi_plugin_soc_case_tickets` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`plugin_soc_cases_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`tickets_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`date_creation` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`tickets_id`),
KEY `tickets_id` (`tickets_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$DB->query($query) or die("Error creating glpi_plugin_soc_case_tickets table" . $DB->error());
}
if (!$DB->tableExists('glpi_plugin_soc_case_changes')) {
$query = "CREATE TABLE `glpi_plugin_soc_case_changes` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`plugin_soc_cases_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`changes_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`date_creation` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`changes_id`),
KEY `changes_id` (`changes_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$DB->query($query) or die("Error creating glpi_plugin_soc_case_changes table" . $DB->error());
}
// Create profiles rights
PluginSocProfile::initProfile();
PluginSocProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
// Initialize plugin configuration
PluginSocConfig::install();
return true;
}
/**
* Uninstall the plugin
*
* @return boolean
*/
function plugin_soc_uninstall() {
global $DB;
// Delete plugin tables
$tables = [
'glpi_plugin_soc_cases',
'glpi_plugin_soc_case_tickets',
'glpi_plugin_soc_case_changes',
'glpi_plugin_soc_profiles'
];
foreach ($tables as $table) {
$query = "DROP TABLE IF EXISTS `$table`";
$DB->query($query) or die("Error dropping $table table");
}
// Delete plugin rights from profiles table
$query = "DELETE FROM `glpi_profilerights` WHERE `name` LIKE 'plugin_soc_%'";
$DB->query($query) or die("Error deleting plugin_soc rights");
// Delete plugin display preferences
$query = "DELETE FROM `glpi_displaypreferences` WHERE `itemtype` LIKE 'PluginSoc%'";
$DB->query($query) or die("Error deleting plugin_soc display preferences");
// Uninstall plugin configuration
PluginSocConfig::uninstall();
return true;
}
/**
* Plugin activation function
*
* @return boolean
*/
function plugin_enable_soc() {
// Add any specific activation logic here if needed in the future
return true;
}
/**
* Plugin deactivation function
*
* @return boolean
*/
function plugin_disable_soc() {
// Add any specific deactivation logic here if needed in the future
return true;
}