@@ -32,112 +32,112 @@ |
||
32 | 32 | */ |
33 | 33 | abstract class Kernel implements ContainerAwareInterface |
34 | 34 | { |
35 | - use ContainerAwareTrait; |
|
36 | - |
|
37 | - /** |
|
38 | - * Flag indicating this Kernel has been booted |
|
39 | - * |
|
40 | - * @var boolean |
|
41 | - */ |
|
42 | - protected $booted = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * Boot the Kernel |
|
46 | - * |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - public function boot(): void |
|
50 | - { |
|
51 | - if ($this->booted) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - $this->setContainer($this->buildContainer()); |
|
56 | - |
|
57 | - // Register deprecation logging via Monolog |
|
58 | - ErrorHandler::register($this->getContainer()->get(Logger::class), [E_DEPRECATED, E_USER_DEPRECATED], false, false); |
|
59 | - |
|
60 | - $this->booted = true; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Check if the Kernel is booted |
|
65 | - * |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function isBooted(): bool |
|
69 | - { |
|
70 | - return $this->booted; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Run the kernel |
|
75 | - * |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function run(): void |
|
79 | - { |
|
80 | - $this->boot(); |
|
81 | - |
|
82 | - if (!$this->getContainer()->has(AbstractApplication::class)) { |
|
83 | - throw new \RuntimeException('The application has not been registered with the container.'); |
|
84 | - } |
|
85 | - |
|
86 | - $this->getContainer()->get(AbstractApplication::class)->execute(); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Build the service container |
|
91 | - * |
|
92 | - * @return Container |
|
93 | - */ |
|
94 | - protected function buildContainer(): Container |
|
95 | - { |
|
96 | - $config = $this->loadConfiguration(); |
|
97 | - |
|
98 | - $container = new Container(); |
|
99 | - $container->share('config', $config); |
|
100 | - |
|
101 | - $container->registerServiceProvider(new AnalyticsServiceProvider()) |
|
102 | - ->registerServiceProvider(new ConsoleServiceProvider()) |
|
103 | - ->registerServiceProvider(new DatabaseProvider()) |
|
104 | - ->registerServiceProvider(new DatabaseServiceProvider()) |
|
105 | - ->registerServiceProvider(new EventServiceProvider()) |
|
106 | - ->registerServiceProvider(new FlysystemServiceProvider()) |
|
107 | - ->registerServiceProvider(new GitHubServiceProvider()) |
|
108 | - ->registerServiceProvider(new MonologServiceProvider()) |
|
109 | - ->registerServiceProvider(new RepositoryServiceProvider()) |
|
110 | - ->registerServiceProvider(new WebApplicationServiceProvider()); |
|
111 | - |
|
112 | - $container->share( |
|
113 | - \InfluxDB2\Client::class, |
|
114 | - function (Container $container) { |
|
115 | - /** @var \Joomla\Registry\Registry $config */ |
|
116 | - $config = $container->get('config'); |
|
117 | - $options = (array) $config->get('influxdb'); |
|
118 | - |
|
119 | - return new \InfluxDB2\Client($options); |
|
120 | - } |
|
121 | - ); |
|
122 | - |
|
123 | - |
|
124 | - return $container; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Load the application's configuration |
|
129 | - * |
|
130 | - * @return Registry |
|
131 | - */ |
|
132 | - private function loadConfiguration(): Registry |
|
133 | - { |
|
134 | - $registry = new Registry(); |
|
135 | - $registry->loadFile(APPROOT . '/etc/config.dist.json'); |
|
136 | - |
|
137 | - if (file_exists(APPROOT . '/etc/config.json')) { |
|
138 | - $registry->loadFile(APPROOT . '/etc/config.json'); |
|
139 | - } |
|
140 | - |
|
141 | - return $registry; |
|
142 | - } |
|
35 | + use ContainerAwareTrait; |
|
36 | + |
|
37 | + /** |
|
38 | + * Flag indicating this Kernel has been booted |
|
39 | + * |
|
40 | + * @var boolean |
|
41 | + */ |
|
42 | + protected $booted = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * Boot the Kernel |
|
46 | + * |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + public function boot(): void |
|
50 | + { |
|
51 | + if ($this->booted) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + $this->setContainer($this->buildContainer()); |
|
56 | + |
|
57 | + // Register deprecation logging via Monolog |
|
58 | + ErrorHandler::register($this->getContainer()->get(Logger::class), [E_DEPRECATED, E_USER_DEPRECATED], false, false); |
|
59 | + |
|
60 | + $this->booted = true; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Check if the Kernel is booted |
|
65 | + * |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function isBooted(): bool |
|
69 | + { |
|
70 | + return $this->booted; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Run the kernel |
|
75 | + * |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function run(): void |
|
79 | + { |
|
80 | + $this->boot(); |
|
81 | + |
|
82 | + if (!$this->getContainer()->has(AbstractApplication::class)) { |
|
83 | + throw new \RuntimeException('The application has not been registered with the container.'); |
|
84 | + } |
|
85 | + |
|
86 | + $this->getContainer()->get(AbstractApplication::class)->execute(); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Build the service container |
|
91 | + * |
|
92 | + * @return Container |
|
93 | + */ |
|
94 | + protected function buildContainer(): Container |
|
95 | + { |
|
96 | + $config = $this->loadConfiguration(); |
|
97 | + |
|
98 | + $container = new Container(); |
|
99 | + $container->share('config', $config); |
|
100 | + |
|
101 | + $container->registerServiceProvider(new AnalyticsServiceProvider()) |
|
102 | + ->registerServiceProvider(new ConsoleServiceProvider()) |
|
103 | + ->registerServiceProvider(new DatabaseProvider()) |
|
104 | + ->registerServiceProvider(new DatabaseServiceProvider()) |
|
105 | + ->registerServiceProvider(new EventServiceProvider()) |
|
106 | + ->registerServiceProvider(new FlysystemServiceProvider()) |
|
107 | + ->registerServiceProvider(new GitHubServiceProvider()) |
|
108 | + ->registerServiceProvider(new MonologServiceProvider()) |
|
109 | + ->registerServiceProvider(new RepositoryServiceProvider()) |
|
110 | + ->registerServiceProvider(new WebApplicationServiceProvider()); |
|
111 | + |
|
112 | + $container->share( |
|
113 | + \InfluxDB2\Client::class, |
|
114 | + function (Container $container) { |
|
115 | + /** @var \Joomla\Registry\Registry $config */ |
|
116 | + $config = $container->get('config'); |
|
117 | + $options = (array) $config->get('influxdb'); |
|
118 | + |
|
119 | + return new \InfluxDB2\Client($options); |
|
120 | + } |
|
121 | + ); |
|
122 | + |
|
123 | + |
|
124 | + return $container; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Load the application's configuration |
|
129 | + * |
|
130 | + * @return Registry |
|
131 | + */ |
|
132 | + private function loadConfiguration(): Registry |
|
133 | + { |
|
134 | + $registry = new Registry(); |
|
135 | + $registry->loadFile(APPROOT . '/etc/config.dist.json'); |
|
136 | + |
|
137 | + if (file_exists(APPROOT . '/etc/config.json')) { |
|
138 | + $registry->loadFile(APPROOT . '/etc/config.json'); |
|
139 | + } |
|
140 | + |
|
141 | + return $registry; |
|
142 | + } |
|
143 | 143 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | $container->share( |
113 | 113 | \InfluxDB2\Client::class, |
114 | - function (Container $container) { |
|
114 | + function(Container $container) { |
|
115 | 115 | /** @var \Joomla\Registry\Registry $config */ |
116 | 116 | $config = $container->get('config'); |
117 | 117 | $options = (array) $config->get('influxdb'); |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | private function loadConfiguration(): Registry |
133 | 133 | { |
134 | 134 | $registry = new Registry(); |
135 | - $registry->loadFile(APPROOT . '/etc/config.dist.json'); |
|
135 | + $registry->loadFile(APPROOT.'/etc/config.dist.json'); |
|
136 | 136 | |
137 | - if (file_exists(APPROOT . '/etc/config.json')) { |
|
138 | - $registry->loadFile(APPROOT . '/etc/config.json'); |
|
137 | + if (file_exists(APPROOT.'/etc/config.json')) { |
|
138 | + $registry->loadFile(APPROOT.'/etc/config.json'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | return $registry; |
@@ -17,192 +17,192 @@ |
||
17 | 17 | */ |
18 | 18 | class StatisticsRepository |
19 | 19 | { |
20 | - /** |
|
21 | - * Array containing the allowed sources |
|
22 | - * |
|
23 | - * @var string[] |
|
24 | - */ |
|
25 | - public const ALLOWED_SOURCES = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version']; |
|
26 | - |
|
27 | - /** |
|
28 | - * The database driver. |
|
29 | - * |
|
30 | - * @var DatabaseInterface |
|
31 | - * @since 1.3.0 |
|
32 | - */ |
|
33 | - private $db; |
|
34 | - |
|
35 | - /** |
|
36 | - * Instantiate the repository. |
|
37 | - * |
|
38 | - * @param DatabaseInterface $db The database driver. |
|
39 | - */ |
|
40 | - public function __construct(DatabaseInterface $db) |
|
41 | - { |
|
42 | - $this->db = $db; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Loads the statistics data from the database. |
|
47 | - * |
|
48 | - * @param string $column A single column to filter on |
|
49 | - * |
|
50 | - * @return array An array containing the response data |
|
51 | - * |
|
52 | - * @throws \InvalidArgumentException |
|
53 | - */ |
|
54 | - public function getItems(string $column = ''): array |
|
55 | - { |
|
56 | - // Validate the requested column is actually in the table |
|
57 | - if ($column !== '') { |
|
58 | - // The column should exist in the table and be part of the API |
|
59 | - if (!\in_array($column, self::ALLOWED_SOURCES)) { |
|
60 | - throw new \InvalidArgumentException('An invalid data source was requested.', 404); |
|
61 | - } |
|
62 | - |
|
63 | - return $this->db->setQuery( |
|
64 | - $this->db->getQuery(true) |
|
65 | - ->select('*') |
|
66 | - ->from($this->db->quoteName('#__jstats_counter_' . $column)) |
|
67 | - )->loadAssocList(); |
|
68 | - } |
|
69 | - |
|
70 | - $return = []; |
|
71 | - |
|
72 | - foreach (self::ALLOWED_SOURCES as $column) { |
|
73 | - $return[$column] = $this->db->setQuery( |
|
74 | - $this->db->getQuery(true) |
|
75 | - ->select('*') |
|
76 | - ->from($this->db->quoteName('#__jstats_counter_' . $column)) |
|
77 | - )->loadAssocList(); |
|
78 | - } |
|
79 | - |
|
80 | - return $return; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Loads the recently updated statistics data from the database. |
|
85 | - * |
|
86 | - * Recently updated is an arbitrary 90 days, submit a pull request for a different behavior. |
|
87 | - * |
|
88 | - * @return array An array containing the response data |
|
89 | - */ |
|
90 | - public function getRecentlyUpdatedItems(): array |
|
91 | - { |
|
92 | - $return = []; |
|
93 | - $db = $this->db; |
|
94 | - |
|
95 | - foreach (self::ALLOWED_SOURCES as $column) { |
|
96 | - if (($column !== 'cms_php_version') && ($column !== 'db_type_version')) { |
|
97 | - $return[$column] = $this->db->setQuery( |
|
98 | - $this->db->getQuery(true) |
|
99 | - ->select($column) |
|
100 | - ->select('COUNT(' . $column . ') AS count') |
|
101 | - ->from($this->db->quoteName('#__jstats')) |
|
102 | - ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
|
103 | - ->group($column) |
|
104 | - )->loadAssocList(); |
|
105 | - continue; |
|
106 | - } |
|
107 | - |
|
108 | - if ($column === 'cms_php_version') { |
|
109 | - $return['cms_php_version'] = $this->db->setQuery( |
|
110 | - $this->db->getQuery(true) |
|
111 | - ->select('CONCAT(' . $db->qn('cms_version') . ', ' . $db->q(' - ') . ', ' . $db->qn('php_version') . ') AS cms_php_version') |
|
112 | - ->select('COUNT(*) AS count') |
|
113 | - ->from($this->db->quoteName('#__jstats')) |
|
114 | - ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
|
115 | - ->group('CONCAT(' . $db->qn('cms_version') . ', ' . $db->q(' - ') . ', ' . $db->qn('php_version') . ')') |
|
116 | - )->loadAssocList(); |
|
117 | - continue; |
|
118 | - } |
|
119 | - |
|
120 | - if ($column === 'db_type_version') { |
|
121 | - $return['db_type_version'] = $this->db->setQuery( |
|
122 | - $this->db->getQuery(true) |
|
123 | - ->select('CONCAT(' . $db->qn('db_type') . ', ' . $db->q(' - ') . ', ' . $db->qn('db_version') . ') AS db_type_version') |
|
124 | - ->select('COUNT(*) AS count') |
|
125 | - ->from($this->db->quoteName('#__jstats')) |
|
126 | - ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
|
127 | - ->group('CONCAT(' . $db->qn('db_type') . ', ' . $db->q(' - ') . ', ' . $db->qn('db_version') . ')') |
|
128 | - )->loadAssocList(); |
|
129 | - continue; |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - return $return; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Loads the recently updated statistics data from the database. |
|
138 | - * |
|
139 | - * Updated within a timeframe, submit a pull request for a different behavior. |
|
140 | - * |
|
141 | - * @param int $timeframe The timeframe in days to consider |
|
142 | - * @param string $showColumn The column to return |
|
143 | - * |
|
144 | - * @return array An array containing the response data |
|
145 | - */ |
|
146 | - public function getTimeframeUpdatedItems(int $timeframe = 0, string $showColumn = ''): array |
|
147 | - { |
|
148 | - $return = []; |
|
149 | - $columns = self::ALLOWED_SOURCES; |
|
150 | - |
|
151 | - if ($showColumn !== '') { |
|
152 | - // The column should exist in the table and be part of the API |
|
153 | - if (!\in_array($showColumn, self::ALLOWED_SOURCES)) { |
|
154 | - throw new \InvalidArgumentException('An invalid data source was requested.', 404); |
|
155 | - } |
|
156 | - |
|
157 | - $columns = [$showColumn]; |
|
158 | - } |
|
159 | - |
|
160 | - foreach ($columns as $column) { |
|
161 | - if (\in_array($column, ['cms_php_version', 'db_type_version'])) { |
|
162 | - continue; |
|
163 | - } |
|
164 | - |
|
165 | - $return[$column] = $this->db->setQuery( |
|
166 | - $this->db->getQuery(true) |
|
167 | - ->select($column) |
|
168 | - ->select('COUNT(' . $column . ') AS count') |
|
169 | - ->from('(SELECT * FROM ' . $this->db->quoteName('#__jstats') |
|
170 | - . ' WHERE modified > DATE_SUB(NOW(), INTERVAL ' . $this->db->quote($timeframe) . ' DAY)) AS tmptable') |
|
171 | - ->group($column) |
|
172 | - )->loadAssocList(); |
|
173 | - } |
|
174 | - |
|
175 | - if ($showColumn !== '') { |
|
176 | - return $return[$showColumn]; |
|
177 | - } |
|
178 | - |
|
179 | - return $return; |
|
180 | - } |
|
181 | - /** |
|
182 | - * Saves the given data. |
|
183 | - * |
|
184 | - * @param \stdClass $data Data object to save. |
|
185 | - * |
|
186 | - * @return void |
|
187 | - */ |
|
188 | - public function save(\stdClass $data): void |
|
189 | - { |
|
190 | - // Set the modified date of the record |
|
191 | - $data->modified = (new \DateTime('now', new \DateTimeZone('UTC')))->format($this->db->getDateFormat()); |
|
192 | - |
|
193 | - // Check if a row exists for this unique ID and update the existing record if so |
|
194 | - $recordExists = $this->db->setQuery( |
|
195 | - $this->db->getQuery(true) |
|
196 | - ->select('unique_id') |
|
197 | - ->from('#__jstats') |
|
198 | - ->where('unique_id = :unique_id') |
|
199 | - ->bind(':unique_id', $data->unique_id, ParameterType::STRING) |
|
200 | - )->loadResult(); |
|
201 | - |
|
202 | - if ($recordExists) { |
|
203 | - $this->db->updateObject('#__jstats', $data, ['unique_id']); |
|
204 | - } else { |
|
205 | - $this->db->insertObject('#__jstats', $data, ['unique_id']); |
|
206 | - } |
|
207 | - } |
|
20 | + /** |
|
21 | + * Array containing the allowed sources |
|
22 | + * |
|
23 | + * @var string[] |
|
24 | + */ |
|
25 | + public const ALLOWED_SOURCES = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version']; |
|
26 | + |
|
27 | + /** |
|
28 | + * The database driver. |
|
29 | + * |
|
30 | + * @var DatabaseInterface |
|
31 | + * @since 1.3.0 |
|
32 | + */ |
|
33 | + private $db; |
|
34 | + |
|
35 | + /** |
|
36 | + * Instantiate the repository. |
|
37 | + * |
|
38 | + * @param DatabaseInterface $db The database driver. |
|
39 | + */ |
|
40 | + public function __construct(DatabaseInterface $db) |
|
41 | + { |
|
42 | + $this->db = $db; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Loads the statistics data from the database. |
|
47 | + * |
|
48 | + * @param string $column A single column to filter on |
|
49 | + * |
|
50 | + * @return array An array containing the response data |
|
51 | + * |
|
52 | + * @throws \InvalidArgumentException |
|
53 | + */ |
|
54 | + public function getItems(string $column = ''): array |
|
55 | + { |
|
56 | + // Validate the requested column is actually in the table |
|
57 | + if ($column !== '') { |
|
58 | + // The column should exist in the table and be part of the API |
|
59 | + if (!\in_array($column, self::ALLOWED_SOURCES)) { |
|
60 | + throw new \InvalidArgumentException('An invalid data source was requested.', 404); |
|
61 | + } |
|
62 | + |
|
63 | + return $this->db->setQuery( |
|
64 | + $this->db->getQuery(true) |
|
65 | + ->select('*') |
|
66 | + ->from($this->db->quoteName('#__jstats_counter_' . $column)) |
|
67 | + )->loadAssocList(); |
|
68 | + } |
|
69 | + |
|
70 | + $return = []; |
|
71 | + |
|
72 | + foreach (self::ALLOWED_SOURCES as $column) { |
|
73 | + $return[$column] = $this->db->setQuery( |
|
74 | + $this->db->getQuery(true) |
|
75 | + ->select('*') |
|
76 | + ->from($this->db->quoteName('#__jstats_counter_' . $column)) |
|
77 | + )->loadAssocList(); |
|
78 | + } |
|
79 | + |
|
80 | + return $return; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Loads the recently updated statistics data from the database. |
|
85 | + * |
|
86 | + * Recently updated is an arbitrary 90 days, submit a pull request for a different behavior. |
|
87 | + * |
|
88 | + * @return array An array containing the response data |
|
89 | + */ |
|
90 | + public function getRecentlyUpdatedItems(): array |
|
91 | + { |
|
92 | + $return = []; |
|
93 | + $db = $this->db; |
|
94 | + |
|
95 | + foreach (self::ALLOWED_SOURCES as $column) { |
|
96 | + if (($column !== 'cms_php_version') && ($column !== 'db_type_version')) { |
|
97 | + $return[$column] = $this->db->setQuery( |
|
98 | + $this->db->getQuery(true) |
|
99 | + ->select($column) |
|
100 | + ->select('COUNT(' . $column . ') AS count') |
|
101 | + ->from($this->db->quoteName('#__jstats')) |
|
102 | + ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
|
103 | + ->group($column) |
|
104 | + )->loadAssocList(); |
|
105 | + continue; |
|
106 | + } |
|
107 | + |
|
108 | + if ($column === 'cms_php_version') { |
|
109 | + $return['cms_php_version'] = $this->db->setQuery( |
|
110 | + $this->db->getQuery(true) |
|
111 | + ->select('CONCAT(' . $db->qn('cms_version') . ', ' . $db->q(' - ') . ', ' . $db->qn('php_version') . ') AS cms_php_version') |
|
112 | + ->select('COUNT(*) AS count') |
|
113 | + ->from($this->db->quoteName('#__jstats')) |
|
114 | + ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
|
115 | + ->group('CONCAT(' . $db->qn('cms_version') . ', ' . $db->q(' - ') . ', ' . $db->qn('php_version') . ')') |
|
116 | + )->loadAssocList(); |
|
117 | + continue; |
|
118 | + } |
|
119 | + |
|
120 | + if ($column === 'db_type_version') { |
|
121 | + $return['db_type_version'] = $this->db->setQuery( |
|
122 | + $this->db->getQuery(true) |
|
123 | + ->select('CONCAT(' . $db->qn('db_type') . ', ' . $db->q(' - ') . ', ' . $db->qn('db_version') . ') AS db_type_version') |
|
124 | + ->select('COUNT(*) AS count') |
|
125 | + ->from($this->db->quoteName('#__jstats')) |
|
126 | + ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
|
127 | + ->group('CONCAT(' . $db->qn('db_type') . ', ' . $db->q(' - ') . ', ' . $db->qn('db_version') . ')') |
|
128 | + )->loadAssocList(); |
|
129 | + continue; |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + return $return; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Loads the recently updated statistics data from the database. |
|
138 | + * |
|
139 | + * Updated within a timeframe, submit a pull request for a different behavior. |
|
140 | + * |
|
141 | + * @param int $timeframe The timeframe in days to consider |
|
142 | + * @param string $showColumn The column to return |
|
143 | + * |
|
144 | + * @return array An array containing the response data |
|
145 | + */ |
|
146 | + public function getTimeframeUpdatedItems(int $timeframe = 0, string $showColumn = ''): array |
|
147 | + { |
|
148 | + $return = []; |
|
149 | + $columns = self::ALLOWED_SOURCES; |
|
150 | + |
|
151 | + if ($showColumn !== '') { |
|
152 | + // The column should exist in the table and be part of the API |
|
153 | + if (!\in_array($showColumn, self::ALLOWED_SOURCES)) { |
|
154 | + throw new \InvalidArgumentException('An invalid data source was requested.', 404); |
|
155 | + } |
|
156 | + |
|
157 | + $columns = [$showColumn]; |
|
158 | + } |
|
159 | + |
|
160 | + foreach ($columns as $column) { |
|
161 | + if (\in_array($column, ['cms_php_version', 'db_type_version'])) { |
|
162 | + continue; |
|
163 | + } |
|
164 | + |
|
165 | + $return[$column] = $this->db->setQuery( |
|
166 | + $this->db->getQuery(true) |
|
167 | + ->select($column) |
|
168 | + ->select('COUNT(' . $column . ') AS count') |
|
169 | + ->from('(SELECT * FROM ' . $this->db->quoteName('#__jstats') |
|
170 | + . ' WHERE modified > DATE_SUB(NOW(), INTERVAL ' . $this->db->quote($timeframe) . ' DAY)) AS tmptable') |
|
171 | + ->group($column) |
|
172 | + )->loadAssocList(); |
|
173 | + } |
|
174 | + |
|
175 | + if ($showColumn !== '') { |
|
176 | + return $return[$showColumn]; |
|
177 | + } |
|
178 | + |
|
179 | + return $return; |
|
180 | + } |
|
181 | + /** |
|
182 | + * Saves the given data. |
|
183 | + * |
|
184 | + * @param \stdClass $data Data object to save. |
|
185 | + * |
|
186 | + * @return void |
|
187 | + */ |
|
188 | + public function save(\stdClass $data): void |
|
189 | + { |
|
190 | + // Set the modified date of the record |
|
191 | + $data->modified = (new \DateTime('now', new \DateTimeZone('UTC')))->format($this->db->getDateFormat()); |
|
192 | + |
|
193 | + // Check if a row exists for this unique ID and update the existing record if so |
|
194 | + $recordExists = $this->db->setQuery( |
|
195 | + $this->db->getQuery(true) |
|
196 | + ->select('unique_id') |
|
197 | + ->from('#__jstats') |
|
198 | + ->where('unique_id = :unique_id') |
|
199 | + ->bind(':unique_id', $data->unique_id, ParameterType::STRING) |
|
200 | + )->loadResult(); |
|
201 | + |
|
202 | + if ($recordExists) { |
|
203 | + $this->db->updateObject('#__jstats', $data, ['unique_id']); |
|
204 | + } else { |
|
205 | + $this->db->insertObject('#__jstats', $data, ['unique_id']); |
|
206 | + } |
|
207 | + } |
|
208 | 208 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | return $this->db->setQuery( |
64 | 64 | $this->db->getQuery(true) |
65 | 65 | ->select('*') |
66 | - ->from($this->db->quoteName('#__jstats_counter_' . $column)) |
|
66 | + ->from($this->db->quoteName('#__jstats_counter_'.$column)) |
|
67 | 67 | )->loadAssocList(); |
68 | 68 | } |
69 | 69 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $return[$column] = $this->db->setQuery( |
74 | 74 | $this->db->getQuery(true) |
75 | 75 | ->select('*') |
76 | - ->from($this->db->quoteName('#__jstats_counter_' . $column)) |
|
76 | + ->from($this->db->quoteName('#__jstats_counter_'.$column)) |
|
77 | 77 | )->loadAssocList(); |
78 | 78 | } |
79 | 79 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $return[$column] = $this->db->setQuery( |
98 | 98 | $this->db->getQuery(true) |
99 | 99 | ->select($column) |
100 | - ->select('COUNT(' . $column . ') AS count') |
|
100 | + ->select('COUNT('.$column.') AS count') |
|
101 | 101 | ->from($this->db->quoteName('#__jstats')) |
102 | 102 | ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
103 | 103 | ->group($column) |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | if ($column === 'cms_php_version') { |
109 | 109 | $return['cms_php_version'] = $this->db->setQuery( |
110 | 110 | $this->db->getQuery(true) |
111 | - ->select('CONCAT(' . $db->qn('cms_version') . ', ' . $db->q(' - ') . ', ' . $db->qn('php_version') . ') AS cms_php_version') |
|
111 | + ->select('CONCAT('.$db->qn('cms_version').', '.$db->q(' - ').', '.$db->qn('php_version').') AS cms_php_version') |
|
112 | 112 | ->select('COUNT(*) AS count') |
113 | 113 | ->from($this->db->quoteName('#__jstats')) |
114 | 114 | ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
115 | - ->group('CONCAT(' . $db->qn('cms_version') . ', ' . $db->q(' - ') . ', ' . $db->qn('php_version') . ')') |
|
115 | + ->group('CONCAT('.$db->qn('cms_version').', '.$db->q(' - ').', '.$db->qn('php_version').')') |
|
116 | 116 | )->loadAssocList(); |
117 | 117 | continue; |
118 | 118 | } |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | if ($column === 'db_type_version') { |
121 | 121 | $return['db_type_version'] = $this->db->setQuery( |
122 | 122 | $this->db->getQuery(true) |
123 | - ->select('CONCAT(' . $db->qn('db_type') . ', ' . $db->q(' - ') . ', ' . $db->qn('db_version') . ') AS db_type_version') |
|
123 | + ->select('CONCAT('.$db->qn('db_type').', '.$db->q(' - ').', '.$db->qn('db_version').') AS db_type_version') |
|
124 | 124 | ->select('COUNT(*) AS count') |
125 | 125 | ->from($this->db->quoteName('#__jstats')) |
126 | 126 | ->where('modified BETWEEN DATE_SUB(NOW(), INTERVAL 90 DAY) AND NOW()') |
127 | - ->group('CONCAT(' . $db->qn('db_type') . ', ' . $db->q(' - ') . ', ' . $db->qn('db_version') . ')') |
|
127 | + ->group('CONCAT('.$db->qn('db_type').', '.$db->q(' - ').', '.$db->qn('db_version').')') |
|
128 | 128 | )->loadAssocList(); |
129 | 129 | continue; |
130 | 130 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | $return[$column] = $this->db->setQuery( |
166 | 166 | $this->db->getQuery(true) |
167 | 167 | ->select($column) |
168 | - ->select('COUNT(' . $column . ') AS count') |
|
169 | - ->from('(SELECT * FROM ' . $this->db->quoteName('#__jstats') |
|
170 | - . ' WHERE modified > DATE_SUB(NOW(), INTERVAL ' . $this->db->quote($timeframe) . ' DAY)) AS tmptable') |
|
168 | + ->select('COUNT('.$column.') AS count') |
|
169 | + ->from('(SELECT * FROM '.$this->db->quoteName('#__jstats') |
|
170 | + . ' WHERE modified > DATE_SUB(NOW(), INTERVAL '.$this->db->quote($timeframe).' DAY)) AS tmptable') |
|
171 | 171 | ->group($column) |
172 | 172 | )->loadAssocList(); |
173 | 173 | } |
@@ -21,28 +21,28 @@ |
||
21 | 21 | */ |
22 | 22 | class WebKernel extends Kernel |
23 | 23 | { |
24 | - /** |
|
25 | - * Build the service container |
|
26 | - * |
|
27 | - * @return Container |
|
28 | - */ |
|
29 | - protected function buildContainer(): Container |
|
30 | - { |
|
31 | - $container = parent::buildContainer(); |
|
32 | - |
|
33 | - // Alias the web application to Joomla's base application class as this is the primary application for the environment |
|
34 | - $container->alias(AbstractApplication::class, AbstractWebApplication::class); |
|
35 | - |
|
36 | - // Alias the web application logger as the primary logger for the environment |
|
37 | - $container->alias('monolog', 'monolog.logger.application') |
|
38 | - ->alias('logger', 'monolog.logger.application') |
|
39 | - ->alias(Logger::class, 'monolog.logger.application') |
|
40 | - ->alias(LoggerInterface::class, 'monolog.logger.application'); |
|
41 | - |
|
42 | - // Set error reporting based on config |
|
43 | - $errorReporting = (int) $container->get('config')->get('errorReporting', 0); |
|
44 | - error_reporting($errorReporting); |
|
45 | - |
|
46 | - return $container; |
|
47 | - } |
|
24 | + /** |
|
25 | + * Build the service container |
|
26 | + * |
|
27 | + * @return Container |
|
28 | + */ |
|
29 | + protected function buildContainer(): Container |
|
30 | + { |
|
31 | + $container = parent::buildContainer(); |
|
32 | + |
|
33 | + // Alias the web application to Joomla's base application class as this is the primary application for the environment |
|
34 | + $container->alias(AbstractApplication::class, AbstractWebApplication::class); |
|
35 | + |
|
36 | + // Alias the web application logger as the primary logger for the environment |
|
37 | + $container->alias('monolog', 'monolog.logger.application') |
|
38 | + ->alias('logger', 'monolog.logger.application') |
|
39 | + ->alias(Logger::class, 'monolog.logger.application') |
|
40 | + ->alias(LoggerInterface::class, 'monolog.logger.application'); |
|
41 | + |
|
42 | + // Set error reporting based on config |
|
43 | + $errorReporting = (int) $container->get('config')->get('errorReporting', 0); |
|
44 | + error_reporting($errorReporting); |
|
45 | + |
|
46 | + return $container; |
|
47 | + } |
|
48 | 48 | } |
@@ -21,28 +21,28 @@ |
||
21 | 21 | */ |
22 | 22 | class ConsoleKernel extends Kernel |
23 | 23 | { |
24 | - /** |
|
25 | - * Build the service container |
|
26 | - * |
|
27 | - * @return Container |
|
28 | - */ |
|
29 | - protected function buildContainer(): Container |
|
30 | - { |
|
31 | - $container = parent::buildContainer(); |
|
32 | - |
|
33 | - // Alias the web application to Joomla's base application class as this is the primary application for the environment |
|
34 | - $container->alias(AbstractApplication::class, Application::class); |
|
35 | - |
|
36 | - // Alias the web application logger as the primary logger for the environment |
|
37 | - $container->alias('monolog', 'monolog.logger.cli') |
|
38 | - ->alias('logger', 'monolog.logger.cli') |
|
39 | - ->alias(Logger::class, 'monolog.logger.cli') |
|
40 | - ->alias(LoggerInterface::class, 'monolog.logger.cli'); |
|
41 | - |
|
42 | - // Set error reporting based on config |
|
43 | - $errorReporting = (int) $container->get('config')->get('errorReporting', 0); |
|
44 | - error_reporting($errorReporting); |
|
45 | - |
|
46 | - return $container; |
|
47 | - } |
|
24 | + /** |
|
25 | + * Build the service container |
|
26 | + * |
|
27 | + * @return Container |
|
28 | + */ |
|
29 | + protected function buildContainer(): Container |
|
30 | + { |
|
31 | + $container = parent::buildContainer(); |
|
32 | + |
|
33 | + // Alias the web application to Joomla's base application class as this is the primary application for the environment |
|
34 | + $container->alias(AbstractApplication::class, Application::class); |
|
35 | + |
|
36 | + // Alias the web application logger as the primary logger for the environment |
|
37 | + $container->alias('monolog', 'monolog.logger.cli') |
|
38 | + ->alias('logger', 'monolog.logger.cli') |
|
39 | + ->alias(Logger::class, 'monolog.logger.cli') |
|
40 | + ->alias(LoggerInterface::class, 'monolog.logger.cli'); |
|
41 | + |
|
42 | + // Set error reporting based on config |
|
43 | + $errorReporting = (int) $container->get('config')->get('errorReporting', 0); |
|
44 | + error_reporting($errorReporting); |
|
45 | + |
|
46 | + return $container; |
|
47 | + } |
|
48 | 48 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $point->addField('php_version', $data->php_version); |
69 | 69 | if (!empty($phpVersion)) { |
70 | 70 | $point->addField('php_major', $phpVersion[1]) |
71 | - ->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]); |
|
71 | + ->addField('php_minor', $phpVersion[1].'.'.$phpVersion[2]); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | if (!empty($cmsVersions)) { |
81 | 81 | $point |
82 | 82 | ->addField('cms_major', $cmsVersions[1]) |
83 | - ->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]); |
|
83 | + ->addField('cms_minor', $cmsVersions[1].'.'.$cmsVersions[2]); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $point->addField('db_version', $data->db_version); |
92 | 92 | if (!empty($dbVersions)) { |
93 | 93 | $point->addField('db_major', $dbVersions[1]) |
94 | - ->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]); |
|
94 | + ->addField('db_minor', $dbVersions[1].'.'.$dbVersions[2]); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 |
@@ -19,120 +19,120 @@ |
||
19 | 19 | */ |
20 | 20 | class InfluxdbRepository |
21 | 21 | { |
22 | - /** |
|
23 | - * Array containing the allowed sources |
|
24 | - * |
|
25 | - * @var string[] |
|
26 | - */ |
|
27 | - public const ALLOWED_SOURCES = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version']; |
|
28 | - |
|
29 | - /** |
|
30 | - * The database driver. |
|
31 | - * |
|
32 | - * @var DatabaseInterface |
|
33 | - * @since 1.3.0 |
|
34 | - */ |
|
35 | - private $db; |
|
36 | - |
|
37 | - /** |
|
38 | - * Instantiate the repository. |
|
39 | - * |
|
40 | - * @param DatabaseInterface $db The database driver. |
|
41 | - */ |
|
42 | - public function __construct(DatabaseInterface $db) |
|
43 | - { |
|
44 | - $this->db = $db; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Saves the given data. |
|
49 | - * |
|
50 | - * @param \stdClass $data Data object to save. |
|
51 | - * |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function save(\stdClass $data): void |
|
55 | - { |
|
56 | - $writeApi = $this->db->createWriteApi(); |
|
57 | - |
|
58 | - // Set the modified date of the record |
|
59 | - $timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp(); |
|
60 | - |
|
61 | - $point = Point::measurement('joomla') |
|
62 | - ->addTag('unique_id', $data->unique_id) |
|
63 | - ->time($timestamp); |
|
64 | - |
|
65 | - // Extract major and minor version |
|
66 | - if (!empty($data->php_version)) { |
|
67 | - preg_match('/^(\d+)\.(\d+)\./', $data->php_version, $phpVersion); |
|
68 | - $point->addField('php_version', $data->php_version); |
|
69 | - if (!empty($phpVersion)) { |
|
70 | - $point->addField('php_major', $phpVersion[1]) |
|
71 | - ->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - // Prepare CMS version |
|
76 | - if (!empty($data->cms_version)) { |
|
77 | - preg_match('/^(\d+)\.(\d+)\./', $data->cms_version, $cmsVersions); |
|
78 | - |
|
79 | - $point->addField('cms_version', $data->cms_version); |
|
80 | - if (!empty($cmsVersions)) { |
|
81 | - $point |
|
82 | - ->addField('cms_major', $cmsVersions[1]) |
|
83 | - ->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - // Prepare Database versions |
|
88 | - if (!empty($data->db_version)) { |
|
89 | - preg_match('/^(\d+)\.(\d+)\./', $data->db_version, $dbVersions); |
|
90 | - |
|
91 | - $point->addField('db_version', $data->db_version); |
|
92 | - if (!empty($dbVersions)) { |
|
93 | - $point->addField('db_major', $dbVersions[1]) |
|
94 | - ->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]); |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - // Prepare Database Driver |
|
99 | - if (!empty($data->db_type)) { |
|
100 | - $dbServer = null; |
|
101 | - if ($data->db_type === 'postgresql') { |
|
102 | - $dbServer = 'PostgreSQL'; |
|
103 | - } elseif (str_contains($data->db_type, 'mysql')) { |
|
104 | - $dbServer = 'MySQL'; |
|
105 | - if (!empty($data->db_version)) { |
|
106 | - if ( |
|
107 | - version_compare($data->db_version, '10.0.0', '>=') |
|
108 | - // We know this is not 100% correct but more accurate than expecting MySQL with this version string |
|
109 | - || version_compare($data->db_version, '5.5.5', '=') |
|
110 | - ) { |
|
111 | - $dbServer = 'MariaDB'; |
|
112 | - } |
|
113 | - } |
|
114 | - } elseif (str_contains($data->db_type, 'mariadb')) { |
|
115 | - $dbServer = 'MariaDB'; |
|
116 | - } elseif (str_contains($data->db_type, 'sqlsrv')) { |
|
117 | - $dbServer = 'MSSQL'; |
|
118 | - } |
|
119 | - |
|
120 | - $point->addField('db_driver', $data->db_type); |
|
121 | - if (!empty($dbServer)) { |
|
122 | - $point->addField('db_server', $dbServer); |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - // Prepare Operating System |
|
127 | - if (!empty($data->server_os)) { |
|
128 | - $os = explode(' ', $data->server_os, 2); |
|
129 | - |
|
130 | - $point->addField('server_string', $data->server_os); |
|
131 | - if (!empty($os[0])) { |
|
132 | - $point->addField('server_os', $os[0]); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - $writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms'); |
|
137 | - } |
|
22 | + /** |
|
23 | + * Array containing the allowed sources |
|
24 | + * |
|
25 | + * @var string[] |
|
26 | + */ |
|
27 | + public const ALLOWED_SOURCES = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version']; |
|
28 | + |
|
29 | + /** |
|
30 | + * The database driver. |
|
31 | + * |
|
32 | + * @var DatabaseInterface |
|
33 | + * @since 1.3.0 |
|
34 | + */ |
|
35 | + private $db; |
|
36 | + |
|
37 | + /** |
|
38 | + * Instantiate the repository. |
|
39 | + * |
|
40 | + * @param DatabaseInterface $db The database driver. |
|
41 | + */ |
|
42 | + public function __construct(DatabaseInterface $db) |
|
43 | + { |
|
44 | + $this->db = $db; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Saves the given data. |
|
49 | + * |
|
50 | + * @param \stdClass $data Data object to save. |
|
51 | + * |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function save(\stdClass $data): void |
|
55 | + { |
|
56 | + $writeApi = $this->db->createWriteApi(); |
|
57 | + |
|
58 | + // Set the modified date of the record |
|
59 | + $timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp(); |
|
60 | + |
|
61 | + $point = Point::measurement('joomla') |
|
62 | + ->addTag('unique_id', $data->unique_id) |
|
63 | + ->time($timestamp); |
|
64 | + |
|
65 | + // Extract major and minor version |
|
66 | + if (!empty($data->php_version)) { |
|
67 | + preg_match('/^(\d+)\.(\d+)\./', $data->php_version, $phpVersion); |
|
68 | + $point->addField('php_version', $data->php_version); |
|
69 | + if (!empty($phpVersion)) { |
|
70 | + $point->addField('php_major', $phpVersion[1]) |
|
71 | + ->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + // Prepare CMS version |
|
76 | + if (!empty($data->cms_version)) { |
|
77 | + preg_match('/^(\d+)\.(\d+)\./', $data->cms_version, $cmsVersions); |
|
78 | + |
|
79 | + $point->addField('cms_version', $data->cms_version); |
|
80 | + if (!empty($cmsVersions)) { |
|
81 | + $point |
|
82 | + ->addField('cms_major', $cmsVersions[1]) |
|
83 | + ->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + // Prepare Database versions |
|
88 | + if (!empty($data->db_version)) { |
|
89 | + preg_match('/^(\d+)\.(\d+)\./', $data->db_version, $dbVersions); |
|
90 | + |
|
91 | + $point->addField('db_version', $data->db_version); |
|
92 | + if (!empty($dbVersions)) { |
|
93 | + $point->addField('db_major', $dbVersions[1]) |
|
94 | + ->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]); |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + // Prepare Database Driver |
|
99 | + if (!empty($data->db_type)) { |
|
100 | + $dbServer = null; |
|
101 | + if ($data->db_type === 'postgresql') { |
|
102 | + $dbServer = 'PostgreSQL'; |
|
103 | + } elseif (str_contains($data->db_type, 'mysql')) { |
|
104 | + $dbServer = 'MySQL'; |
|
105 | + if (!empty($data->db_version)) { |
|
106 | + if ( |
|
107 | + version_compare($data->db_version, '10.0.0', '>=') |
|
108 | + // We know this is not 100% correct but more accurate than expecting MySQL with this version string |
|
109 | + || version_compare($data->db_version, '5.5.5', '=') |
|
110 | + ) { |
|
111 | + $dbServer = 'MariaDB'; |
|
112 | + } |
|
113 | + } |
|
114 | + } elseif (str_contains($data->db_type, 'mariadb')) { |
|
115 | + $dbServer = 'MariaDB'; |
|
116 | + } elseif (str_contains($data->db_type, 'sqlsrv')) { |
|
117 | + $dbServer = 'MSSQL'; |
|
118 | + } |
|
119 | + |
|
120 | + $point->addField('db_driver', $data->db_type); |
|
121 | + if (!empty($dbServer)) { |
|
122 | + $point->addField('db_server', $dbServer); |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + // Prepare Operating System |
|
127 | + if (!empty($data->server_os)) { |
|
128 | + $os = explode(' ', $data->server_os, 2); |
|
129 | + |
|
130 | + $point->addField('server_string', $data->server_os); |
|
131 | + if (!empty($os[0])) { |
|
132 | + $point->addField('server_os', $os[0]); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + $writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms'); |
|
137 | + } |
|
138 | 138 | } |