Passed
Pull Request — developer (#17179)
by Mariusz
29:27 queued 10:21
created

Vtiger_Comarch_Cron   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 18
dl 0
loc 25
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 22 8
1
<?php
2
/**
3
 * Integration Comarch cron file.
4
 *
5
 * @package   Cron
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Mariusz Krzaczkowski <[email protected]>
10
 */
11
12
/**
13
 * Integration Comarch cron class.
14
 */
15
class Vtiger_Comarch_Cron extends \App\CronHandler
16
{
17
	/** {@inheritdoc} */
18
	public function process()
19
	{
20
		$bathCallback = fn (): bool => $this->checkTimeout() ? false : true;
21
		foreach (App\Integrations\Comarch\Config::getAllServers() as $serverId => $config) {
22
			if (0 == $config['status']) {
23
				continue;
24
			}
25
			$this->updateLastActionTime();
26
			$connector = (new App\Integrations\Comarch($serverId, $bathCallback));
27
			if ($message = $connector->testConnection()) {
28
				$this->addErrorLog($message);
29
				continue;
30
			}
31
			foreach ([
32
				'sync_accounts' => 'Accounts',
33
				'sync_products' => 'Products',
34
			] as $key => $value) {
35
				if ($connector->config->get($key)) {
36
					$connector->getSync($value)->process();
37
				}
38
				if ($this->checkTimeout()) {
39
					return;
40
				}
41
			}
42
		}
43
	}
44
}
45