Skip to content

Commit

Permalink
issue: Activity Notice getLastRespondent()
Browse files Browse the repository at this point in the history
This addresses issue 3647 where Internal Activity Alerts are never sent out
for both Tasks and Tickets. Upon initial investigation it appeared that we
set the `lastrespondent` property before we call
`onResponse()`/`onActivity()` so when we checked the Last Respondent it was
the same Agent posting the Reply so an email was never sent out. Upon moving
the `lastrespondent` property below the `onResponse()`/`onActivity()` calls,
it still grabbed the current Responding Agent. Looking deeper into
`getLastRespondent()` (for both Ticket and Task classes) I found that the
query we use to get the Last Response from an Agent on the Thread, grabs the
newly added Response. This is because the Thread Entry is added before we
call `getLastRespondent()` so we really need to grab the second record, not
the first. This updates the `limit()` clause from `1` to `1,1` to utilize
MySQL/MariaDB "LIMIT offest" so that we grab the second entry which is the
true Last Response. This also moves the `lastrespondent` property below the
`onResponse()`/`onActivity()` calls to ensure we don't return the current
Responding Agent.
  • Loading branch information
JediKev committed Jun 17, 2020
1 parent 741122a commit 07024fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions include/class.task.php
Expand Up @@ -361,7 +361,7 @@ function getLastRespondent() {
))
->values_flat('thread__entries__staff_id')
->order_by('-thread__entries__id')
->limit(1)
->limit('1,1')
))
->first()
?: false;
Expand Down Expand Up @@ -1039,16 +1039,17 @@ function postReply($vars, &$errors, $alert = true) {
}
*/

$this->lastrespondent = $response->staff;
$this->save();

// Send activity alert to agents
$activity = $vars['activity'] ?: $response->getActivity();
$this->onActivity( array(
'activity' => $activity,
'threadentry' => $response,
'assignee' => $assignee,
));

$this->lastrespondent = $response->staff;
$this->save();

// Send alert to collaborators
if ($alert && $vars['emailcollab']) {
$signature = '';
Expand Down
6 changes: 3 additions & 3 deletions include/class.ticket.php
Expand Up @@ -814,7 +814,7 @@ function getLastRespondent() {
))
->values_flat('staff_id')
->order_by('-id')
->limit(1)
->limit('1,1')
))
->first()
?: false;
Expand Down Expand Up @@ -3329,10 +3329,10 @@ function postReply($vars, &$errors, $alert=true, $claim=true) {
$this->setStaffId($thisstaff->getId()); //direct assignment;
}

$this->lastrespondent = $response->staff;

$this->onResponse($response, array('assignee' => $assignee)); //do house cleaning..

$this->lastrespondent = $response->staff;

$type = array('type' => 'message');
Signal::send('object.created', $this, $type);

Expand Down

0 comments on commit 07024fc

Please sign in to comment.