Commit 0d0878e0 authored by Mathias Schreiber's avatar Mathias Schreiber Committed by Susanne Moog
Browse files

[FEATURE] Add button to delete similar errors from sys_log

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's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
parent 1c7daaa0
......@@ -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');
}
}
......@@ -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.
......@@ -154,6 +157,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
*
......
......@@ -369,6 +369,21 @@
<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>
......@@ -128,6 +128,9 @@
<th>
<f:translate key="chLog_l_details" />
</th>
<th>
<f:translate key="actions" />
</th>
</tr>
</thead>
<tbody>
......@@ -198,6 +201,17 @@
(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>
......
<f:flashMessages />
<f:render partial="Content" arguments="{_all}" />
\ No newline at end of file
......@@ -18,7 +18,7 @@ if (TYPO3_MODE === 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
'log',
'',
[
'Tools' => 'index',
'Tools' => 'index,deleteMessage',
'WebInfo' => 'index',
],
[
......
.. 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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment