Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions htdocs/ticket/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,13 @@

$res = $object->setStatut($new_status, null, '', $triggermodname);
if ($res) {
if ($new_status != Ticket::STATUS_NOT_READ) {
$res = $object->setReadDate($user, 1); // Update date read if necessary, without trigger because we already run trigger in setStatut()
if ($res < 0) {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
}
$url = 'card.php?track_id=' . $object->track_id;
header("Location: " . $url);
exit();
Expand Down
58 changes: 58 additions & 0 deletions htdocs/ticket/class/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,64 @@ public function markAsRead($user, $notrigger = 0)
return 0;
}

/**
* Set read date if not already set.
*
* @param User $user User performing the action
* @param int $notrigger Disable triggers
* @return int Return -1 if error, 0 if nothing done, 1 if success
*/
public function setReadDate($user, $notrigger = 0)
{
global $langs;

if (!empty($this->date_read)) {
return 0;
}

$this->oldcopy = dol_clone($this, 2);

$this->db->begin();

$sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
$sql .= " SET date_read = '".$this->db->idate(dol_now())."'";
$sql .= ", fk_user_modif = ".((int) $user->id);
$sql .= " WHERE rowid = ".((int) $this->id);

dol_syslog(get_class($this)."::setReadDate");

$resql = $this->db->query($sql);

if (!$resql) {
$this->db->rollback();
$this->date_read = $this->oldcopy->date_read;
$this->error = $this->db->lasterror();

dol_syslog(get_class($this)."::setReadDate ".$this->error, LOG_ERR);
return -1;
}

if (!$notrigger) {
$result = $this->call_trigger('TICKET_MODIFY', $user);
if ($result < 0) {
$this->db->rollback();
$this->date_read = $this->oldcopy->date_read;
$this->error = implode(',', $this->errors);

dol_syslog(get_class($this)."::setReadDate ".$this->error, LOG_ERR);
return -1;
}
}

$this->db->commit();

$this->date_read = dol_now();
$this->fk_user_modif = $user->id;
$this->user_modification_id = $user->id;

return 1;
}

/**
* Set an assigned user to a ticket.
*
Expand Down
Loading