1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base mail scanner action file. |
4
|
|
|
* |
5
|
|
|
* @package App |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce S.A. |
8
|
|
|
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Mail\ScannerAction; |
13
|
|
|
|
14
|
|
|
use App\Mail\RecordFinder; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Base mail scanner action class. |
18
|
|
|
*/ |
19
|
|
|
class CreatedHelpDesk extends Base |
20
|
|
|
{ |
21
|
|
|
/** {@inheritdoc} */ |
22
|
|
|
public static $priority = 5; |
23
|
|
|
|
24
|
|
|
/** {@inheritdoc} */ |
25
|
|
|
public function process(): void |
26
|
|
|
{ |
27
|
|
|
if ($this->checkExceptions('CreatedHelpDesk')) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
$scanner = $this->scannerEngine; |
31
|
|
|
if (($prefix = RecordFinder::getRecordNumberFromString($scanner->get('subject'), 'HelpDesk')) && \App\Record::getIdByRecordNumber($prefix, 'HelpDesk')) { |
32
|
|
|
return; |
33
|
|
|
} |
34
|
|
|
$fromEmail = [$scanner->get('from_email')]; |
35
|
|
|
$contactId = current(\App\Utils::flatten(RecordFinder::findByEmail($fromEmail, $scanner->getEmailsFields('Contacts')))); |
36
|
|
|
$parentId = current(\App\Utils::flatten(RecordFinder::findByEmail($fromEmail, $scanner->getEmailsFields('Accounts')))); |
37
|
|
|
if (!$parentId) { |
38
|
|
|
$parentId = current(\App\Utils::flatten(RecordFinder::findByEmail($fromEmail, $scanner->getEmailsFields('Vendors')))); |
39
|
|
|
} |
40
|
|
|
if (!$parentId && $contactId) { |
41
|
|
|
$parentId = \App\Record::getParentRecord($contactId, 'Contacts'); |
42
|
|
|
} |
43
|
|
|
$recordModel = \Vtiger_Record_Model::getCleanInstance('HelpDesk'); |
44
|
|
|
$this->loadServiceContracts($recordModel, $parentId); |
45
|
|
|
$recordModel->set('assigned_user_id', $scanner->getUserId()); |
46
|
|
|
$recordModel->set('created_user_id', $scanner->getUserId()); |
47
|
|
|
$recordModel->set('createdtime', $scanner->get('date')); |
48
|
|
|
$recordModel->setFromUserValue('ticket_title', \App\TextUtils::textTruncate($scanner->get('subject'), $recordModel->getField('ticket_title')->getMaxValue(), false)); |
49
|
|
|
$recordModel->set('description', \App\TextUtils::htmlTruncate($scanner->get('body'), $recordModel->getField('description')->getMaxValue())); |
50
|
|
|
$recordModel->set('ticketstatus', \Config\Modules\OSSMailScanner::$helpdeskCreateDefaultStatus); |
|
|
|
|
51
|
|
|
if ($contactId) { |
52
|
|
|
$recordModel->ext['relations'][] = [ |
53
|
|
|
'relatedModule' => 'Contacts', |
54
|
|
|
'relatedRecords' => [$contactId], |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
if ($mailId = $scanner->getMailCrmId()) { |
58
|
|
|
$recordModel->ext['relations'][] = [ |
59
|
|
|
'reverse' => true, |
60
|
|
|
'relatedModule' => 'OSSMailView', |
61
|
|
|
'relatedRecords' => [$mailId], |
62
|
|
|
'params' => $scanner->get('date'), |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
$recordModel->save(); |
66
|
|
|
$id = $recordModel->getId(); |
67
|
|
|
$scanner->processData['CreatedHelpDesk'] = $id; |
68
|
|
|
if ($mailId) { |
|
|
|
|
69
|
|
|
$dbCommand = \App\Db::getInstance()->createCommand(); |
70
|
|
|
$query = (new \App\Db\Query())->select(['documentsid'])->from('vtiger_ossmailview_files')->where(['ossmailviewid' => $mailId]); |
71
|
|
|
$dataReader = $query->createCommand()->query(); |
72
|
|
|
while ($documentId = $dataReader->readColumn(0)) { |
73
|
|
|
$dbCommand->insert('vtiger_senotesrel', ['crmid' => $id, 'notesid' => $documentId])->execute(); |
74
|
|
|
} |
75
|
|
|
$dataReader->close(); |
76
|
|
|
unset($dataReader,$query, $dbCommand, $recordModel); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Find service contracts and init data. |
82
|
|
|
* |
83
|
|
|
* @param Vtiger_Record_Model $recordModel |
|
|
|
|
84
|
|
|
* @param int|bool $parentId |
85
|
|
|
* |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
private function loadServiceContracts(\Vtiger_Record_Model $recordModel, $parentId) |
89
|
|
|
{ |
90
|
|
|
if (!$parentId) { |
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
$recordModel->set('parent_id', $parentId); |
94
|
|
|
$queryGenerator = new \App\QueryGenerator('ServiceContracts'); |
95
|
|
|
$queryGenerator->setFields(['id', 'contract_priority']); |
96
|
|
|
$queryGenerator->addNativeCondition(['vtiger_servicecontracts.sc_related_to' => $parentId]); |
97
|
|
|
$queryGenerator->permissions = false; |
98
|
|
|
$queryGenerator->addCondition('contract_status', 'In Progress', 'e'); |
99
|
|
|
$dataReader = $queryGenerator->createQuery()->createCommand()->query(); |
100
|
|
|
if (1 === $dataReader->count()) { |
101
|
|
|
$serviceContracts = $dataReader->read(); |
102
|
|
|
$recordModel->set('servicecontractsid', $serviceContracts['id']); |
103
|
|
|
if (\App\Fields\Picklist::isExists('ticketpriorities', $serviceContracts['contract_priority'])) { |
104
|
|
|
$recordModel->set('ticketpriorities', $serviceContracts['contract_priority']); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
$dataReader->close(); |
108
|
|
|
unset($dataReader, $queryGenerator); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths