Пример #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(TicketInterface $ticket, TicketActionInterface $action)
 {
     $ticketOld = $ticket->find($this->data->get('ticket_id'));
     $actionOld = $action->findWhere(['ticket_id' => $this->data->get('ticket_id'), 'type' => 'create'])->first();
     // dd($this->data);
     $ticket->update($this->data->only(['user_id', 'priority', 'org_id'])->toArray(), $this->data->get('ticket_id'));
     $action->update($this->data->only(['body', 'title'])->toArray(), $actionOld->id);
     $ticketUpdated = $ticket->find($this->data->get('ticket_id'));
     $actionUpdated = $action->find($actionOld->id);
     $changes = array_merge($this->getActionChanges($actionOld, $actionUpdated), $this->getTicketChanges($ticketOld, $ticketUpdated));
     if (empty($changes)) {
         return null;
     }
     $action = $this->createEditAction($action, $changes);
     $action->ticketOld = $ticketOld;
     $action->actionOld = $actionOld;
     $action->ticketUpdated = $ticketUpdated;
     //throw event
     if (!$this->data->get('defer_event')) {
         event(new ActionCreatedEvent($action));
     }
     return $action;
 }
Пример #2
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(TicketActionInterface $action, TimeLogInterface $time, TicketInterface $ticket)
 {
     $exist = $ticket->find($this->data->get('ticket_id'));
     if ($exist->status == $this->data->get('type')) {
         throw Exception('Action can not be ' . $this->data->get('type') . ' on an existing ' . $exist->status . ' ticket.');
     }
     $action = $action->create($this->data->except(['hours', 'time_at', 'defer_event'])->toArray());
     //update timelog
     if ($this->data->get('hours') > 0 && in_array($this->data->get('type'), ['reply', 'comment', 'closed', 'resolved', 'open'])) {
         $this->updateTimeLog($action, $time);
     }
     // update ticket
     $ticket->update($this->getTicketAttrs($exist), $exist->id);
     //throw event
     if (!$this->data->get('defer_event')) {
         event(new ActionCreatedEvent($action));
     }
     return $action;
 }