‪TYPO3CMS  9.5
DeletedRecordsController.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
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  if ($this->runtimeCache->has($cacheId)) {
106  $pageTitle = $this->runtimeCache->get($cacheId);
107  } else {
108  if ($pageId === 0) {
109  $pageTitle = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
110  } else {
111  $recordInfo = $this->tce->recordInfo('pages', $pageId, 'title');
112  $pageTitle = $recordInfo['title'];
113  }
114  $this->runtimeCache->set($cacheId, $pageTitle);
115  }
116  return $pageTitle;
117  }
118 
125  protected function ‪getBackendUser(int $userId): string
126  {
127  if ($userId === 0) {
128  return '';
129  }
130  $cacheId = 'recycler-user-' . $userId;
131  if ($this->runtimeCache->has($cacheId)) {
132  $username = $this->runtimeCache->get($cacheId);
133  } else {
134  $backendUser = ‪BackendUtility::getRecord('be_users', $userId, 'username', '', false);
135  if ($backendUser === null) {
136  $username = sprintf(
137  '[%s]',
138  ‪LocalizationUtility::translate('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:record.deleted')
139  );
140  } else {
141  $username = $backendUser['username'];
142  }
143  $this->runtimeCache->set($cacheId, $username);
144  }
145  return $username;
146  }
147 
155  protected function ‪getUserWhoDeleted(string $table, int $uid): int
156  {
157  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
158  ->getQueryBuilderForTable('sys_history');
159  $queryBuilder->select('userid')
160  ->from('sys_history')
161  ->where(
162  $queryBuilder->expr()->eq(
163  'tablename',
164  $queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
165  ),
166  $queryBuilder->expr()->eq(
167  'usertype',
168  $queryBuilder->createNamedParameter('BE', \PDO::PARAM_STR)
169  ),
170  $queryBuilder->expr()->eq(
171  'recuid',
172  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
173  ),
174  $queryBuilder->expr()->eq(
175  'actiontype',
176  $queryBuilder->createNamedParameter(‪RecordHistoryStore::ACTION_DELETE, \PDO::PARAM_INT)
177  )
178  )
179  ->setMaxResults(1);
180 
181  return (int)$queryBuilder->execute()->fetchColumn(0);
182  }
183 
189  protected function ‪getLanguageService()
190  {
191  return ‪$GLOBALS['LANG'];
192  }
193 
199  protected function ‪getCacheManager()
200  {
201  return GeneralUtility::makeInstance(CacheManager::class);
202  }
203 
209  protected function ‪getMemoryCache()
210  {
211  return $this->‪getCacheManager()->‪getCache('cache_runtime');
212  }
213 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪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:129
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:29
‪TYPO3\CMS\Backend\Utility\BackendUtility\datetime
‪static string datetime($value)
Definition: BackendUtility.php:1190
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getRecordPath
‪static string getRecordPath($uid)
Definition: RecyclerUtility.php:83
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\transform
‪array transform($deletedRowsArray)
Definition: DeletedRecordsController.php:55
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪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:153
‪TYPO3\CMS\Recycler\Controller
Definition: DeletedRecordsController.php:3
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore
Definition: RecordHistoryStore.php:28
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: DeletedRecordsController.php:187
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getMemoryCache
‪TYPO3 CMS Core Cache Frontend FrontendInterface getMemoryCache()
Definition: DeletedRecordsController.php:207
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1811
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getCacheManager
‪CacheManager getCacheManager()
Definition: DeletedRecordsController.php:197
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\getBackendUser
‪string getBackendUser(int $userId)
Definition: DeletedRecordsController.php:123
‪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:142
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\ACTION_DELETE
‪const ACTION_DELETE
Definition: RecordHistoryStore.php:32
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility
Definition: RecyclerUtility.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Recycler\Controller\DeletedRecordsController\__construct
‪__construct()
Definition: DeletedRecordsController.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45