Conditions | 15 |
Paths | 114 |
Total Lines | 69 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | } |
||
89 |