‪TYPO3CMS  9.5
RecordService.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
21 
26 {
30  protected ‪$records = [];
31 
36  public function ‪add($tableName, $id)
37  {
38  $databaseRecord = ‪DatabaseRecord::create($tableName, $id);
39  if (!isset($this->records[$databaseRecord->getIdentifier()])) {
40  $this->records[$databaseRecord->getIdentifier()] = $databaseRecord;
41  }
42  }
43 
47  public function ‪getIdsPerTable()
48  {
49  $idsPerTable = [];
50  foreach ($this->records as $databaseRecord) {
51  if (!isset($idsPerTable[$databaseRecord->getTable()])) {
52  $idsPerTable[$databaseRecord->getTable()] = [];
53  }
54  $idsPerTable[$databaseRecord->getTable()][] = $databaseRecord->getUid();
55  }
56  return $idsPerTable;
57  }
58 
62  public function ‪getCreateUserIds()
63  {
64  $createUserIds = [];
65  foreach ($this->‪getIdsPerTable() as $tableName => $ids) {
66  if (empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['cruser_id'])) {
67  continue;
68  }
69  $createUserIdFieldName = ‪$GLOBALS['TCA'][$tableName]['ctrl']['cruser_id'];
70 
71  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
72  $queryBuilder->getRestrictions()->removeAll();
73 
74  ‪$records = $queryBuilder
75  ->select($createUserIdFieldName)
76  ->from($tableName)
77  ->where(
78  $queryBuilder->expr()->in(
79  'uid',
80  $queryBuilder->createNamedParameter($ids, Connection::PARAM_INT_ARRAY)
81  )
82  )
83  ->groupBy($createUserIdFieldName)
84  ->execute()
85  ->fetchAll();
86 
87  ‪$records = array_column(‪$records, $createUserIdFieldName);
88 
89  if (!empty(‪$records)) {
90  $createUserIds = array_merge($createUserIds, ‪$records);
91  }
92  }
93  return array_unique($createUserIds);
94  }
95 }
‪TYPO3\CMS\Workspaces\Service\RecordService\getIdsPerTable
‪array getIdsPerTable()
Definition: RecordService.php:46
‪TYPO3\CMS\Workspaces\Service\RecordService\add
‪add($tableName, $id)
Definition: RecordService.php:35
‪TYPO3\CMS\Workspaces\Service
Definition: AdditionalColumnService.php:2
‪TYPO3\CMS\Workspaces\Service\RecordService\$records
‪DatabaseRecord[] $records
Definition: RecordService.php:29
‪TYPO3\CMS\Workspaces\Service\RecordService\getCreateUserIds
‪array getCreateUserIds()
Definition: RecordService.php:61
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord
Definition: DatabaseRecord.php:24
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Workspaces\Service\RecordService
Definition: RecordService.php:26
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\create
‪static DatabaseRecord create($table, $uid)
Definition: DatabaseRecord.php:44