@@ -187,7 +187,7 @@ |
||
187 | 187 | $multitype = true; |
188 | 188 | if (self::IGNORE_MODULE === $tabid) { |
189 | 189 | $permittedTabIdList = \App\User::getCurrentUserId() ? \vtlib\Deprecated::getPermittedModuleIdList() : []; |
190 | - $permittedTabIdList[] = 0; // Added to support one link for all modules |
|
190 | + $permittedTabIdList[] = 0; // Added to support one link for all modules |
|
191 | 191 | foreach ($permittedTabIdList as $moduleId) { |
192 | 192 | foreach ($type as $typ) { |
193 | 193 | if (isset($rows[$moduleId][$typ])) { |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader(['index' => $content])); |
471 | 471 | $sandbox = new \Twig\Extension\SandboxExtension(\App\Extension\Twig\SecurityPolicy::getPolicy(), true); |
472 | 472 | $twig->addExtension($sandbox); |
473 | - $twig->addFunction(new \Twig\TwigFunction('YFParser', function ($text) { |
|
473 | + $twig->addFunction(new \Twig\TwigFunction('YFParser', function($text) { |
|
474 | 474 | $value = ''; |
475 | 475 | preg_match(static::VARIABLE_REGEX, $text, $matches); |
476 | 476 | if ($matches) { |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | })); |
482 | 482 | $content = $twig->render('index'); |
483 | 483 | } |
484 | - return preg_replace_callback(static::VARIABLE_REGEX, function ($matches) { |
|
484 | + return preg_replace_callback(static::VARIABLE_REGEX, function($matches) { |
|
485 | 485 | [, $function, $params] = array_pad($matches, 3, ''); |
486 | 486 | return \in_array($function, static::BASE_FUNCTIONS) ? $this->{$function}($params) : ''; |
487 | 487 | }, $content); |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | if (isset($this->language)) { |
498 | 498 | Language::setTemporaryLanguage($this->language); |
499 | 499 | } |
500 | - $this->content = preg_replace_callback('/\$\(translate : ([,"\+\%\.\=\-\[\]\&\w\s\|]+)\)\$/u', function ($matches) { |
|
500 | + $this->content = preg_replace_callback('/\$\(translate : ([,"\+\%\.\=\-\[\]\&\w\s\|]+)\)\$/u', function($matches) { |
|
501 | 501 | [, $params] = array_pad($matches, 2, ''); |
502 | 502 | return $this->translate($params); |
503 | 503 | }, $this->content); |
@@ -1757,7 +1757,7 @@ discard block |
||
1757 | 1757 | $width = isset($config['width']) ? preg_replace('/[^[:alnum:]]/', '', explode(',', $config['width'])) : []; |
1758 | 1758 | foreach ($config['columns'] as $key => $name) { |
1759 | 1759 | if (false !== strpos($name, '||')) { |
1760 | - [$title,$value] = explode('||', $name, 2); |
|
1760 | + [$title, $value] = explode('||', $name, 2); |
|
1761 | 1761 | if ('(' === $title[0] && ')' === substr($title, -1)) { |
1762 | 1762 | $title = $this->parseVariable("\${$title}\$"); |
1763 | 1763 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | switch ($this->get('type')) { |
216 | 216 | case 1: |
217 | 217 | $this->queryGenerator->addNativeCondition([ |
218 | - 'and', ['>=', $columnA, $startFormatted], ['<=', $columnA, $endFormatted] |
|
218 | + 'and', ['>=', $columnA, $startFormatted], ['<=', $columnA, $endFormatted] |
|
219 | 219 | ]); |
220 | 220 | break; |
221 | 221 | case 3: |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | $this->queryGenerator->setField($fieldB->getName()); |
225 | 225 | $this->queryGenerator->addNativeCondition([ |
226 | 226 | 'or', |
227 | - ['and', ['>=', $columnA, $startFormatted], ['<=', $columnA, $endFormatted]], |
|
228 | - ['and', ['>=', $columnB, $startFormatted], ['<=', $columnB, $endFormatted]], |
|
229 | - ['and', ['<', $columnA, $startFormatted], ['>', $columnB, $endFormatted]], |
|
227 | + ['and', ['>=', $columnA, $startFormatted], ['<=', $columnA, $endFormatted]], |
|
228 | + ['and', ['>=', $columnB, $startFormatted], ['<=', $columnB, $endFormatted]], |
|
229 | + ['and', ['<', $columnA, $startFormatted], ['>', $columnB, $endFormatted]], |
|
230 | 230 | ]); |
231 | 231 | break; |
232 | 232 | case 2: |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | 'or', |
238 | 238 | [ |
239 | 239 | 'and', |
240 | - ['>=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $startDateTime], |
|
241 | - ['<=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $endDateTime], |
|
240 | + ['>=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $startDateTime], |
|
241 | + ['<=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $endDateTime], |
|
242 | 242 | ], |
243 | 243 | ]); |
244 | 244 | break; |
@@ -256,16 +256,16 @@ discard block |
||
256 | 256 | 'or', |
257 | 257 | [ |
258 | 258 | 'and', |
259 | - ['>=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $startDateTime], |
|
260 | - ['<=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $endDateTime], |
|
259 | + ['>=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $startDateTime], |
|
260 | + ['<=', new \yii\db\Expression("CONCAT($columnA, ' ', $columnATime)"), $endDateTime], |
|
261 | 261 | ], |
262 | 262 | [ |
263 | 263 | 'and', |
264 | - ['>=', new \yii\db\Expression("CONCAT($columnB, ' ', $columnBTime)"), $startDateTime], |
|
265 | - ['<=', new \yii\db\Expression("CONCAT($columnB, ' ', $columnBTime)"), $endDateTime], |
|
264 | + ['>=', new \yii\db\Expression("CONCAT($columnB, ' ', $columnBTime)"), $startDateTime], |
|
265 | + ['<=', new \yii\db\Expression("CONCAT($columnB, ' ', $columnBTime)"), $endDateTime], |
|
266 | 266 | ], |
267 | 267 | [ |
268 | - 'and', ['<', $columnA, $startDate], ['>', $columnB, $endDate], |
|
268 | + 'and', ['<', $columnA, $startDate], ['>', $columnB, $endDate], |
|
269 | 269 | ], |
270 | 270 | ]); |
271 | 271 | break; |
@@ -464,7 +464,7 @@ |
||
464 | 464 | public function addToQueue(string $type, int $id): void |
465 | 465 | { |
466 | 466 | $data = ['server_id' => $this->config->get('id'), |
467 | - 'name' => $this->name, 'type' => $type, 'value' => $id, |
|
467 | + 'name' => $this->name, 'type' => $type, 'value' => $id, |
|
468 | 468 | ]; |
469 | 469 | $db = \App\Db::getInstance('admin'); |
470 | 470 | if ((new \App\Db\Query())->from(\App\Integrations\Comarch::QUEUE_TABLE_NAME) |
@@ -256,7 +256,7 @@ |
||
256 | 256 | \App\Log::trace("Updated: {$field['tablename']}.{$field['columnname']} |maximumlength: before:{$field['maximumlength']} after: $range |type:{$type}|{$column->type}|{$column->dbType}", __METHOD__); |
257 | 257 | } |
258 | 258 | } |
259 | - return ['NotSupported' => $notSupported, 'TypeNotFound' => $typeNotFound, 'RequiresVerification' => $requiresVerification, 'RequiresVerificationInfo' => $requiresVerificationInfo, 'Updated' => $updated, 'UpdatedInfo' => $updatedInfo]; |
|
259 | + return ['NotSupported' => $notSupported, 'TypeNotFound' => $typeNotFound, 'RequiresVerification' => $requiresVerification, 'RequiresVerificationInfo' => $requiresVerificationInfo, 'Updated' => $updated, 'UpdatedInfo' => $updatedInfo]; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'appVersion' => '6.4.259', |
|
5 | - 'patchVersion' => '2023.07.10', |
|
6 | - 'lib_roundcube' => '0.3.4', |
|
4 | + 'appVersion' => '6.4.259', |
|
5 | + 'patchVersion' => '2023.07.10', |
|
6 | + 'lib_roundcube' => '0.3.4', |
|
7 | 7 | ]; |
@@ -17,41 +17,41 @@ |
||
17 | 17 | */ |
18 | 18 | class Comarch extends \App\SystemWarnings\Template |
19 | 19 | { |
20 | - /** {@inheritdoc} */ |
|
21 | - protected $title = 'LBL_CHECK_COMARCH_INTEGRATION_LOG'; |
|
20 | + /** {@inheritdoc} */ |
|
21 | + protected $title = 'LBL_CHECK_COMARCH_INTEGRATION_LOG'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Checks for suspended email accounts. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function process(): void |
|
29 | - { |
|
30 | - $db = \App\DB::getInstance('log'); |
|
31 | - if(!$db->isTableExists(\App\Integrations\Comarch::LOG_TABLE_NAME)) { |
|
32 | - $this->status = 1; |
|
33 | - return; |
|
34 | - } |
|
35 | - $data = (new \App\Db\Query())->select(['time', 'message'])->from(\App\Integrations\Comarch::LOG_TABLE_NAME) |
|
36 | - ->where([ |
|
37 | - 'and', |
|
38 | - ['error' => 1], |
|
39 | - ['>=', 'time', date('Y-m-d H:i:s', strtotime('-24 hours'))] |
|
40 | - ])->orderBy(['id' => SORT_DESC]) |
|
41 | - ->all($db); |
|
42 | - if ($data) { |
|
43 | - $this->status = 0; |
|
44 | - $this->description = \App\Language::translate('LBL_CHECK_COMARCH_INTEGRATION_LOG_DESC', 'Settings:SystemWarnings'); |
|
45 | - $this->description .= '<br>' . \App\TextUtils::getHtmlTable($data, [ |
|
46 | - 'time' => \App\Language::translate('LBL_TIME', 'Settings:Log'), |
|
47 | - 'message' => \App\Language::translate('LBL_MESSAGE', 'Settings:Comarch') |
|
48 | - ]); |
|
49 | - if (\App\Security\AdminAccess::isPermitted('Log')) { |
|
50 | - $this->link = 'index.php?parent=Settings&module=Log&view=LogsViewer&type=mail'; |
|
51 | - $this->linkTitle = \App\Language::translate('LBL_LOGS_VIEWER', 'Settings:Log'); |
|
52 | - } |
|
53 | - } else { |
|
54 | - $this->status = 1; |
|
55 | - } |
|
56 | - } |
|
23 | + /** |
|
24 | + * Checks for suspended email accounts. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function process(): void |
|
29 | + { |
|
30 | + $db = \App\DB::getInstance('log'); |
|
31 | + if(!$db->isTableExists(\App\Integrations\Comarch::LOG_TABLE_NAME)) { |
|
32 | + $this->status = 1; |
|
33 | + return; |
|
34 | + } |
|
35 | + $data = (new \App\Db\Query())->select(['time', 'message'])->from(\App\Integrations\Comarch::LOG_TABLE_NAME) |
|
36 | + ->where([ |
|
37 | + 'and', |
|
38 | + ['error' => 1], |
|
39 | + ['>=', 'time', date('Y-m-d H:i:s', strtotime('-24 hours'))] |
|
40 | + ])->orderBy(['id' => SORT_DESC]) |
|
41 | + ->all($db); |
|
42 | + if ($data) { |
|
43 | + $this->status = 0; |
|
44 | + $this->description = \App\Language::translate('LBL_CHECK_COMARCH_INTEGRATION_LOG_DESC', 'Settings:SystemWarnings'); |
|
45 | + $this->description .= '<br>' . \App\TextUtils::getHtmlTable($data, [ |
|
46 | + 'time' => \App\Language::translate('LBL_TIME', 'Settings:Log'), |
|
47 | + 'message' => \App\Language::translate('LBL_MESSAGE', 'Settings:Comarch') |
|
48 | + ]); |
|
49 | + if (\App\Security\AdminAccess::isPermitted('Log')) { |
|
50 | + $this->link = 'index.php?parent=Settings&module=Log&view=LogsViewer&type=mail'; |
|
51 | + $this->linkTitle = \App\Language::translate('LBL_LOGS_VIEWER', 'Settings:Log'); |
|
52 | + } |
|
53 | + } else { |
|
54 | + $this->status = 1; |
|
55 | + } |
|
56 | + } |
|
57 | 57 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | public function process(): void |
29 | 29 | { |
30 | 30 | $db = \App\DB::getInstance('log'); |
31 | - if(!$db->isTableExists(\App\Integrations\Comarch::LOG_TABLE_NAME)) { |
|
31 | + if (!$db->isTableExists(\App\Integrations\Comarch::LOG_TABLE_NAME)) { |
|
32 | 32 | $this->status = 1; |
33 | 33 | return; |
34 | 34 | } |
@@ -22,196 +22,196 @@ |
||
22 | 22 | */ |
23 | 23 | class Config extends \App\Base |
24 | 24 | { |
25 | - /** |
|
26 | - * Get all servers. |
|
27 | - * |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - public static function getAllServers(): array |
|
31 | - { |
|
32 | - if (\App\Cache::has('Comarch|getAllServers', '')) { |
|
33 | - return \App\Cache::get('Comarch|getAllServers', ''); |
|
34 | - } |
|
35 | - $servers = []; |
|
36 | - $dataReader = (new Query())->from(Comarch::TABLE_NAME)->where(['status' => 1]) |
|
37 | - ->createCommand(\App\Db::getInstance('admin'))->query(); |
|
38 | - while ($row = $dataReader->read()) { |
|
39 | - $row['password'] = \App\Encryption::getInstance()->decrypt($row['password']); |
|
40 | - $servers[$row['id']] = $row; |
|
41 | - } |
|
42 | - $dataReader->close(); |
|
43 | - \App\Cache::save('Comarch|getAllServers', '', $servers); |
|
44 | - return $servers; |
|
45 | - } |
|
25 | + /** |
|
26 | + * Get all servers. |
|
27 | + * |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + public static function getAllServers(): array |
|
31 | + { |
|
32 | + if (\App\Cache::has('Comarch|getAllServers', '')) { |
|
33 | + return \App\Cache::get('Comarch|getAllServers', ''); |
|
34 | + } |
|
35 | + $servers = []; |
|
36 | + $dataReader = (new Query())->from(Comarch::TABLE_NAME)->where(['status' => 1]) |
|
37 | + ->createCommand(\App\Db::getInstance('admin'))->query(); |
|
38 | + while ($row = $dataReader->read()) { |
|
39 | + $row['password'] = \App\Encryption::getInstance()->decrypt($row['password']); |
|
40 | + $servers[$row['id']] = $row; |
|
41 | + } |
|
42 | + $dataReader->close(); |
|
43 | + \App\Cache::save('Comarch|getAllServers', '', $servers); |
|
44 | + return $servers; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get server configuration by id. |
|
49 | - * |
|
50 | - * @param int $id |
|
51 | - * |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public static function getServer(int $id): array |
|
55 | - { |
|
56 | - $servers = self::getAllServers(); |
|
57 | - if (empty($servers[$id])) { |
|
58 | - throw new \App\Exceptions\AppException('Comarch Server not found: ' . $id); |
|
59 | - } |
|
60 | - $server = $servers[$id]; |
|
61 | - if (!empty($server['attributes'])) { |
|
62 | - $server['attributes'] = \App\Json::decode($server['attributes']); |
|
63 | - } |
|
64 | - return $server; |
|
65 | - } |
|
47 | + /** |
|
48 | + * Get server configuration by id. |
|
49 | + * |
|
50 | + * @param int $id |
|
51 | + * |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public static function getServer(int $id): array |
|
55 | + { |
|
56 | + $servers = self::getAllServers(); |
|
57 | + if (empty($servers[$id])) { |
|
58 | + throw new \App\Exceptions\AppException('Comarch Server not found: ' . $id); |
|
59 | + } |
|
60 | + $server = $servers[$id]; |
|
61 | + if (!empty($server['attributes'])) { |
|
62 | + $server['attributes'] = \App\Json::decode($server['attributes']); |
|
63 | + } |
|
64 | + return $server; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Function to get object to read configuration. |
|
69 | - * |
|
70 | - * @param int $serverId |
|
71 | - * |
|
72 | - * @return self |
|
73 | - */ |
|
74 | - public static function getInstance(int $serverId): self |
|
75 | - { |
|
76 | - $db = \App\Db::getInstance('admin'); |
|
77 | - $instance = new self(); |
|
78 | - $instance->setData( |
|
79 | - array_merge( |
|
80 | - self::getServer($serverId), |
|
81 | - \App\Config::component('IntegrationComarch', null, []), |
|
82 | - (new Query())->select(['name', 'value'])->from(Comarch::CONFIG_TABLE_NAME) |
|
83 | - ->where(['server_id' => $serverId]) |
|
84 | - ->createCommand($db)->queryAllByGroup(), |
|
85 | - [ |
|
86 | - 'maps' => (new Query())->select(['map', 'class'])->from(Comarch::MAP_TABLE_NAME) |
|
87 | - ->where(['server_id' => $serverId]) |
|
88 | - ->createCommand($db)->queryAllByGroup() |
|
89 | - ] |
|
90 | - ), |
|
91 | - ); |
|
92 | - return $instance; |
|
93 | - } |
|
67 | + /** |
|
68 | + * Function to get object to read configuration. |
|
69 | + * |
|
70 | + * @param int $serverId |
|
71 | + * |
|
72 | + * @return self |
|
73 | + */ |
|
74 | + public static function getInstance(int $serverId): self |
|
75 | + { |
|
76 | + $db = \App\Db::getInstance('admin'); |
|
77 | + $instance = new self(); |
|
78 | + $instance->setData( |
|
79 | + array_merge( |
|
80 | + self::getServer($serverId), |
|
81 | + \App\Config::component('IntegrationComarch', null, []), |
|
82 | + (new Query())->select(['name', 'value'])->from(Comarch::CONFIG_TABLE_NAME) |
|
83 | + ->where(['server_id' => $serverId]) |
|
84 | + ->createCommand($db)->queryAllByGroup(), |
|
85 | + [ |
|
86 | + 'maps' => (new Query())->select(['map', 'class'])->from(Comarch::MAP_TABLE_NAME) |
|
87 | + ->where(['server_id' => $serverId]) |
|
88 | + ->createCommand($db)->queryAllByGroup() |
|
89 | + ] |
|
90 | + ), |
|
91 | + ); |
|
92 | + return $instance; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Save in db last scanned id. |
|
97 | - * |
|
98 | - * @param string $type |
|
99 | - * @param string|null $name |
|
100 | - * @param int|null $id |
|
101 | - * |
|
102 | - * @throws \yii\db\Exception |
|
103 | - */ |
|
104 | - public function setScan(string $type, ?string $name = null, ?int $id = null): void |
|
105 | - { |
|
106 | - $dbCommand = \App\Db::getInstance('admin')->createCommand(); |
|
107 | - if (null !== $name) { |
|
108 | - $data = ['name' => "{$type}_last_{$name}", 'value' => $id]; |
|
109 | - } else { |
|
110 | - $data = ['name' => $type . '_start_date', 'value' => date('Y-m-d H:i:s')]; |
|
111 | - } |
|
112 | - if (!(new Query())->from(Comarch::CONFIG_TABLE_NAME) |
|
113 | - ->where(['server_id' => $this->get('id'), 'name' => $data['name']])->exists()) { |
|
114 | - $data['server_id'] = $this->get('id'); |
|
115 | - $dbCommand->insert(Comarch::CONFIG_TABLE_NAME, $data)->execute(); |
|
116 | - } |
|
117 | - $dbCommand->update( |
|
118 | - Comarch::CONFIG_TABLE_NAME, |
|
119 | - $data, |
|
120 | - ['server_id' => $this->get('id'), 'name' => $data['name']] |
|
121 | - )->execute(); |
|
122 | - $this->set($data['name'], $data['value']); |
|
123 | - } |
|
95 | + /** |
|
96 | + * Save in db last scanned id. |
|
97 | + * |
|
98 | + * @param string $type |
|
99 | + * @param string|null $name |
|
100 | + * @param int|null $id |
|
101 | + * |
|
102 | + * @throws \yii\db\Exception |
|
103 | + */ |
|
104 | + public function setScan(string $type, ?string $name = null, ?int $id = null): void |
|
105 | + { |
|
106 | + $dbCommand = \App\Db::getInstance('admin')->createCommand(); |
|
107 | + if (null !== $name) { |
|
108 | + $data = ['name' => "{$type}_last_{$name}", 'value' => $id]; |
|
109 | + } else { |
|
110 | + $data = ['name' => $type . '_start_date', 'value' => date('Y-m-d H:i:s')]; |
|
111 | + } |
|
112 | + if (!(new Query())->from(Comarch::CONFIG_TABLE_NAME) |
|
113 | + ->where(['server_id' => $this->get('id'), 'name' => $data['name']])->exists()) { |
|
114 | + $data['server_id'] = $this->get('id'); |
|
115 | + $dbCommand->insert(Comarch::CONFIG_TABLE_NAME, $data)->execute(); |
|
116 | + } |
|
117 | + $dbCommand->update( |
|
118 | + Comarch::CONFIG_TABLE_NAME, |
|
119 | + $data, |
|
120 | + ['server_id' => $this->get('id'), 'name' => $data['name']] |
|
121 | + )->execute(); |
|
122 | + $this->set($data['name'], $data['value']); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Set end scan. |
|
127 | - * |
|
128 | - * @param string $type |
|
129 | - * @param string $date |
|
130 | - * |
|
131 | - * @throws \yii\db\Exception |
|
132 | - */ |
|
133 | - public function setEndScan(string $type, string $date): void |
|
134 | - { |
|
135 | - $dbCommand = \App\Db::getInstance('admin')->createCommand(); |
|
136 | - if (!$date) { |
|
137 | - $date = date('Y-m-d H:i:s'); |
|
138 | - } |
|
139 | - $saveData = [ |
|
140 | - [ |
|
141 | - 'name' => $type . '_end_date', |
|
142 | - 'value' => $date, |
|
143 | - ], [ |
|
144 | - 'name' => $type . '_last_id', |
|
145 | - 'value' => 0, |
|
146 | - ], [ |
|
147 | - 'name' => $type . '_last_page', |
|
148 | - 'value' => null, |
|
149 | - ], |
|
150 | - ]; |
|
151 | - foreach ($saveData as $data) { |
|
152 | - if (!(new Query())->from(Comarch::CONFIG_TABLE_NAME) |
|
153 | - ->where(['server_id' => $this->get('id'), 'name' => $data['name']])->exists()) { |
|
154 | - $data['server_id'] = $this->get('id'); |
|
155 | - $dbCommand->insert(Comarch::CONFIG_TABLE_NAME, $data)->execute(); |
|
156 | - } else { |
|
157 | - $dbCommand->update( |
|
158 | - Comarch::CONFIG_TABLE_NAME, |
|
159 | - $data, |
|
160 | - ['server_id' => $this->get('id'), 'name' => $data['name']] |
|
161 | - )->execute(); |
|
162 | - } |
|
163 | - $this->set($data['name'], $data['value']); |
|
164 | - } |
|
165 | - } |
|
125 | + /** |
|
126 | + * Set end scan. |
|
127 | + * |
|
128 | + * @param string $type |
|
129 | + * @param string $date |
|
130 | + * |
|
131 | + * @throws \yii\db\Exception |
|
132 | + */ |
|
133 | + public function setEndScan(string $type, string $date): void |
|
134 | + { |
|
135 | + $dbCommand = \App\Db::getInstance('admin')->createCommand(); |
|
136 | + if (!$date) { |
|
137 | + $date = date('Y-m-d H:i:s'); |
|
138 | + } |
|
139 | + $saveData = [ |
|
140 | + [ |
|
141 | + 'name' => $type . '_end_date', |
|
142 | + 'value' => $date, |
|
143 | + ], [ |
|
144 | + 'name' => $type . '_last_id', |
|
145 | + 'value' => 0, |
|
146 | + ], [ |
|
147 | + 'name' => $type . '_last_page', |
|
148 | + 'value' => null, |
|
149 | + ], |
|
150 | + ]; |
|
151 | + foreach ($saveData as $data) { |
|
152 | + if (!(new Query())->from(Comarch::CONFIG_TABLE_NAME) |
|
153 | + ->where(['server_id' => $this->get('id'), 'name' => $data['name']])->exists()) { |
|
154 | + $data['server_id'] = $this->get('id'); |
|
155 | + $dbCommand->insert(Comarch::CONFIG_TABLE_NAME, $data)->execute(); |
|
156 | + } else { |
|
157 | + $dbCommand->update( |
|
158 | + Comarch::CONFIG_TABLE_NAME, |
|
159 | + $data, |
|
160 | + ['server_id' => $this->get('id'), 'name' => $data['name']] |
|
161 | + )->execute(); |
|
162 | + } |
|
163 | + $this->set($data['name'], $data['value']); |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Get last scan information. |
|
169 | - * |
|
170 | - * @param string $type |
|
171 | - * |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - public function getLastScan(string $type): array |
|
175 | - { |
|
176 | - return [ |
|
177 | - 'id' => (int) $this->get($type . '_last_id') ?? 0, |
|
178 | - 'page' => $this->get($type . '_last_page') ?: null, |
|
179 | - 'start_date' => $this->get($type . '_start_date') ?? false, |
|
180 | - 'end_date' => $this->get($type . '_end_date') ?? false, |
|
181 | - ]; |
|
182 | - } |
|
167 | + /** |
|
168 | + * Get last scan information. |
|
169 | + * |
|
170 | + * @param string $type |
|
171 | + * |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + public function getLastScan(string $type): array |
|
175 | + { |
|
176 | + return [ |
|
177 | + 'id' => (int) $this->get($type . '_last_id') ?? 0, |
|
178 | + 'page' => $this->get($type . '_last_page') ?: null, |
|
179 | + 'start_date' => $this->get($type . '_start_date') ?? false, |
|
180 | + 'end_date' => $this->get($type . '_end_date') ?? false, |
|
181 | + ]; |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Reload integration with Comarch. |
|
186 | - * |
|
187 | - * @param int $id |
|
188 | - * |
|
189 | - * @return void |
|
190 | - */ |
|
191 | - public static function reload(int $id): void |
|
192 | - { |
|
193 | - \App\Db::getInstance('admin')->createCommand() |
|
194 | - ->delete(Comarch::CONFIG_TABLE_NAME, ['server_id' => $id]) |
|
195 | - ->execute(); |
|
196 | - } |
|
184 | + /** |
|
185 | + * Reload integration with Comarch. |
|
186 | + * |
|
187 | + * @param int $id |
|
188 | + * |
|
189 | + * @return void |
|
190 | + */ |
|
191 | + public static function reload(int $id): void |
|
192 | + { |
|
193 | + \App\Db::getInstance('admin')->createCommand() |
|
194 | + ->delete(Comarch::CONFIG_TABLE_NAME, ['server_id' => $id]) |
|
195 | + ->execute(); |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Get available connectors. |
|
200 | - * |
|
201 | - * @return string[] |
|
202 | - */ |
|
203 | - public static function getConnectors(): array |
|
204 | - { |
|
205 | - $connectors = []; |
|
206 | - $iterator = new \DirectoryIterator(__DIR__ . '/Connector'); |
|
207 | - foreach ($iterator as $item) { |
|
208 | - if ($item->isFile() && 'Base.php' !== $item->getFilename() && 'php' === $item->getExtension() |
|
209 | - ) { |
|
210 | - $name = $item->getBasename('.php'); |
|
211 | - $className = '\\App\\Integrations\\Comarch\\Connector\\' . $name; |
|
212 | - $connectors[$name] = $className::NAME; |
|
213 | - } |
|
214 | - } |
|
215 | - return $connectors; |
|
216 | - } |
|
198 | + /** |
|
199 | + * Get available connectors. |
|
200 | + * |
|
201 | + * @return string[] |
|
202 | + */ |
|
203 | + public static function getConnectors(): array |
|
204 | + { |
|
205 | + $connectors = []; |
|
206 | + $iterator = new \DirectoryIterator(__DIR__ . '/Connector'); |
|
207 | + foreach ($iterator as $item) { |
|
208 | + if ($item->isFile() && 'Base.php' !== $item->getFilename() && 'php' === $item->getExtension() |
|
209 | + ) { |
|
210 | + $name = $item->getBasename('.php'); |
|
211 | + $className = '\\App\\Integrations\\Comarch\\Connector\\' . $name; |
|
212 | + $connectors[$name] = $className::NAME; |
|
213 | + } |
|
214 | + } |
|
215 | + return $connectors; |
|
216 | + } |
|
217 | 217 | } |
@@ -105,7 +105,7 @@ |
||
105 | 105 | { |
106 | 106 | $dbCommand = \App\Db::getInstance('admin')->createCommand(); |
107 | 107 | if (null !== $name) { |
108 | - $data = ['name' => "{$type}_last_{$name}", 'value' => $id]; |
|
108 | + $data = ['name' => "{$type}_last_{$name}", 'value' => $id]; |
|
109 | 109 | } else { |
110 | 110 | $data = ['name' => $type . '_start_date', 'value' => date('Y-m-d H:i:s')]; |
111 | 111 | } |