Skip to content

Fix: simplify group reassignment via core actor diff - #488

Open
Rom1-B wants to merge 1 commit into
feature/glpi-12.0from
fix_actor
Open

Fix: simplify group reassignment via core actor diff#488
Rom1-B wants to merge 1 commit into
feature/glpi-12.0from
fix_actor

Conversation

@Rom1-B

@Rom1-B Rom1-B commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

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):

Comment thread inc/ticket.class.php
// 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
    },
));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Rom1-B
Rom1-B requested a review from stonebuzz August 27, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants