From c2db9499d1430c0195a6325b11b1bf74386f006e Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Tue, 12 Jul 2022 11:56:59 +0200 Subject: [PATCH] [!!!][TASK] Remove TCA option "cruser_id" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TYPO3's TCA definition has a setting called `cruser_id` which automatically is filled with the current TYPO3's Backend User ID, if created via DataHandler. However, this information is also available in the RecordHistory (since its extraction from sys_log in v9) and can be queried, when needed, directly from there. This way, all TCA-based tables, having the setting "cruser_id" do not need to carry this value anymore, as it is duplicated in TYPO3's data model. This change removes the evaluation of "cruser_id", and removes the filling of this property via DataHandler. The DB field is also not set anymore automatically. The Info popup (ElementInformationController) now shows the information from the RecordHistory information. Resolves: #98024 Releases: main Change-Id: I1fe54b0ecfc0ee9b2d1867011dd960e1906fd2d4 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75123 Tested-by: core-ci Tested-by: Christian Kuhn Tested-by: Stefan Bürk Reviewed-by: Christian Kuhn Reviewed-by: Stefan Bürk --- Classes/Controller/RecyclerAjaxController.php | 9 +++++++-- Tests/Functional/Fixtures/Database/be_groups.csv | 6 +++--- Tests/Functional/Fixtures/Database/be_users.csv | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Classes/Controller/RecyclerAjaxController.php b/Classes/Controller/RecyclerAjaxController.php index 4ff19b3..037f41d 100644 --- a/Classes/Controller/RecyclerAjaxController.php +++ b/Classes/Controller/RecyclerAjaxController.php @@ -19,6 +19,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Backend\History\RecordHistory; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\BackendViewFactory; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; @@ -160,6 +161,7 @@ protected function transform(array $deletedRowsArray): array $groupedRecords = []; $lang = $this->getLanguageService(); + $recordHistory = GeneralUtility::makeInstance(RecordHistory::class); foreach ($deletedRowsArray as $table => $rows) { $groupedRecords[$table]['information'] = [ 'table' => $table, @@ -167,7 +169,9 @@ protected function transform(array $deletedRowsArray): array ]; foreach ($rows as $row) { $pageTitle = $this->getPageTitle((int)$row['pid']); - $backendUserName = $this->getBackendUserInformation((int)$row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']]); + $ownerInformation = $recordHistory->getCreationInformationForRecord($table, $row); + $ownerUid = (int)(is_array($ownerInformation) && $ownerInformation['actiontype'] === 'BE' ? $ownerInformation['userid'] : 0); + $backendUserName = $this->getBackendUserInformation($ownerUid); $userIdWhoDeleted = $this->getUserWhoDeleted($table, (int)$row['uid']); $groupedRecords[$table]['records'][] = [ @@ -178,7 +182,7 @@ protected function transform(array $deletedRowsArray): array 'crdate' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['crdate']]), 'tstamp' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['tstamp']]), 'owner' => $backendUserName, - 'owner_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], + 'owner_uid' => $ownerUid, 'title' => BackendUtility::getRecordTitle($table, $row), 'path' => $this->getRecordPath((int)$row['pid']), 'delete_user_uid' => $userIdWhoDeleted, @@ -237,6 +241,7 @@ protected function getBackendUserInformation(int $userId): string /** * Get the user uid of the user who deleted the record + * @todo: move this to RecordHistory class */ protected function getUserWhoDeleted(string $table, int $uid): int { diff --git a/Tests/Functional/Fixtures/Database/be_groups.csv b/Tests/Functional/Fixtures/Database/be_groups.csv index 713d486..99150d7 100644 --- a/Tests/Functional/Fixtures/Database/be_groups.csv +++ b/Tests/Functional/Fixtures/Database/be_groups.csv @@ -1,3 +1,3 @@ -be_groups,,,,,,, -,uid,pid,tstamp,title,tables_modify,crdate,cruser_id -,1,0,1452959228,editor-group,pages,1452959228,1 +be_groups,,,,,, +,uid,pid,tstamp,title,tables_modify,crdate +,1,0,1452959228,editor-group,pages,1452959228 diff --git a/Tests/Functional/Fixtures/Database/be_users.csv b/Tests/Functional/Fixtures/Database/be_users.csv index 99f58b9..034252e 100644 --- a/Tests/Functional/Fixtures/Database/be_users.csv +++ b/Tests/Functional/Fixtures/Database/be_users.csv @@ -1,4 +1,4 @@ "be_users" -,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","cruser_id","workspace_perms","deleted","lastlogin","workspace_id","db_mountpoints","usergroup" -,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,0,1,0,1371033743,0,"","" -,2,0,1452944912,"editor","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",0,0,0,0,0,1452944912,1,1,0,1452944915,0,"1","1" +,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","lastlogin","workspace_id","db_mountpoints","usergroup" +,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,1371033743,0,"","" +,2,0,1452944912,"editor","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",0,0,0,0,0,1452944912,1,0,1452944915,0,"1","1"