‪TYPO3CMS  10.4
DeletedRecordsController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
28 
34 {
38  protected ‪$runtimeCache;
39 
43  protected ‪$tce;
44 
45  public function ‪__construct()
46  {
47  $this->runtimeCache = $this->‪getMemoryCache();
48  $this->tce = GeneralUtility::makeInstance(DataHandler::class);
49  }
50 
57  public function ‪transform($deletedRowsArray)
58  {
59  $jsonArray = [
60  'rows' => []
61  ];
62 
63  if (is_array($deletedRowsArray)) {
64  $lang = $this->‪getLanguageService();
65  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
66 
67  foreach ($deletedRowsArray as $table => $rows) {
68  foreach ($rows as $row) {
69  $pageTitle = $this->‪getPageTitle((int)$row['pid']);
70  $backendUserName = $this->‪getBackendUser((int)$row[‪$GLOBALS['TCA'][$table]['ctrl']['cruser_id']]);
71  $userIdWhoDeleted = $this->‪getUserWhoDeleted($table, (int)$row['uid']);
72 
73  $jsonArray['rows'][] = [
74  'uid' => $row['uid'],
75  'pid' => $row['pid'],
76  'icon' => $iconFactory->getIconForRecord($table, $row, ‪Icon::SIZE_SMALL)->render(),
77  'pageTitle' => $pageTitle,
78  'table' => $table,
79  'crdate' => ‪BackendUtility::datetime($row[‪$GLOBALS['TCA'][$table]['ctrl']['crdate']]),
80  'tstamp' => ‪BackendUtility::datetime($row[‪$GLOBALS['TCA'][$table]['ctrl']['tstamp']]),
81  'owner' => htmlspecialchars($backendUserName),
82  'owner_uid' => $row[‪$GLOBALS['TCA'][$table]['ctrl']['cruser_id']],
83  'tableTitle' => $lang->sL(‪$GLOBALS['TCA'][$table]['ctrl']['title']),
84  'title' => htmlspecialchars(‪BackendUtility::getRecordTitle($table, $row)),
85  'path' => ‪RecyclerUtility::getRecordPath($row['pid']),
86  'delete_user_uid' => $userIdWhoDeleted,
87  'delete_user' => $this->‪getBackendUser($userIdWhoDeleted),
88  'isParentDeleted' => $table === 'pages' ? ‪RecyclerUtility::isParentPageDeleted($row['pid']) : false
89  ];
90  }
91  }
92  }
93  return $jsonArray;
94  }
95 
102  protected function ‪getPageTitle($pageId)
103  {
104  $cacheId = 'recycler-pagetitle-' . $pageId;
105  $pageTitle = $this->runtimeCache->get($cacheId);
106  if ($pageTitle === false) {
107  if ($pageId === 0) {
108  $pageTitle = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
109  } else {
110  $recordInfo = $this->tce->recordInfo('pages', $pageId, 'title');
111  $pageTitle = $recordInfo['title'];
112  }
113  $this->runtimeCache->set($cacheId, $pageTitle);
114  }
115  return $pageTitle;
116  }
117 
124  protected function ‪getBackendUser(int $userId): string
125  {
126  if ($userId === 0) {
127  return '';
128  }
129  $cacheId = 'recycler-user-' . $userId;
130  $username = $this->runtimeCache->get($cacheId);
131  if ($username === false) {
132  $backendUser = ‪BackendUtility::getRecord('be_users', $userId, 'username', '', false);
133  if ($backendUser === null) {
134  $username = sprintf(
135  '[%s]',
136  ‪LocalizationUtility::translate('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:record.deleted')
137  );
138  } else {
139  $username = $backendUser['username'];
140  }
141  $this->runtimeCache->set($cacheId, $username);
142  }
143  return $username;
144  }
145 
153  protected function ‪getUserWhoDeleted(string $table, int $uid): int
154  {
155  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
156  ->getQueryBuilderForTable('sys_history');
157  $queryBuilder->select('userid')
158  ->from('sys_history')
159  ->where(
160  $queryBuilder->expr()->eq(
161  'tablename',
162  $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
163  ),
164  $queryBuilder->expr()->eq(
165  'usertype',
166  $queryBuilder->createNamedParameter('BE', \PDO::PARAM_STR)
167  ),
168  $queryBuilder->expr()->eq(
169  'recuid',
170  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
171  ),
172  $queryBuilder->expr()->eq(
173  'actiontype',
174  $queryBuilder->createNamedParameter(‪RecordHistoryStore::ACTION_DELETE, \PDO::PARAM_INT)
175  )
176  )
177  ->setMaxResults(1);
178 
179  return (int)$queryBuilder->execute()->fetchColumn(0);
180  }
181 
187  protected function ‪getLanguageService()
188  {
189  return ‪$GLOBALS['LANG'];
190  }
191 
197  protected function ‪getCacheManager()
198  {
199  return GeneralUtility::makeInstance(CacheManager::class);
200  }
201 
207  protected function ‪getMemoryCache()
208  {
209  return $this->‪getCacheManager()->‪getCache('runtime');
210  }
211 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\$runtimeCache
‪TYPO3 CMS Core Cache Frontend FrontendInterface $runtimeCache
Definition: DeletedRecordsController.php:37
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController
Definition: DeletedRecordsController.php:34
‪TYPO3\CMS\Core\Cache\CacheManager\getCache
‪FrontendInterface getCache($identifier)
Definition: CacheManager.php:141
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Backend\Utility\BackendUtility\datetime
‪static string datetime($value)
Definition: BackendUtility.php:989
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getRecordPath
‪static string getRecordPath($uid)
Definition: RecyclerUtility.php:84
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\transform
‪array transform($deletedRowsArray)
Definition: DeletedRecordsController.php:55
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getPageTitle
‪string getPageTitle($pageId)
Definition: DeletedRecordsController.php:100
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getUserWhoDeleted
‪int getUserWhoDeleted(string $table, int $uid)
Definition: DeletedRecordsController.php:151
‪TYPO3\CMS\Recycler\Controller
Definition: DeletedRecordsController.php:16
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore
Definition: RecordHistoryStore.php:31
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: DeletedRecordsController.php:185
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getMemoryCache
‪TYPO3 CMS Core Cache Frontend FrontendInterface getMemoryCache()
Definition: DeletedRecordsController.php:205
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getCacheManager
‪CacheManager getCacheManager()
Definition: DeletedRecordsController.php:195
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getBackendUser
‪string getBackendUser(int $userId)
Definition: DeletedRecordsController.php:122
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\$tce
‪DataHandler $tce
Definition: DeletedRecordsController.php:41
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\isParentPageDeleted
‪static bool isParentPageDeleted($pid)
Definition: RecyclerUtility.php:143
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\ACTION_DELETE
‪const ACTION_DELETE
Definition: RecordHistoryStore.php:35
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility
Definition: RecyclerUtility.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\__construct
‪__construct()
Definition: DeletedRecordsController.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46