[FEATURE] Add button to delete similar errors from sys_log 38/51238/16
authorMathias Schreiber <mathias.schreiber@typo3.com>
Tue, 10 Jan 2017 13:40:45 +0000 (14:40 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Wed, 11 Jan 2017 11:49:27 +0000 (12:49 +0100)
The log module of TYPO3 now shows a button to delete multiple errors at once based on
the `details` field of the `sys_log` table.
This comes in handy when you fixed an error that spammed the log before.

Releases: master
Resolves: #79235
Change-Id: I314abcae454e96b9809c6f4a2fb69b3b926f3118
Reviewed-on: https://review.typo3.org/51238
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/belog/Classes/Controller/ToolsController.php
typo3/sysext/belog/Classes/Domain/Repository/LogEntryRepository.php
typo3/sysext/belog/Resources/Private/Language/locallang.xlf
typo3/sysext/belog/Resources/Private/Partials/Content/LogEntries.html
typo3/sysext/belog/Resources/Private/Templates/Tools/Index.html
typo3/sysext/belog/ext_tables.php
typo3/sysext/core/Documentation/Changelog/master/Feature-79235-AddButtonToDeleteSimilarErrorsFromSys_log.rst [new file with mode: 0644]

index c339cf0..c474c3a 100644 (file)
@@ -13,10 +13,30 @@ namespace TYPO3\CMS\Belog\Controller;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Messaging\AbstractMessage;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 
 /**
  * Show log entries from table sys_log
  */
 class ToolsController extends \TYPO3\CMS\Belog\Controller\AbstractController
 {
+    /**
+     * Delete all log entries that share the same message with the log entry given
+     * in $errorUid
+     *
+     * @param int $errorUid
+     */
+    public function deleteMessageAction(int $errorUid)
+    {
+        /** @var \TYPO3\CMS\Belog\Domain\Model\LogEntry $logEntry */
+        $logEntry = $this->logEntryRepository->findByUid($errorUid);
+        if (!$logEntry) {
+            $this->addFlashMessage(LocalizationUtility::translate('actions.delete.noRowFound', 'belog'), '', AbstractMessage::WARNING);
+            $this->redirect('index');
+        }
+        $numberOfDeletedRows = $this->logEntryRepository->deleteByMessageDetails($logEntry);
+        $this->addFlashMessage(sprintf(LocalizationUtility::translate('actions.delete.message', 'belog'), $numberOfDeletedRows));
+        $this->redirect('index');
+    }
 }
index a3cbd85..bd8d103 100644 (file)
@@ -13,6 +13,9 @@ namespace TYPO3\CMS\Belog\Domain\Repository;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Belog\Domain\Model\LogEntry;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Sys log entry repository
@@ -78,7 +81,7 @@ class LogEntryRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
         if ($constraint->getAction() > 0) {
             $queryConstraints[] = $query->equals('type', $constraint->getAction());
         } elseif ($constraint->getAction() == -1) {
-            $queryConstraints[] = $query->in('error', [-1, 1, 2, 3]);
+            $queryConstraints[] = $query->equals('type', 5);
         }
         // Start / endtime handling: The timestamp calculation was already done
         // in the controller, since we need those calculated values in the view as well.
@@ -155,6 +158,28 @@ class LogEntryRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
     }
 
     /**
+     * Deletes all messages which have the same message details
+     *
+     * @param LogEntry $logEntry
+     * @return int
+     */
+    public function deleteByMessageDetails(LogEntry $logEntry): int
+    {
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable('sys_log');
+        $constraints = [];
+        $constraints[] = $queryBuilder->expr()->eq('details', $queryBuilder->createNamedParameter($logEntry->getDetails()));
+        // If the detailsNo is 11 or 12 we got messages that are heavily using placeholders. In this case
+        // we need to compare both the message and the actual log data to not remove too many log entries.
+        if (GeneralUtility::inList('11,12', $logEntry->getDetailsNumber())) {
+            $constraints[] = $queryBuilder->expr()->eq('log_data', $queryBuilder->createNamedParameter($logEntry->getLogData()));
+        }
+        return $queryBuilder->delete('sys_log')
+            ->where(...$constraints)
+            ->execute();
+    }
+
+    /**
      * Get a list of all backend users that are not deleted
      *
      * @return array
index eaa139c..5f25528 100644 (file)
                        <trans-unit id="systemmessage.errorsInPeriod">
                                <source><![CDATA[We have found %1$d errors. Please check your <a href="%2$s">system log</a>.]]></source>
                        </trans-unit>
+                       <trans-unit id="actions">
+                               <source>Actions</source>
+                       </trans-unit>
+                       <trans-unit id="actions.delete">
+                               <source>Delete similar errors</source>
+                       </trans-unit>
+                       <trans-unit id="actions.deleteWarnings">
+                               <source>Delete similar warnings</source>
+                       </trans-unit>
+                       <trans-unit id="actions.delete.message">
+                               <source>Total entries deleted: %1$d</source>
+                       </trans-unit>
+                       <trans-unit id="actions.delete.noRowFound">
+                               <source>Log entry could not be found.</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
index 0faf5e6..f393c40 100644 (file)
                                                <th>
                                                        <f:translate key="chLog_l_details" />
                                                </th>
+                                               <th>
+                                                       <f:translate key="actions" />
+                                               </th>
                                        </tr>
                                </thead>
                                <tbody>
                                                                        (msg#{logItem.type}.{logItem.action}.{logItem.detailsNumber})
                                                                </f:if>
                                                        </td>
+                                                       <td>
+                                                               <f:switch expression="{logItem.error}">
+                                                                       <f:case value="1">
+                                                                               <f:link.action action="deleteMessage" arguments="{errorUid:logItem.uid}" class="btn btn-warning"><f:translate key="actions.deleteWarnings" /></f:link.action>
+                                                                       </f:case>
+                                                                       <f:case value="2">
+                                                                               <f:link.action action="deleteMessage" arguments="{errorUid:logItem.uid}" class="btn btn-danger"><f:translate key="actions.delete" /></f:link.action>
+                                                                       </f:case>
+                                                                       <f:defaultCase />
+                                                               </f:switch>
+                                                       </td>
                                                </tr>
                                        </f:for>
                                </tbody>
index 6764f34..2324d44 100644 (file)
@@ -18,7 +18,7 @@ if (TYPO3_MODE === 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
         'log',
         '',
         [
-            'Tools' => 'index',
+            'Tools' => 'index,deleteMessage',
             'WebInfo' => 'index',
         ],
         [
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-79235-AddButtonToDeleteSimilarErrorsFromSys_log.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-79235-AddButtonToDeleteSimilarErrorsFromSys_log.rst
new file mode 100644 (file)
index 0000000..69c6ba1
--- /dev/null
@@ -0,0 +1,16 @@
+.. include:: ../../Includes.txt
+
+==================================================================
+Feature: #79235 - Add button to delete similar errors from sys_log
+==================================================================
+
+See :issue:`79235`
+
+Description
+===========
+
+The log module of TYPO3 now shows a button to delete multiple errors at once based on
+the `details` field of the `sys_log` table.
+This comes in handy when you fixed an error that spammed the log before.
+
+.. index:: Backend
\ No newline at end of file