[TASK] Re-work/simplify copyright header in PHP files - Part 9
[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 'ContentAdapter' => $this->getContentAdapterStatus(),
35 );
36 return $statuses;
37 }
38
39 /**
40 * Checks if there are files marked as missed.
41 *
42 * @return \TYPO3\CMS\Reports\Status An object representing whether there are files marked as missed or not
43 */
44 protected function getMissingFilesStatus() {
45 $value = $GLOBALS['LANG']->getLL('status_none');
46 $count = 0;
47 $maxFilesToShow = 100;
48 $message = '';
49 $severity = \TYPO3\CMS\Reports\Status::OK;
50
51 /** @var $storageRepository \TYPO3\CMS\Core\Resource\StorageRepository */
52 $storageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
53 $storageObjects = $storageRepository->findAll();
54 $storages = array();
55
56 /** @var $storageObject \TYPO3\CMS\Core\Resource\ResourceStorage */
57 foreach ($storageObjects as $storageObject) {
58
59 // We only check missing files for storages that are online
60 if ($storageObject->isOnline()) {
61 $storages[$storageObject->getUid()] = $storageObject;
62 }
63 }
64
65 if (count($storages)) {
66 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
67 '*',
68 'sys_file',
69 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')'
70 );
71 }
72
73 if ($count) {
74 $value = sprintf($GLOBALS['LANG']->getLL('status_missingFilesCount'), $count);
75 $severity = \TYPO3\CMS\Reports\Status::WARNING;
76
77 $files = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
78 'identifier,storage',
79 'sys_file',
80 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')',
81 '',
82 '',
83 $maxFilesToShow
84 );
85
86 $message = '<p>' . $GLOBALS['LANG']->getLL('status_missingFilesMessage') . '</p>';
87 foreach ($files as $file) {
88 $message .= $storages[$file['storage']]->getName() . ' ' . $file['identifier'] . '<br />';
89 }
90
91 if ($count > $maxFilesToShow) {
92 $message .= '...<br />';
93 }
94 }
95
96 return GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_missingFiles'), $value, $message, $severity);
97 }
98
99 /**
100 * Checks if content adapter is active
101 *
102 * @return \TYPO3\CMS\Reports\Status An object representing whether the content adapter is active or not
103 */
104 protected function getContentAdapterStatus() {
105 $value = $GLOBALS['LANG']->getLL('status_disabled');
106 $message = '';
107 $severity = \TYPO3\CMS\Reports\Status::OK;
108 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['activateContentAdapter']) {
109 $value = $GLOBALS['LANG']->getLL('status_enabled');
110 $message = '<p>' . $GLOBALS['LANG']->getLL('status_contentAdapterActiveMessage') . '</p>';
111 $severity = \TYPO3\CMS\Reports\Status::WARNING;
112 }
113 return GeneralUtility::makeInstance(
114 'TYPO3\\CMS\\Reports\\Status',
115 $GLOBALS['LANG']->getLL('status_contentAdapterActive'),
116 $value,
117 $message,
118 $severity
119 );
120
121 }
122 }