Fix email collector to add update of ticket email collector (#29541)

* Fix email collector to add update of ticket email collector

* update lang file

* fix lang file

---------

Co-authored-by: Hystepik <lmarcouiller@nltechno.com>
This commit is contained in:
Lucas Marcouiller 2024-05-01 17:34:55 +02:00 committed by GitHub
parent 960063a531
commit 2928ae54c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 11 deletions

View File

@ -2277,7 +2277,7 @@ class EmailCollector extends CommonObject
if ($mode < 2) { // 0=Mode production, 1=Mode test (read IMAP and try SQL update then rollback), 2=Mode test with no SQL updates
foreach ($this->actions as $operation) {
$errorforthisaction = 0;
$ticketalreadyexists = 0;
if ($errorforactions) {
break;
}
@ -2313,6 +2313,31 @@ class EmailCollector extends CommonObject
$descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailCC").($langs->trans("MailCC") != 'CC' ? ' (CC)' : '').' : '.dol_escape_htmltag($sendtocc));
}
if ($operation['type'] == 'ticket') {
// Verify if ticket already exists to fall back on the right operation
$tickettocreate = new Ticket($this->db);
$errorfetchticket = 0;
$alreadycreated1 = 0;
if (!empty($trackid)) {
$alreadycreated1 = $tickettocreate->fetch(0, '', $trackid);
}
$alreadycreated2 = $tickettocreate->fetch(0, '', '', $msgid);
$alreadycreated = $alreadycreated1 + $alreadycreated2;
if ($alreadycreated1 < 0 || $alreadycreated2 < 0) {
$errorfetchticket ++;
}
if (empty($errorfetchticket)) {
if ($alreadycreated == 0) {
$ticketalreadyexists = 0;
} else {
$ticketalreadyexists = 1;
$operation['type'] = 'recordevent';
}
} else {
$ticketalreadyexists = -1;
}
}
// Search and create thirdparty
if ($operation['type'] == 'loadthirdparty' || $operation['type'] == 'loadandcreatethirdparty') {
if (empty($operation['actionparam'])) {
@ -3067,15 +3092,7 @@ class EmailCollector extends CommonObject
} elseif ($operation['type'] == 'ticket') {
// Create ticket
$tickettocreate = new Ticket($this->db);
$errorfetchticket = 0;
$alreadycreated1 = $tickettocreate->fetch(0, '', $trackid);
$alreadycreated2 = $tickettocreate->fetch(0, '', '', $msgid);
$alreadycreated = $alreadycreated1 + $alreadycreated2;
if ($alreadycreated1 < 0 || $alreadycreated2 < 0) {
$errorfetchticket ++;
}
if (empty($errorfetchticket) && $alreadycreated == 0) {
if ($ticketalreadyexists == 0) {
if ($thirdpartystatic->id > 0) {
$tickettocreate->socid = $thirdpartystatic->id;
$tickettocreate->fk_soc = $thirdpartystatic->id;

View File

@ -2181,7 +2181,7 @@ NoNewEmailToProcess=No new email (matching filters) to process
NothingProcessed=Nothing done
RecordEvent=Record an event in agenda (with type Email sent or received)
CreateLeadAndThirdParty=Create a lead (and a third party if necessary)
CreateTicketAndThirdParty=Create a ticket (linked to a third party if the third party was loaded by a previous operation or was guessed from a tracker in email header, without third party otherwise)
CreateTicketAndThirdParty=Create or complete a ticket (linked to a third party if the third party was loaded by a previous operation or was guessed from a tracker in email header, without third party otherwise)
CodeLastResult=Latest result code
NbOfEmailsInInbox=Number of emails in source directory
LoadThirdPartyFromName=Load third party searching on %s (load only)