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