[TASK] Add warning in Reports module if content adapter is active
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Report / Status / FalStatus.php
1 <?php
2 namespace TYPO3\CMS\Reports\Report\Status;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Frans Saris <franssaris@gmail.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * Performs several checks about the FAL status
31 *
32 * @author Frans Saris <franssaris@gmail.com>
33 */
34 class FalStatus implements \TYPO3\CMS\Reports\StatusProviderInterface {
35
36 /**
37 * Determines the status of the FAL index.
38 *
39 * @return array List of statuses
40 */
41 public function getStatus() {
42 $statuses = array(
43 'MissingFiles' => $this->getMissingFilesStatus(),
44 'ContentAdapter' => $this->getContentAdapterStatus(),
45 );
46 return $statuses;
47 }
48
49 /**
50 * Checks if there are files marked as missed.
51 *
52 * @return \TYPO3\CMS\Reports\Status An object representing whether there are files marked as missed or not
53 */
54 protected function getMissingFilesStatus() {
55 $value = $GLOBALS['LANG']->getLL('status_none');
56 $count = 0;
57 $maxFilesToShow = 100;
58 $message = '';
59 $severity = \TYPO3\CMS\Reports\Status::OK;
60
61 /** @var $storageRepository \TYPO3\CMS\Core\Resource\StorageRepository */
62 $storageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
63 $storageObjects = $storageRepository->findAll();
64 $storages = array();
65
66 /** @var $storageObject \TYPO3\CMS\Core\Resource\ResourceStorage */
67 foreach ($storageObjects as $storageObject) {
68
69 // We only check missing files for storages that are online
70 if ($storageObject->isOnline()) {
71 $storages[$storageObject->getUid()] = $storageObject;
72 }
73 }
74
75 if (count($storages)) {
76 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
77 '*',
78 'sys_file',
79 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')'
80 );
81 }
82
83 if ($count) {
84 $value = sprintf($GLOBALS['LANG']->getLL('status_missingFilesCount'), $count);
85 $severity = \TYPO3\CMS\Reports\Status::WARNING;
86
87 $files = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
88 'identifier,storage',
89 'sys_file',
90 'missing=1 AND storage IN (' . implode(',', array_keys($storages)) . ')',
91 '',
92 '',
93 $maxFilesToShow
94 );
95
96 $message = '<p>' . $GLOBALS['LANG']->getLL('status_missingFilesMessage') . '</p>';
97 foreach ($files as $file) {
98 $message .= $storages[$file['storage']]->getName() . ' ' . $file['identifier'] . '<br />';
99 }
100
101 if ($count > $maxFilesToShow) {
102 $message .= '...<br />';
103 }
104 }
105
106 return GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_missingFiles'), $value, $message, $severity);
107 }
108
109 /**
110 * Checks if content adapter is active
111 *
112 * @return \TYPO3\CMS\Reports\Status An object representing whether the content adapter is active or not
113 */
114 protected function getContentAdapterStatus() {
115 $value = $GLOBALS['LANG']->getLL('status_disabled');
116 $message = '';
117 $severity = \TYPO3\CMS\Reports\Status::OK;
118 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['activateContentAdapter']) {
119 $value = $GLOBALS['LANG']->getLL('status_enabled');
120 $message = '<p>' . $GLOBALS['LANG']->getLL('status_contentAdapterActiveMessage') . '</p>';
121 $severity = \TYPO3\CMS\Reports\Status::WARNING;
122 }
123 return GeneralUtility::makeInstance(
124 'TYPO3\\CMS\\Reports\\Status',
125 $GLOBALS['LANG']->getLL('status_contentAdapterActive'),
126 $value,
127 $message,
128 $severity
129 );
130
131 }
132 }