[!!!][TASK] Drop ContentAdapter
[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\Utility\GeneralUtility;
18
19 /**
20 * Performs several checks about the FAL status
21 *
22 * @author Frans Saris <franssaris@gmail.com>
23 */
24 class FalStatus implements \TYPO3\CMS\Reports\StatusProviderInterface {
25
26 /**
27 * Determines the status of the FAL index.
28 *
29 * @return array List of statuses
30 */
31 public function getStatus() {
32 $statuses = array(
33 'MissingFiles' => $this->getMissingFilesStatus(),
34 );
35 return $statuses;
36 }
37
38 /**
39 * Checks if there are files marked as missed.
40 *
41 * @return \TYPO3\CMS\Reports\Status An object representing whether there are files marked as missed or not
42 */
43 protected function getMissingFilesStatus() {
44 $value = $GLOBALS['LANG']->getLL('status_none');
45 $count = 0;
46 $maxFilesToShow = 100;
47 $message = '';
48 $severity = \TYPO3\CMS\Reports\Status::OK;
49
50 /** @var $storageRepository \TYPO3\CMS\Core\Resource\StorageRepository */
51 $storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
52 $storageObjects = $storageRepository->findAll();
53 $storages = array();
54
55 /** @var $storageObject \TYPO3\CMS\Core\Resource\ResourceStorage */
56 foreach ($storageObjects as $storageObject) {
57
58 // We only check missing files for storages that are online
59 if ($storageObject->isOnline()) {
60 $storages[$storageObject->getUid()] = $storageObject;
61 }
62 }
63
64 if (count($storages)) {
65 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
66 '*',
67 'sys_file',
68 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')'
69 );
70 }
71
72 if ($count) {
73 $value = sprintf($GLOBALS['LANG']->getLL('status_missingFilesCount'), $count);
74 $severity = \TYPO3\CMS\Reports\Status::WARNING;
75
76 $files = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
77 'identifier,storage',
78 'sys_file',
79 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')',
80 '',
81 '',
82 $maxFilesToShow
83 );
84
85 $message = '<p>' . $GLOBALS['LANG']->getLL('status_missingFilesMessage') . '</p>';
86 foreach ($files as $file) {
87 $message .= $storages[$file['storage']]->getName() . ' ' . $file['identifier'] . '<br />';
88 }
89
90 if ($count > $maxFilesToShow) {
91 $message .= '...<br />';
92 }
93 }
94
95 return GeneralUtility::makeInstance(\TYPO3\CMS\Reports\Status::class, $GLOBALS['LANG']->getLL('status_missingFiles'), $value, $message, $severity);
96 }
97
98 }