mirror of
https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management.git
synced 2025-06-28 05:38:42 +02:00
203 lines
6.6 KiB
PHP
203 lines
6.6 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;
|
|
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
|
|
$PLUGIN_HOOKS['javascript']['soc'] = ['plugins/soc/js/soc.js'];
|
|
$PLUGIN_HOOKS['add_css']['soc'] = ['plugins/soc/css/soc.css'];
|
|
|
|
// Initialize translations
|
|
Plugin::registerClass('PluginSocCase');
|
|
|
|
if (Session::haveRight('plugin_soc_case', READ)) {
|
|
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
|
|
}
|
|
|
|
// Add a tab to Changes
|
|
if (Session::haveRight('change', READ)) {
|
|
Plugin::registerClass('PluginSocCase', [
|
|
'addtabtypes' => ['Change']
|
|
]);
|
|
}
|
|
|
|
// Add a tab to Tickets
|
|
if (Session::haveRight('ticket', READ)) {
|
|
Plugin::registerClass('PluginSocCase', [
|
|
'addtabtypes' => ['Ticket']
|
|
]);
|
|
}
|
|
|
|
// Add config page
|
|
if (Session::haveRight('config', UPDATE)) {
|
|
$PLUGIN_HOOKS['config_page']['soc'] = 'front/config.form.php';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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) NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
`entities_id` int(11) NOT NULL DEFAULT '0',
|
|
`is_recursive` tinyint(1) NOT NULL DEFAULT '0',
|
|
`severity` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
`status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
`date_creation` timestamp NULL DEFAULT NULL,
|
|
`date_mod` timestamp NULL DEFAULT NULL,
|
|
`description` text COLLATE utf8_unicode_ci,
|
|
`users_id_tech` int(11) NOT NULL DEFAULT '0',
|
|
`groups_id_tech` int(11) 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=utf8 COLLATE=utf8_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) NOT NULL AUTO_INCREMENT,
|
|
`plugin_soc_cases_id` int(11) NOT NULL DEFAULT '0',
|
|
`tickets_id` int(11) 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=utf8 COLLATE=utf8_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) NOT NULL AUTO_INCREMENT,
|
|
`plugin_soc_cases_id` int(11) NOT NULL DEFAULT '0',
|
|
`changes_id` int(11) 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=utf8 COLLATE=utf8_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;
|
|
} |