@@ -20,113 +20,113 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class InfluxdbRepository |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * The database driver. |
|
| 25 | - * |
|
| 26 | - * @var Client |
|
| 27 | - * @since 1.3.0 |
|
| 28 | - */ |
|
| 29 | - private $db; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Instantiate the repository. |
|
| 33 | - * |
|
| 34 | - * @param Client $db The database driver. |
|
| 35 | - */ |
|
| 36 | - public function __construct(Client $db) |
|
| 37 | - { |
|
| 38 | - $this->db = $db; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Saves the given data. |
|
| 43 | - * |
|
| 44 | - * @param \stdClass $data Data object to save. |
|
| 45 | - * |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - public function save(\stdClass $data): void |
|
| 49 | - { |
|
| 50 | - $writeApi = $this->db->createWriteApi(); |
|
| 51 | - |
|
| 52 | - // Set the modified date of the record |
|
| 53 | - $timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp(); |
|
| 54 | - |
|
| 55 | - $point = Point::measurement('joomla') |
|
| 56 | - ->addTag('unique_id', $data->unique_id) |
|
| 57 | - ->time($timestamp); |
|
| 58 | - |
|
| 59 | - // Extract major and minor version |
|
| 60 | - if (!empty($data->php_version)) { |
|
| 61 | - preg_match('/^(\d+)\.(\d+)\./', $data->php_version, $phpVersion); |
|
| 62 | - $point->addField('php_version', $data->php_version); |
|
| 63 | - if (!empty($phpVersion)) { |
|
| 64 | - $point->addField('php_major', $phpVersion[1]) |
|
| 65 | - ->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - // Prepare CMS version |
|
| 70 | - if (!empty($data->cms_version)) { |
|
| 71 | - preg_match('/^(\d+)\.(\d+)\./', $data->cms_version, $cmsVersions); |
|
| 72 | - |
|
| 73 | - $point->addField('cms_version', $data->cms_version); |
|
| 74 | - if (!empty($cmsVersions)) { |
|
| 75 | - $point |
|
| 76 | - ->addField('cms_major', $cmsVersions[1]) |
|
| 77 | - ->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // Prepare Database versions |
|
| 82 | - if (!empty($data->db_version)) { |
|
| 83 | - preg_match('/^(\d+)\.(\d+)\./', $data->db_version, $dbVersions); |
|
| 84 | - |
|
| 85 | - $point->addField('db_version', $data->db_version); |
|
| 86 | - if (!empty($dbVersions)) { |
|
| 87 | - $point->addField('db_major', $dbVersions[1]) |
|
| 88 | - ->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Prepare Database Driver |
|
| 93 | - if (!empty($data->db_type)) { |
|
| 94 | - $dbServer = null; |
|
| 95 | - if ($data->db_type === 'postgresql') { |
|
| 96 | - $dbServer = 'PostgreSQL'; |
|
| 97 | - } elseif (str_contains($data->db_type, 'mysql')) { |
|
| 98 | - $dbServer = 'MySQL'; |
|
| 99 | - if (!empty($data->db_version)) { |
|
| 100 | - if ( |
|
| 101 | - version_compare($data->db_version, '10.0.0', '>=') |
|
| 102 | - // We know this is not 100% correct but more accurate than expecting MySQL with this version string |
|
| 103 | - || version_compare($data->db_version, '5.5.5', '=') |
|
| 104 | - ) { |
|
| 105 | - $dbServer = 'MariaDB'; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } elseif (str_contains($data->db_type, 'mariadb')) { |
|
| 109 | - $dbServer = 'MariaDB'; |
|
| 110 | - } elseif (str_contains($data->db_type, 'sqlsrv')) { |
|
| 111 | - $dbServer = 'MSSQL'; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $point->addField('db_driver', $data->db_type); |
|
| 115 | - if (!empty($dbServer)) { |
|
| 116 | - $point->addField('db_server', $dbServer); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // Prepare Operating System |
|
| 121 | - if (!empty($data->server_os)) { |
|
| 122 | - $os = explode(' ', $data->server_os, 2); |
|
| 123 | - |
|
| 124 | - $point->addField('server_string', $data->server_os); |
|
| 125 | - if (!empty($os[0])) { |
|
| 126 | - $point->addField('server_os', $os[0]); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms'); |
|
| 131 | - } |
|
| 23 | + /** |
|
| 24 | + * The database driver. |
|
| 25 | + * |
|
| 26 | + * @var Client |
|
| 27 | + * @since 1.3.0 |
|
| 28 | + */ |
|
| 29 | + private $db; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Instantiate the repository. |
|
| 33 | + * |
|
| 34 | + * @param Client $db The database driver. |
|
| 35 | + */ |
|
| 36 | + public function __construct(Client $db) |
|
| 37 | + { |
|
| 38 | + $this->db = $db; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Saves the given data. |
|
| 43 | + * |
|
| 44 | + * @param \stdClass $data Data object to save. |
|
| 45 | + * |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + public function save(\stdClass $data): void |
|
| 49 | + { |
|
| 50 | + $writeApi = $this->db->createWriteApi(); |
|
| 51 | + |
|
| 52 | + // Set the modified date of the record |
|
| 53 | + $timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp(); |
|
| 54 | + |
|
| 55 | + $point = Point::measurement('joomla') |
|
| 56 | + ->addTag('unique_id', $data->unique_id) |
|
| 57 | + ->time($timestamp); |
|
| 58 | + |
|
| 59 | + // Extract major and minor version |
|
| 60 | + if (!empty($data->php_version)) { |
|
| 61 | + preg_match('/^(\d+)\.(\d+)\./', $data->php_version, $phpVersion); |
|
| 62 | + $point->addField('php_version', $data->php_version); |
|
| 63 | + if (!empty($phpVersion)) { |
|
| 64 | + $point->addField('php_major', $phpVersion[1]) |
|
| 65 | + ->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + // Prepare CMS version |
|
| 70 | + if (!empty($data->cms_version)) { |
|
| 71 | + preg_match('/^(\d+)\.(\d+)\./', $data->cms_version, $cmsVersions); |
|
| 72 | + |
|
| 73 | + $point->addField('cms_version', $data->cms_version); |
|
| 74 | + if (!empty($cmsVersions)) { |
|
| 75 | + $point |
|
| 76 | + ->addField('cms_major', $cmsVersions[1]) |
|
| 77 | + ->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // Prepare Database versions |
|
| 82 | + if (!empty($data->db_version)) { |
|
| 83 | + preg_match('/^(\d+)\.(\d+)\./', $data->db_version, $dbVersions); |
|
| 84 | + |
|
| 85 | + $point->addField('db_version', $data->db_version); |
|
| 86 | + if (!empty($dbVersions)) { |
|
| 87 | + $point->addField('db_major', $dbVersions[1]) |
|
| 88 | + ->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Prepare Database Driver |
|
| 93 | + if (!empty($data->db_type)) { |
|
| 94 | + $dbServer = null; |
|
| 95 | + if ($data->db_type === 'postgresql') { |
|
| 96 | + $dbServer = 'PostgreSQL'; |
|
| 97 | + } elseif (str_contains($data->db_type, 'mysql')) { |
|
| 98 | + $dbServer = 'MySQL'; |
|
| 99 | + if (!empty($data->db_version)) { |
|
| 100 | + if ( |
|
| 101 | + version_compare($data->db_version, '10.0.0', '>=') |
|
| 102 | + // We know this is not 100% correct but more accurate than expecting MySQL with this version string |
|
| 103 | + || version_compare($data->db_version, '5.5.5', '=') |
|
| 104 | + ) { |
|
| 105 | + $dbServer = 'MariaDB'; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } elseif (str_contains($data->db_type, 'mariadb')) { |
|
| 109 | + $dbServer = 'MariaDB'; |
|
| 110 | + } elseif (str_contains($data->db_type, 'sqlsrv')) { |
|
| 111 | + $dbServer = 'MSSQL'; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $point->addField('db_driver', $data->db_type); |
|
| 115 | + if (!empty($dbServer)) { |
|
| 116 | + $point->addField('db_server', $dbServer); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // Prepare Operating System |
|
| 121 | + if (!empty($data->server_os)) { |
|
| 122 | + $os = explode(' ', $data->server_os, 2); |
|
| 123 | + |
|
| 124 | + $point->addField('server_string', $data->server_os); |
|
| 125 | + if (!empty($os[0])) { |
|
| 126 | + $point->addField('server_os', $os[0]); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms'); |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -21,44 +21,44 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class RepositoryServiceProvider implements ServiceProviderInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Registers the service provider with a DI container. |
|
| 26 | - * |
|
| 27 | - * @param Container $container The DI container. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function register(Container $container): void |
|
| 32 | - { |
|
| 33 | - $container->share(StatisticsRepository::class, [$this, 'getStatisticsRepositoryService']); |
|
| 34 | - $container->share(InfluxdbRepository::class, [$this, 'getInfluxdbRepositoryService']); |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * Registers the service provider with a DI container. |
|
| 26 | + * |
|
| 27 | + * @param Container $container The DI container. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function register(Container $container): void |
|
| 32 | + { |
|
| 33 | + $container->share(StatisticsRepository::class, [$this, 'getStatisticsRepositoryService']); |
|
| 34 | + $container->share(InfluxdbRepository::class, [$this, 'getInfluxdbRepositoryService']); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Get the StatisticsRepository service |
|
| 39 | - * |
|
| 40 | - * @param Container $container The DI container. |
|
| 41 | - * |
|
| 42 | - * @return StatisticsRepository |
|
| 43 | - */ |
|
| 44 | - public function getStatisticsRepositoryService(Container $container): StatisticsRepository |
|
| 45 | - { |
|
| 46 | - return new StatisticsRepository( |
|
| 47 | - $container->get(DatabaseInterface::class) |
|
| 48 | - ); |
|
| 49 | - } |
|
| 37 | + /** |
|
| 38 | + * Get the StatisticsRepository service |
|
| 39 | + * |
|
| 40 | + * @param Container $container The DI container. |
|
| 41 | + * |
|
| 42 | + * @return StatisticsRepository |
|
| 43 | + */ |
|
| 44 | + public function getStatisticsRepositoryService(Container $container): StatisticsRepository |
|
| 45 | + { |
|
| 46 | + return new StatisticsRepository( |
|
| 47 | + $container->get(DatabaseInterface::class) |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Get the StatisticsRepository service |
|
| 53 | - * |
|
| 54 | - * @param Container $container The DI container. |
|
| 55 | - * |
|
| 56 | - * @return StatisticsRepository |
|
| 57 | - */ |
|
| 58 | - public function getInfluxdbRepositoryService(Container $container): InfluxdbRepository |
|
| 59 | - { |
|
| 60 | - return new InfluxdbRepository( |
|
| 61 | - $container->get(Client::class) |
|
| 62 | - ); |
|
| 63 | - } |
|
| 51 | + /** |
|
| 52 | + * Get the StatisticsRepository service |
|
| 53 | + * |
|
| 54 | + * @param Container $container The DI container. |
|
| 55 | + * |
|
| 56 | + * @return StatisticsRepository |
|
| 57 | + */ |
|
| 58 | + public function getInfluxdbRepositoryService(Container $container): InfluxdbRepository |
|
| 59 | + { |
|
| 60 | + return new InfluxdbRepository( |
|
| 61 | + $container->get(Client::class) |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | 64 | } |