‪TYPO3CMS  10.4
SysLogErrorsDataProvider.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use ‪TYPO3\CMS\Core\SysLog\Type as SystemLogType;
27 
32 {
38  protected ‪$days = 31;
39 
43  protected ‪$labels = [];
44 
48  protected ‪$data = [];
49 
50  public function ‪__construct(int ‪$days = 31)
51  {
52  $this->days = ‪$days;
53  }
54 
58  public function ‪getChartData(): array
59  {
61 
62  return [
63  'labels' => ‪$this->labels,
64  'datasets' => [
65  [
66  'label' => $this->‪getLanguageService()->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.sysLogErrors.chart.dataSet.0'),
67  'backgroundColor' => ‪WidgetApi::getDefaultChartColors()[0],
68  'border' => 0,
69  'data' => ‪$this->data
70  ]
71  ]
72  ];
73  }
74 
75  protected function ‪getNumberOfErrorsInPeriod(int $start, int $end): int
76  {
77  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_log');
78  return (int)$queryBuilder
79  ->count('*')
80  ->from('sys_log')
81  ->where(
82  $queryBuilder->expr()->eq(
83  'type',
84  $queryBuilder->createNamedParameter(SystemLogType::ERROR, ‪Connection::PARAM_INT)
85  ),
86  $queryBuilder->expr()->gte(
87  'tstamp',
88  $queryBuilder->createNamedParameter($start, ‪Connection::PARAM_INT)
89  ),
90  $queryBuilder->expr()->lte(
91  'tstamp',
92  $queryBuilder->createNamedParameter($end, ‪Connection::PARAM_INT)
93  )
94  )
95  ->execute()
96  ->fetchColumn();
97  }
98 
99  protected function ‪calculateDataForLastDays(): void
100  {
101  $format = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
102 
103  for ($daysBefore = $this->days; $daysBefore >= 0; $daysBefore--) {
104  $this->labels[] = date($format, (int)strtotime('-' . $daysBefore . ' day'));
105  $startPeriod = (int)strtotime('-' . $daysBefore . ' day 0:00:00');
106  $endPeriod = (int)strtotime('-' . $daysBefore . ' day 23:59:59');
107 
108  $this->data[] = $this->‪getNumberOfErrorsInPeriod($startPeriod, $endPeriod);
109  }
110  }
111 
112  protected function ‪getLanguageService(): ‪LanguageService
113  {
114  return ‪$GLOBALS['LANG'];
115  }
116 }
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\$data
‪array $data
Definition: SysLogErrorsDataProvider.php:45
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:47
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\$labels
‪array $labels
Definition: SysLogErrorsDataProvider.php:41
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\calculateDataForLastDays
‪calculateDataForLastDays()
Definition: SysLogErrorsDataProvider.php:96
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\__construct
‪__construct(int $days=31)
Definition: SysLogErrorsDataProvider.php:47
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider
Definition: SysLogErrorsDataProvider.php:32
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\$days
‪int $days
Definition: SysLogErrorsDataProvider.php:37
‪TYPO3\CMS\Dashboard\WidgetApi
Definition: WidgetApi.php:24
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\getNumberOfErrorsInPeriod
‪getNumberOfErrorsInPeriod(int $start, int $end)
Definition: SysLogErrorsDataProvider.php:72
‪TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface
Definition: ChartDataProviderInterface.php:24
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Dashboard\Widgets\Provider
Definition: ButtonProvider.php:18
‪TYPO3\CMS\Dashboard\WidgetApi\getDefaultChartColors
‪static array getDefaultChartColors()
Definition: WidgetApi.php:30
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\getLanguageService
‪getLanguageService()
Definition: SysLogErrorsDataProvider.php:109
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Dashboard\Widgets\Provider\SysLogErrorsDataProvider\getChartData
‪getChartData()
Definition: SysLogErrorsDataProvider.php:55
‪TYPO3\CMS\Core\SysLog\Type
Definition: Type.php:24