Correction du schéma de la base de données et des hooks

This commit is contained in:
tips-of-mine
2025-05-31 14:50:31 +02:00
committed by GitHub
parent 4622a1a2cd
commit 80167ce471
3 changed files with 67 additions and 35 deletions

View File

@ -42,13 +42,29 @@ if (isset($_POST["add"])) {
Session::checkRight("plugin_soc_case", UPDATE); Session::checkRight("plugin_soc_case", UPDATE);
$case = new PluginSocCase(); $case = new PluginSocCase();
$case->getFromDB($_POST['plugin_soc_cases_id']); $case->getFromDB($_POST['plugin_soc_cases_id']);
$tickets_id = $case->createTicket($_POST);
// Link existing ticket to case
if (isset($_POST['tickets_id']) && $_POST['tickets_id'] > 0) {
$case->addTicket($_POST['tickets_id']);
} else {
// Create new ticket from case
$case->createTicket($_POST);
}
Html::back(); Html::back();
} else if (isset($_POST["add_change"])) { } else if (isset($_POST["add_change"])) {
Session::checkRight("plugin_soc_case", UPDATE); Session::checkRight("plugin_soc_case", UPDATE);
$case = new PluginSocCase(); $case = new PluginSocCase();
$case->getFromDB($_POST['plugin_soc_cases_id']); $case->getFromDB($_POST['plugin_soc_cases_id']);
$changes_id = $case->createChange($_POST);
// Link existing change to case
if (isset($_POST['changes_id']) && $_POST['changes_id'] > 0) {
$case->addChange($_POST['changes_id']);
} else {
// Create new change from case
$case->createChange($_POST);
}
Html::back(); Html::back();
} else { } else {
$id = ""; $id = "";

View File

@ -322,4 +322,26 @@ class PluginSocCase extends CommonDBTM {
'date_creation' => $_SESSION["glpi_currenttime"] 'date_creation' => $_SESSION["glpi_currenttime"]
]); ]);
} }
/**
* Display tab content for item
*
* @param CommonGLPI $item
* @param integer $tabnum
* @param integer $withtemplate
* @return boolean
*/
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
switch ($item->getType()) {
case 'Ticket':
$case_ticket = new PluginSocCaseTicket();
$case_ticket->showForTicket($item);
return true;
case 'Change':
$case_change = new PluginSocCaseChange();
$case_change->showForChange($item);
return true;
}
return false;
}
} }

View File

@ -76,26 +76,18 @@ function plugin_init_soc() {
// Register plugin classes // Register plugin classes
Plugin::registerClass('PluginSocCase'); Plugin::registerClass('PluginSocCase');
Plugin::registerClass('PluginSocProfile', ['addtabtypes' => ['Profile']]); Plugin::registerClass('PluginSocProfile', ['classname' => 'PluginSocProfile']);
// Add menu items // Add menu items
if (Session::haveRight('plugin_soc_case', READ)) { if (Session::haveRight('plugin_soc_case', READ)) {
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase']; $PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
} }
// Add a tab to Changes // Add tabs to items
if (Session::haveRight('change', READ)) { $PLUGIN_HOOKS['add_tab']['soc'] = [
$PLUGIN_HOOKS['add_tab']['soc'] = [ 'Ticket' => ['PluginSocCase', 'displayTabContentForItem'],
'Change' => 'PluginSocCase', 'Change' => ['PluginSocCase', 'displayTabContentForItem']
]; ];
}
// Add a tab to Tickets
if (Session::haveRight('ticket', READ)) {
$PLUGIN_HOOKS['add_tab']['soc'] = [
'Ticket' => 'PluginSocCase',
];
}
// Add config page // Add config page
if (Session::haveRight('config', UPDATE)) { if (Session::haveRight('config', UPDATE)) {
@ -108,8 +100,10 @@ function plugin_init_soc() {
$PLUGIN_HOOKS['item_delete']['soc'] = ['*' => 'plugin_soc_item_delete']; $PLUGIN_HOOKS['item_delete']['soc'] = ['*' => 'plugin_soc_item_delete'];
$PLUGIN_HOOKS['item_purge']['soc'] = ['*' => 'plugin_soc_item_purge']; $PLUGIN_HOOKS['item_purge']['soc'] = ['*' => 'plugin_soc_item_purge'];
// Display hooks // Add standard hooks
$PLUGIN_HOOKS['post_item_form']['soc'] = ['PluginSocCase', 'displayTabContentForItem']; $PLUGIN_HOOKS['headings']['soc'] = 'plugin_get_headings_soc';
$PLUGIN_HOOKS['headings_action']['soc'] = 'plugin_headings_actions_soc';
$PLUGIN_HOOKS['dropdown']['soc'] = 'plugin_soc_getDropdowns';
} }
/** /**
@ -122,17 +116,17 @@ function plugin_soc_install() {
if (!$DB->tableExists('glpi_plugin_soc_cases')) { if (!$DB->tableExists('glpi_plugin_soc_cases')) {
$query = "CREATE TABLE `glpi_plugin_soc_cases` ( $query = "CREATE TABLE `glpi_plugin_soc_cases` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`entities_id` int(11) NOT NULL DEFAULT '0', `entities_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`is_recursive` tinyint(1) NOT NULL DEFAULT '0', `is_recursive` tinyint(1) NOT NULL DEFAULT '0',
`severity` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `severity` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `status` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`date_creation` timestamp NULL DEFAULT NULL, `date_creation` timestamp NULL DEFAULT NULL,
`date_mod` timestamp NULL DEFAULT NULL, `date_mod` timestamp NULL DEFAULT NULL,
`description` text COLLATE utf8_unicode_ci, `description` text COLLATE utf8mb4_unicode_ci,
`users_id_tech` int(11) NOT NULL DEFAULT '0', `users_id_tech` int(11) UNSIGNED NOT NULL DEFAULT '0',
`groups_id_tech` int(11) NOT NULL DEFAULT '0', `groups_id_tech` int(11) UNSIGNED NOT NULL DEFAULT '0',
`is_deleted` tinyint(1) NOT NULL DEFAULT '0', `is_deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `name` (`name`), KEY `name` (`name`),
@ -143,33 +137,33 @@ function plugin_soc_install() {
KEY `users_id_tech` (`users_id_tech`), KEY `users_id_tech` (`users_id_tech`),
KEY `groups_id_tech` (`groups_id_tech`), KEY `groups_id_tech` (`groups_id_tech`),
KEY `is_deleted` (`is_deleted`) KEY `is_deleted` (`is_deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$DB->query($query) or die("Error creating glpi_plugin_soc_cases table " . $DB->error()); $DB->query($query) or die("Error creating glpi_plugin_soc_cases table " . $DB->error());
} }
if (!$DB->tableExists('glpi_plugin_soc_case_tickets')) { if (!$DB->tableExists('glpi_plugin_soc_case_tickets')) {
$query = "CREATE TABLE `glpi_plugin_soc_case_tickets` ( $query = "CREATE TABLE `glpi_plugin_soc_case_tickets` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`plugin_soc_cases_id` int(11) NOT NULL DEFAULT '0', `plugin_soc_cases_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`tickets_id` int(11) NOT NULL DEFAULT '0', `tickets_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`date_creation` timestamp NULL DEFAULT NULL, `date_creation` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`tickets_id`), UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`tickets_id`),
KEY `tickets_id` (`tickets_id`) KEY `tickets_id` (`tickets_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$DB->query($query) or die("Error creating glpi_plugin_soc_case_tickets table" . $DB->error()); $DB->query($query) or die("Error creating glpi_plugin_soc_case_tickets table" . $DB->error());
} }
if (!$DB->tableExists('glpi_plugin_soc_case_changes')) { if (!$DB->tableExists('glpi_plugin_soc_case_changes')) {
$query = "CREATE TABLE `glpi_plugin_soc_case_changes` ( $query = "CREATE TABLE `glpi_plugin_soc_case_changes` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`plugin_soc_cases_id` int(11) NOT NULL DEFAULT '0', `plugin_soc_cases_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`changes_id` int(11) NOT NULL DEFAULT '0', `changes_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`date_creation` timestamp NULL DEFAULT NULL, `date_creation` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`changes_id`), UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`changes_id`),
KEY `changes_id` (`changes_id`) KEY `changes_id` (`changes_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$DB->query($query) or die("Error creating glpi_plugin_soc_case_changes table" . $DB->error()); $DB->query($query) or die("Error creating glpi_plugin_soc_case_changes table" . $DB->error());
} }