Skip to content
Snippets Groups Projects
Commit 4b4586e1 authored by Andreas Nedbal's avatar Andreas Nedbal Committed by Oliver Bartsch
Browse files

[TASK] Turn workspace HistoryService stateless

Resolves: #104313
Releases: main
Change-Id: I17bb0ab444ef180434847a03561aac0414c7af27
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85111


Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarOliver Bartsch <bo@cedev.de>
Tested-by: default avatarOliver Bartsch <bo@cedev.de>
parent 402a65ea
Branches
Tags
No related merge requests found
......@@ -26,20 +26,18 @@ use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\DiffGranularity;
use TYPO3\CMS\Core\Utility\DiffUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* @internal
*/
class HistoryService implements SingletonInterface
{
protected array $backendUserNames;
protected array $historyEntries = [];
public function __construct()
{
$this->backendUserNames = BackendUtility::getUserNames();
}
public function __construct(
private readonly Avatar $avatar,
private readonly DiffUtility $diffUtility,
private readonly FlexFormValueFormatter $flexFormValueFormatter,
private readonly RecordHistory $recordHistory,
) {}
/**
* Gets the editing history of a record.
......@@ -92,13 +90,12 @@ class HistoryService implements SingletonInterface
$differences = $this->getDifferences($entry);
}
$avatar = GeneralUtility::makeInstance(Avatar::class);
$beUserRecord = BackendUtility::getRecord('be_users', $entry['userid']);
return [
'datetime' => htmlspecialchars(BackendUtility::datetime($entry['tstamp'])),
'user' => htmlspecialchars($this->getUserName($entry['userid'])),
'user_avatar' => $avatar->render($beUserRecord),
'user' => htmlspecialchars($beUserRecord['username'] ?? 'unknown'),
'user_avatar' => $this->avatar->render($beUserRecord),
'differences' => $differences,
];
}
......@@ -111,7 +108,6 @@ class HistoryService implements SingletonInterface
*/
protected function getDifferences(array $entry): array
{
$diffUtility = GeneralUtility::makeInstance(DiffUtility::class);
$differences = [];
$tableName = $entry['tablename'];
if (is_array($entry['newRecord'] ?? false)) {
......@@ -124,16 +120,15 @@ class HistoryService implements SingletonInterface
// Create diff-result:
if ($tcaType === 'flex') {
$granularity = DiffGranularity::CHARACTER;
$flexFormValueFormatter = GeneralUtility::makeInstance(FlexFormValueFormatter::class);
$colConfig = $GLOBALS['TCA'][$tableName]['columns'][$field]['config'] ?? [];
$old = $flexFormValueFormatter->format($tableName, $field, $entry['oldRecord'][$field], $entry['recuid'], $colConfig);
$new = $flexFormValueFormatter->format($tableName, $field, $entry['newRecord'][$field], $entry['recuid'], $colConfig);
$old = $this->flexFormValueFormatter->format($tableName, $field, $entry['oldRecord'][$field], $entry['recuid'], $colConfig);
$new = $this->flexFormValueFormatter->format($tableName, $field, $entry['newRecord'][$field], $entry['recuid'], $colConfig);
} else {
$granularity = DiffGranularity::WORD;
$old = (string)BackendUtility::getProcessedValue($tableName, $field, $entry['oldRecord'][$field], 0, true);
$new = (string)BackendUtility::getProcessedValue($tableName, $field, $entry['newRecord'][$field], 0, true);
}
$fieldDifferences = $diffUtility->makeDiffDisplay($old, $new, $granularity);
$fieldDifferences = $this->diffUtility->makeDiffDisplay($old, $new, $granularity);
if (!empty($fieldDifferences)) {
$differences[] = [
'label' => $this->getLanguageService()->sL((string)BackendUtility::getItemLabel($tableName, (string)$field)),
......@@ -146,18 +141,6 @@ class HistoryService implements SingletonInterface
return $differences;
}
/**
* Gets the username of a backend user.
*/
protected function getUserName(int $user): string
{
$userName = 'unknown';
if (!empty($this->backendUserNames[$user]['username'])) {
$userName = $this->backendUserNames[$user]['username'];
}
return $userName;
}
/**
* Gets an instance of the record history of a record.
*
......@@ -166,11 +149,7 @@ class HistoryService implements SingletonInterface
*/
protected function getHistoryEntries(string $table, int $id): array
{
if (!isset($this->historyEntries[$table][$id])) {
$this->historyEntries[$table][$id] = GeneralUtility::makeInstance(RecordHistory::class)
->getHistoryDataForRecord($table, $id);
}
return $this->historyEntries[$table][$id];
return $this->recordHistory->getHistoryDataForRecord($table, $id);
}
protected function getLanguageService(): LanguageService
......
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