[FEATURE] Add a link to delete the deprecation log file
authorMario Rimann <typo3-coding@rimann.org>
Sun, 4 Dec 2011 22:36:31 +0000 (23:36 +0100)
committerSteffen Gebert <steffen.gebert@typo3.org>
Sat, 24 Dec 2011 12:45:36 +0000 (13:45 +0100)
This adds a link to delete the deprecation log file from the reports
module. It also changes the status check on the deprecation log
to always show the size of the file, not only when it's over limit.

Change-Id: Ic51014b9f59100b1550a969e39cfabd4735fe4ac
Resolves: #23387
Releases: 4.7
Reviewed-on: http://review.typo3.org/7069
Reviewed-by: Oliver Klee
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
typo3/sysext/reports/reports/locallang.xlf
typo3/sysext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php

index 533f68a..f10b8c9 100644 (file)
                        <trans-unit id="status_configuration_DeprecationLogSize" xml:space="preserve">
                                <source>Your deprecation log file currently takes up %s.</source>
                        </trans-unit>
+                       <trans-unit id="status_configuration_DeprecationLogDeleteLink" xml:space="preserve">
+                               <source>Delete deprecation log file.</source>
+                       </trans-unit>
+                       <trans-unit id="status_configuration_DeprecationLogDeletedSuccessful" xml:space="preserve">
+                               <source>The deprecation log file was successfully deleted.</source>
+                       </trans-unit>
+                       <trans-unit id="status_configuration_DeprecationLogDeletionFailed" xml:space="preserve">
+                               <source>The deprecation log file could not be deleted!</source>
+                       </trans-unit>
                        <trans-unit id="status_configuration_PhpSafeModeEnabled" xml:space="preserve">
                                <source>PHP INI setting safe_mode "On" is deprecated since PHP 5.3 and is not supported by TYPO3 anymore.</source>
                        </trans-unit>
index d91a42e..fb72101 100644 (file)
@@ -51,6 +51,8 @@ class tx_reports_reports_status_ConfigurationStatus implements tx_reports_Status
         * @see typo3/sysext/reports/interfaces/tx_reports_StatusProvider::getStatus()
         */
        public function getStatus() {
+               $this->executeAdminCommand();
+
                $statuses = array(
                        'emptyReferenceIndex'   => $this->getReferenceIndexStatus(),
                        'deprecationLog'        => $this->getDeprecationLogStatus(),
@@ -254,13 +256,20 @@ class tx_reports_reports_status_ConfigurationStatus implements tx_reports_Status
                        $logFile     = t3lib_div::getDeprecationLogFileName();
                        $logFileSize = 0;
 
-                       if (file_exists($logFile)) {
+                       if (@file_exists($logFile)) {
                                $logFileSize = filesize($logFile);
 
-                               $message .= '<p> ' . sprintf(
+                               $message .= '<p>' . sprintf(
                                                $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogFile'),
                                                $this->getDeprecationLogFileLink()
                                        ) . '</p>';
+
+                               $removeDeprecationLogFileUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL') . '&amp;adminCmd=removeDeprecationLogFile';
+                               $message .= '<p>' . sprintf(
+                                               $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogSize'),
+                                               t3lib_div::formatSize($logFileSize)
+                                       )
+                                       . ' <a href="' . $removeDeprecationLogFileUrl . '">' . $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogDeleteLink') . '</a></p>';
                        }
 
                        if ($logFileSize > $this->deprecationLogFileSizeWarningThreshold) {
@@ -270,13 +279,6 @@ class tx_reports_reports_status_ConfigurationStatus implements tx_reports_Status
                        if ($logFileSize > $this->deprecationLogFileSizeErrorThreshold) {
                                $severity = tx_reports_reports_status_Status::ERROR;
                        }
-
-                       if ($severity > tx_reports_reports_status_Status::OK) {
-                               $message .= '<p> ' . sprintf(
-                                       $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogSize'),
-                                       t3lib_div::formatSize($logFileSize)
-                               ) . '</p>';
-                       }
                }
 
                return t3lib_div::makeInstance('tx_reports_reports_status_Status',
@@ -299,8 +301,50 @@ class tx_reports_reports_status_ConfigurationStatus implements tx_reports_Status
 
                return $link;
        }
-}
 
+       /**
+        * Executes admin commands.
+        *
+        * Currently implemented commands are:
+        *  - Remove deprecation log file
+        *
+        * @return void
+        */
+       protected function executeAdminCommand() {
+               $command = t3lib_div::_GET('adminCmd');
+
+               switch ($command) {
+                       case 'removeDeprecationLogFile':
+                               self::removeDeprecationLogFile();
+                               break;
+                       default:
+                                       // intentionally left blank
+                               break;
+               }
+       }
+
+       /**
+        * Remove deprecation log file.
+        *
+        * @return void
+        */
+       protected static function removeDeprecationLogFile() {
+               if (@unlink(t3lib_div::getDeprecationLogFileName())) {
+                       $message = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogDeletedSuccessful');
+                       $severity =  t3lib_FlashMessage::OK;
+               } else {
+                       $message = $GLOBALS['LANG']->getLL('status_configuration_DeprecationLogDeletionFailed');
+                       $severity =  t3lib_FlashMessage::ERROR;
+               }
+               t3lib_FlashMessageQueue::addMessage(t3lib_div::makeInstance(
+                       't3lib_FlashMessage',
+                       $message,
+                       '',
+                       $severity,
+                       TRUE
+               ));
+       }
+}
 
 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php'])) {
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/reports/status/class.tx_reports_reports_status_configurationstatus.php']);