Passed
Pull Request — developer (#16238)
by Arkadiusz
20:05 queued 01:05
created

VTRecordCollector::doTask()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 21
rs 9.1111
cc 6
nc 10
nop 1
1
<?php
2
/**
3
 * Record collectors task file.
4
 *
5
 * @package 	WorkflowTask
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Arkadiusz Sołek <[email protected]>
10
 */
11
/**
12
 * Record collectors task class.
13
 */
14
require_once 'modules/com_vtiger_workflow/VTWorkflowUtils.php';
15
16
class VTRecordCollector extends VTTask
17
{
18
	/** @var bool Performs the task immediately after saving. */
19
	public $executeImmediately = true;
20
21
	/** {@inheritdoc} */
22
	public function getFieldNames()
23
	{
24
		return ['recordCollector'];
25
	}
26
27
	/** {@inheritdoc} */
28
	public function doTask($recordModel)
29
	{
30
		$moduleName = $recordModel->getModuleName();
31
		$value = [];
32
		$value['module'] = $moduleName;
33
		if (!empty($this->recordCollector)) {
34
			$recordCollector = \App\RecordCollector::getInstance('\App\RecordCollectors\\' . $this->recordCollector, $moduleName);
0 ignored issues
show
Bug Best Practice introduced by
The property recordCollector does not exist on VTRecordCollector. Did you maybe forget to declare it?
Loading history...
35
			foreach ($recordCollector->modulesFieldsMap[$moduleName] as $key => $searchField) {
0 ignored issues
show
Bug introduced by
The property modulesFieldsMap is declared protected in App\RecordCollectors\Base and cannot be accessed from this context.
Loading history...
36
				if ('' !== $recordModel->get($searchField)) {
37
					$value[$key] = $recordModel->get($searchField);
38
					break;
39
				}
40
			}
41
			if (!empty($value)) {
42
				$recordCollector->setRequest(new \App\Request($value, false));
43
				$response = $recordCollector->search();
44
				foreach ($response['fields'] as $fieldName => $values) {
45
					$recordModel->set($fieldName, $values['data'][0]['raw']);
46
				}
47
				$recordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);
48
				$recordModel->save();
49
			}
50
		}
51
	}
52
}
53