‪TYPO3CMS  10.4
RecordService.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 
23 
28 {
32  protected ‪$records = [];
33 
38  public function ‪add($tableName, $id)
39  {
40  $databaseRecord = ‪DatabaseRecord::create($tableName, $id);
41  if (!isset($this->records[$databaseRecord->getIdentifier()])) {
42  $this->records[$databaseRecord->getIdentifier()] = $databaseRecord;
43  }
44  }
45 
49  public function ‪getIdsPerTable()
50  {
51  $idsPerTable = [];
52  foreach ($this->records as $databaseRecord) {
53  if (!isset($idsPerTable[$databaseRecord->getTable()])) {
54  $idsPerTable[$databaseRecord->getTable()] = [];
55  }
56  $idsPerTable[$databaseRecord->getTable()][] = $databaseRecord->getUid();
57  }
58  return $idsPerTable;
59  }
60 
64  public function ‪getCreateUserIds()
65  {
66  $createUserIds = [];
67  foreach ($this->‪getIdsPerTable() as $tableName => $ids) {
68  if (empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['cruser_id'])) {
69  continue;
70  }
71  $createUserIdFieldName = ‪$GLOBALS['TCA'][$tableName]['ctrl']['cruser_id'];
72 
73  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
74  $queryBuilder->getRestrictions()->removeAll();
75 
76  ‪$records = $queryBuilder
77  ->select($createUserIdFieldName)
78  ->from($tableName)
79  ->where(
80  $queryBuilder->expr()->in(
81  'uid',
82  $queryBuilder->createNamedParameter($ids, Connection::PARAM_INT_ARRAY)
83  )
84  )
85  ->groupBy($createUserIdFieldName)
86  ->execute()
87  ->fetchAll();
88 
89  ‪$records = array_column(‪$records, $createUserIdFieldName);
90 
91  if (!empty(‪$records)) {
92  $createUserIds = array_merge($createUserIds, ‪$records);
93  }
94  }
95  return array_unique($createUserIds);
96  }
97 }
‪TYPO3\CMS\Workspaces\Service\RecordService\getIdsPerTable
‪array getIdsPerTable()
Definition: RecordService.php:48
‪TYPO3\CMS\Workspaces\Service\RecordService\add
‪add($tableName, $id)
Definition: RecordService.php:37
‪TYPO3\CMS\Workspaces\Service
Definition: AdditionalColumnService.php:16
‪TYPO3\CMS\Workspaces\Service\RecordService\$records
‪DatabaseRecord[] $records
Definition: RecordService.php:31
‪TYPO3\CMS\Workspaces\Service\RecordService\getCreateUserIds
‪array getCreateUserIds()
Definition: RecordService.php:63
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord
Definition: DatabaseRecord.php:25
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Workspaces\Service\RecordService
Definition: RecordService.php:28
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\create
‪static DatabaseRecord create($table, $uid)
Definition: DatabaseRecord.php:45