Ticket Organisation Hooks
The seven hooks over merging, splitting and moving tickets.
Overview
The operations that reorganise tickets live here: merging, splitting, and changing the department, priority or linked service.
The first two cannot be undone. A merge deletes everything but the target; a split moves replies into a new ticket. That is what makes the gates valuable.
Reference
Stopping a ticket merge
Runs before tickets are merged. A merge cannot be undone: everything but the target is deleted.
Hook::add('gate:ticket.merge', 10, function ($primary_id, $merge_ids) {
// Everything but the target is DELETED: this cannot be undone.
foreach ($merge_ids as $id)
if (Acme::underLegalHold((int) $id)) return 'A ticket under legal hold cannot be merged.';
return null;
});Following a merge
Runs after the tickets are merged.
Hook::add('action:ticket.merged', 10, function ($primary_id, $merged_ids) {
// Those ids are gone: point them at the target.
foreach ($merged_ids as $id) Acme::redirectRef((int) $id, $primary_id);
});Stopping a ticket split
Runs before some replies of a ticket are moved into a new one.
Hook::add('gate:ticket.split', 10, function ($source, $reply_ids) {
// The list has not been checked against the database yet.
if (count($reply_ids) > 50) return 'At most 50 replies can move at once.';
return null;
});Following a split
Runs after the new ticket is created and the replies have moved.
Hook::add('action:ticket.split', 10, function ($source, $new_ticket, $moved_reply_ids) {
// This list is verified: what really moved.
Acme::reindexSplit((int) ($new_ticket['id'] ?? 0), $moved_reply_ids);
});Following a department change
Runs after a ticket moves to another department. The department decides who sees the ticket.
Hook::add('action:ticket.department_changed', 10,
function ($ticket, $oldDepartmentId, $newDepartmentId) {
// The department decides who sees it.
Acme::notifyDepartment($newDepartmentId, (int) ($ticket['id'] ?? 0));
});Following a priority change
Runs after the priority of a ticket changes.
Hook::add('action:ticket.priority_changed', 10,
function ($ticket, $oldPriority, $newPriority) {
if ($newPriority > $oldPriority) Acme::escalate((int) ($ticket['id'] ?? 0));
});Following the linked service changing
Runs after the service a ticket is linked to changes.
Hook::add('action:ticket.service_changed', 10,
function ($ticket, $oldServiceId, $newServiceId) {
// Zero means the link was removed.
if (!$newServiceId) return;
Acme::attachServiceContext((int) ($ticket['id'] ?? 0), $newServiceId);
});Pitfalls
In a merge everything but the target is deleted, not merely moved. The ids in the event hook are records that no longer exist: point them at the target on your side, or you are left with broken references.
The reply ids reaching the gate are cleaned but not matched against the database: the list may hold an id that does not belong to that ticket. To see what really moved, read the list in the event hook.
Related Articles
- Support Ticket Hooks
- Customer Account Hooks
- How Hooks Work
Thanks for your feedback!
Our support team is here around the clock for anything you can't find above.