@@ -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 | } |
@@ -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 | } |