|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Cron for scheduled import. |
|
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 Tomasz Kur <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* OSSMailScanner_Bind_Cron class. |
|
14
|
|
|
*/ |
|
15
|
|
|
class OSSMailScanner_Bind_Cron extends \App\CronHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** {@inheritdoc} */ |
|
18
|
|
|
public function process() |
|
19
|
|
|
{ |
|
20
|
|
|
$dbCommand = App\Db::getInstance()->createCommand(); |
|
21
|
|
|
$scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner'); |
|
22
|
|
|
$dataReader = (new App\Db\Query())->select([ |
|
23
|
|
|
'vtiger_ossmailview.*', |
|
24
|
|
|
'roundcube_users.actions', |
|
25
|
|
|
])->from('vtiger_ossmailview') |
|
26
|
|
|
->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user')->where(['vtiger_ossmailview.verify' => 1]) |
|
27
|
|
|
->createCommand()->query(); |
|
28
|
|
|
|
|
29
|
|
|
while ($row = $dataReader->read()) { |
|
30
|
|
|
$scannerModel->bindMail($row); |
|
|
|
|
|
|
31
|
|
|
$dbCommand->update('vtiger_ossmailview', ['verify' => 0], ['ossmailviewid' => $row['ossmailviewid']])->execute(); |
|
32
|
|
|
} |
|
33
|
|
|
$dataReader->close(); |
|
34
|
|
|
$dataReader = (new App\Db\Query())->from('s_#__mail_relation_updater')->createCommand()->query(); |
|
35
|
|
|
$bindByEmail = ['Leads', 'Accounts', 'Partners', 'Vendors', 'Competition', 'Contacts', 'OSSEmployees']; |
|
36
|
|
|
$bindByPrefix = ['Campaigns', 'HelpDesk', 'Project', 'SSalesProcesses']; |
|
37
|
|
|
while ($relationRow = $dataReader->read()) { |
|
38
|
|
|
$dbCommand->delete('vtiger_ossmailview_relation', ['crmid' => $relationRow['crmid']])->execute(); |
|
39
|
|
|
$moduleName = \App\Module::getModuleName($relationRow['tabid']); |
|
40
|
|
|
$bind = false; |
|
41
|
|
|
if (\in_array($moduleName, $bindByEmail)) { |
|
42
|
|
|
$bind = 'email'; |
|
43
|
|
|
} |
|
44
|
|
|
if (\in_array($moduleName, $bindByPrefix)) { |
|
45
|
|
|
$bind = 'prefix'; |
|
46
|
|
|
} |
|
47
|
|
|
if (false === $bind) { |
|
48
|
|
|
continue; |
|
49
|
|
|
} |
|
50
|
|
|
$recordModel = Vtiger_Record_Model::getInstanceById($relationRow['crmid'], $moduleName); |
|
51
|
|
|
$where = []; |
|
52
|
|
|
if ('prefix' == $bind) { |
|
53
|
|
|
$recordNumber = $recordModel->getRecordNumber(); |
|
54
|
|
|
if (empty($recordNumber)) { |
|
55
|
|
|
continue; |
|
56
|
|
|
} |
|
57
|
|
|
$where = ['like', 'vtiger_ossmailview.subject', "[{$recordNumber}]"]; |
|
58
|
|
|
} elseif ('email' == $bind) { |
|
59
|
|
|
$where = ['or']; |
|
60
|
|
|
$fieldModels = $recordModel->getModule()->getFieldsByType('email'); |
|
61
|
|
|
foreach ($fieldModels as $fieldName => $fieldModel) { |
|
62
|
|
|
if (!$recordModel->isEmpty($fieldName)) { |
|
63
|
|
|
$email = $recordModel->get($fieldName); |
|
64
|
|
|
$where[] = ['from_email' => $email]; |
|
65
|
|
|
$where[] = ['to_email' => $email]; |
|
66
|
|
|
$where[] = ['cc_email' => $email]; |
|
67
|
|
|
$where[] = ['bcc_email' => $email]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
if (!empty($where) && $where !== ['or']) { |
|
72
|
|
|
$dataReaderMail = (new App\Db\Query())->select(['vtiger_ossmailview.*', 'roundcube_users.actions']) |
|
73
|
|
|
->from('vtiger_ossmailview') |
|
74
|
|
|
->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user') |
|
75
|
|
|
->where($where)->createCommand()->query(); |
|
76
|
|
|
while ($row = $dataReaderMail->read()) { |
|
77
|
|
|
$scannerModel->bindMail($row); |
|
78
|
|
|
} |
|
79
|
|
|
$dataReaderMail->close(); |
|
80
|
|
|
} |
|
81
|
|
|
$dbCommand->delete('s_#__mail_relation_updater', ['crmid' => $relationRow['crmid']])->execute(); |
|
82
|
|
|
if ($this->checkTimeout()) { |
|
83
|
|
|
break; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
$dataReader->close(); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|