Skip to content

Commit

Permalink
Fix broken tag rules with ticket created from mails
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault authored and cedric-anne committed Aug 9, 2023
1 parent f3c8bce commit 88e5db1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function plugin_tag_getDropdown() {
* @return array the massive action list
*/
function plugin_tag_MassiveActions($itemtype = '') {
if (PluginTagTag::canItemtype($itemtype) && is_a($itemtype, CommonDBTM::class, true) && $itemtype::canUpdate()) {
if (PluginTagTag::canItemtype($itemtype) && is_a($itemtype, CommonDBTM::class, true) && $itemtype::canUpdate()) {
return [
'PluginTagTagItem'.MassiveAction::CLASS_ACTION_SEPARATOR.'addTag'
=> __("Add tags", 'tag'),
Expand Down Expand Up @@ -256,6 +256,13 @@ function plugin_tag_post_init() {
$PLUGIN_HOOKS['pre_item_purge']['tag'][$itemtype] = ['PluginTagTagItem', 'purgeItem'];
}
}

// Always define hook for tickets
// Needed for rules to function properly when a ticket is created from a mail
// collector
$PLUGIN_HOOKS['item_add']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS['pre_item_update']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS['pre_item_purge']['tag'][Ticket::getType()] = ['PluginTagTagItem', 'purgeItem'];
}

function plugin_tag_getRuleActions($params = [])
Expand Down
10 changes: 9 additions & 1 deletion inc/tagitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,15 @@ static function showForTag(PluginTagTag $tag) {
static function updateItem(CommonDBTM $item, bool $delete_existing_tags = true) {

if ($item->getID()
&& !isset($item->input["_plugin_tag_tag_process_form"])) {
&& !isset($item->input["_plugin_tag_tag_process_form"])
&& !(
// Always trigger on newly created tickets, as they may come from
// the mail collector which wont set the _plugin_tag_tag_process_form
// flag
$item::getType() == Ticket::getType()
&& $item->fields['date_creation'] == $_SESSION['glpi_currenttime']
)
) {
return true;
}

Expand Down

0 comments on commit 88e5db1

Please sign in to comment.