Fix: simplify group reassignment via core actor diff - #488
Conversation
| // that add a group without already removing the old one themselves. | ||
| if ($_SESSION['glpi_plugins']['escalade']['config']['remove_group'] == true) { | ||
| $all_actors = self::getTicketFieldsWithActors($tickets_id, $groups_id); | ||
|
|
There was a problem hiding this comment.
The array_filter block that was removed from processAfterAddGroup served dual purpose: it ensured _actors contained only the new group so GLPI core (a) removed old groups from the DB and (b) fired business rules against the final actor state. For the primary Escalade path, this is now redundant: the diff-only update at line 1250 runs first and GLPI core removes old groups atomically before processAfterAddGroup fires. For the secondary safety-net path — entry points such as auto-assign or category-based reassignment that insert a Group_Ticket row directly without going through getTicketFieldsWithActors at line 1246 — old groups are still in the DB when this hook fires. getTicketFieldsWithActors() will return old groups + new group, and the rules update call will include old groups in _actors, causing GLPI core to keep them rather than remove them. These paths were exactly what the safety-net comment names; they lose their cleanup behaviour.
// Restoring intent: only carry the new group so GLPI removes stale groups.
$seen_new = false;
$all_actors['assign'] = array_values(array_filter(
$all_actors['assign'],
function (array $actor) use ($groups_id, &$seen_new): bool {
if ($actor['itemtype'] !== 'Group') {
return true;
}
if ($actor['items_id'] == $groups_id && !$seen_new) {
$seen_new = true;
return true;
}
return false;
},
));There was a problem hiding this comment.
The old array_filter wasn't removed, it moved into getTicketFieldsWithActors() (lines 1250-1252), which now resets the Group assign list to just the new group before returning, independent of what's already in DB. That function is shared by all three callers including processAfterAddGroup's safety net at line 541, so the auto-assign/category-reassignment entry points still get old groups cleaned up.
Checklist before requesting a review
Please delete options that are not relevant.
Checklist before requesting a review
Please delete options that are not relevant.
Description
fixes #N/A
Group reassignment now sends a single actor diff to GLPI core instead of a two-step add-then-remove sequence.
This relies on GLPI 12 core preserving ticket status and notifications correctly when an actor is removed and another added in the same request, which removes the need for the plugin's own workaround.
Related to: fix(notifications): actor replacement glpi-project/glpi#15623
Screenshots (if appropriate):