[CLEANUP] Code cleanup in ext:reports
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Report / Status / FalStatus.php
1 <?php
2 namespace TYPO3\CMS\Reports\Report\Status;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\DatabaseConnection;
18 use TYPO3\CMS\Core\Resource\StorageRepository;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Lang\LanguageService;
21 use TYPO3\CMS\Reports\Status;
22 use TYPO3\CMS\Reports\StatusProviderInterface;
23
24 /**
25 * Performs several checks about the FAL status
26 */
27 class FalStatus implements StatusProviderInterface
28 {
29 /**
30 * Determines the status of the FAL index.
31 *
32 * @return array List of statuses
33 */
34 public function getStatus()
35 {
36 $statuses = array(
37 'MissingFiles' => $this->getMissingFilesStatus(),
38 );
39 return $statuses;
40 }
41
42 /**
43 * Checks if there are files marked as missed.
44 *
45 * @return \TYPO3\CMS\Reports\Status An object representing whether there are files marked as missed or not
46 */
47 protected function getMissingFilesStatus()
48 {
49 $value = $this->getLanguageService()->getLL('status_none');
50 $count = 0;
51 $maxFilesToShow = 100;
52 $message = '';
53 $severity = Status::OK;
54
55 /** @var StorageRepository $storageRepository */
56 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
57 $storageObjects = $storageRepository->findAll();
58 $storages = array();
59
60 /** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storageObject */
61 foreach ($storageObjects as $storageObject) {
62
63 // We only check missing files for storages that are online
64 if ($storageObject->isOnline()) {
65 $storages[$storageObject->getUid()] = $storageObject;
66 }
67 }
68
69 if (!empty($storages)) {
70 $count = $this->getDatabaseConnection()->exec_SELECTcountRows(
71 '*',
72 'sys_file',
73 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')'
74 );
75 }
76
77 if ($count) {
78 $value = sprintf($this->getLanguageService()->getLL('status_missingFilesCount'), $count);
79 $severity = Status::WARNING;
80
81 $files = $this->getDatabaseConnection()->exec_SELECTgetRows(
82 'identifier,storage',
83 'sys_file',
84 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')',
85 '',
86 '',
87 $maxFilesToShow
88 );
89
90 $message = '<p>' . $this->getLanguageService()->getLL('status_missingFilesMessage') . '</p>';
91 foreach ($files as $file) {
92 $message .= $storages[$file['storage']]->getName() . ' ' . $file['identifier'] . '<br />';
93 }
94
95 if ($count > $maxFilesToShow) {
96 $message .= '...<br />';
97 }
98 }
99
100 return GeneralUtility::makeInstance(Status::class, $this->getLanguageService()->getLL('status_missingFiles'), $value, $message, $severity);
101 }
102
103 /**
104 * @return LanguageService
105 */
106 protected function getLanguageService()
107 {
108 return $GLOBALS['LANG'];
109 }
110
111 /**
112 * @return DatabaseConnection
113 */
114 protected function getDatabaseConnection()
115 {
116 return $GLOBALS['TYPO3_DB'];
117 }
118 }