Ticket API: allow postNewMessage to target ticket by id or ref (#39360)

POST /tickets/newmessage could only reach a ticket via its track_id
(fetch was hardcoded to id=0). This resolves the ticket by id, then ref,
then track_id (kept as fallback), so integrations that store the Dolibarr
ticket id can append messages without knowing the track_id.
This commit is contained in:
Pichinov-Jose 2026-08-04 18:36:51 +02:00 committed by GitHub
parent 2be65df31f
commit 6049574af7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@
/* Copyright (C) 2016 Jean-François Ferry <hello@librethic.io>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -435,7 +436,14 @@ class Tickets extends DolibarrApi
$this->ticket->$field = $this->_checkValForAPI($field, $value, $this->ticket);
}
$ticketMessageText = $this->ticket->message;
$result = $this->ticket->fetch(0, '', $this->ticket->track_id);
// Allow targeting the ticket by id or ref, not only track_id
if (!empty($this->ticket->id)) {
$result = $this->ticket->fetch($this->ticket->id);
} elseif (!empty($this->ticket->ref)) {
$result = $this->ticket->fetch(0, $this->ticket->ref);
} else {
$result = $this->ticket->fetch(0, '', $this->ticket->track_id);
}
if (!$result) {
throw new RestException(404, 'Ticket not found');
}