‪TYPO3CMS  10.4
LogEntryRepository.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 
29 
35 {
41  protected ‪$beUserList = [];
42 
46  public function ‪initializeObject()
47  {
48  $this->beUserList = $this->‪getBackendUsers();
50  ‪$defaultQuerySettings = $this->objectManager->get(QuerySettingsInterface::class);
53  }
54 
61  public function ‪findByConstraint(‪Constraint $constraint)
62  {
63  $query = $this->‪createQuery();
64  $queryConstraints = $this->‪createQueryConstraints($query, $constraint);
65  if (!empty($queryConstraints)) {
66  $query->matching($query->logicalAnd($queryConstraints));
67  }
68  $query->setOrderings(['uid' => ‪QueryInterface::ORDER_DESCENDING]);
69  $query->setLimit($constraint->‪getNumber());
70  return $query->execute();
71  }
72 
80  protected function ‪createQueryConstraints(‪QueryInterface $query, ‪Constraint $constraint)
81  {
82  $queryConstraints = [];
83  // User / group handling
84  $this->‪addUsersAndGroupsToQueryConstraints($constraint, $query, $queryConstraints);
85  // Workspace
87  $queryConstraints[] = $query->‪equals('workspace', $constraint->‪getWorkspaceUid());
88  }
89  // Action (type):
90  if ($constraint->‪getAction() > 0) {
91  $queryConstraints[] = $query->‪equals('type', $constraint->‪getAction());
92  } elseif ($constraint->‪getAction() == -1) {
93  $queryConstraints[] = $query->‪equals('type', 5);
94  }
95  // Start / endtime handling: The timestamp calculation was already done
96  // in the controller, since we need those calculated values in the view as well.
97  $queryConstraints[] = $query->‪greaterThanOrEqual('tstamp', $constraint->‪getStartTimestamp());
98  $queryConstraints[] = $query->‪lessThan('tstamp', $constraint->‪getEndTimestamp());
99  // Page and level constraint if in page context
100  $this->‪addPageTreeConstraintsToQuery($constraint, $query, $queryConstraints);
101  return $queryConstraints;
102  }
103 
112  protected function ‪addPageTreeConstraintsToQuery(‪Constraint $constraint, ‪QueryInterface $query, array &$queryConstraints)
113  {
114  $pageIds = [];
115  // Check if we should get a whole tree of pages and not only a single page
116  if ($constraint->‪getDepth() > 0) {
118  $pageTree = GeneralUtility::makeInstance(PageTreeView::class);
119  $pageTree->init('AND ' . ‪$GLOBALS['BE_USER']->getPagePermsClause(‪Permission::PAGE_SHOW));
120  $pageTree->makeHTML = 0;
121  $pageTree->fieldArray = ['uid'];
122  $pageTree->getTree($constraint->‪getPageId(), $constraint->‪getDepth());
123  $pageIds = $pageTree->ids;
124  }
125  if (!empty($constraint->‪getPageId())) {
126  $pageIds[] = $constraint->‪getPageId();
127  }
128  if (!empty($pageIds)) {
129  $queryConstraints[] = $query->‪in('eventPid', $pageIds);
130  }
131  }
132 
140  protected function ‪addUsersAndGroupsToQueryConstraints(‪Constraint $constraint, ‪QueryInterface $query, array &$queryConstraints)
141  {
142  $userOrGroup = $constraint->‪getUserOrGroup();
143  if ($userOrGroup === '') {
144  return;
145  }
146  // Constraint for a group
147  if (strpos($userOrGroup, 'gr-') === 0) {
148  $groupId = (int)substr($userOrGroup, 3);
149  $userIds = [];
150  foreach ($this->beUserList as $userId => $userData) {
151  if (GeneralUtility::inList($userData['usergroup_cached_list'], (string)$groupId)) {
152  $userIds[] = $userId;
153  }
154  }
155  if (!empty($userIds)) {
156  $queryConstraints[] = $query->‪in('userid', $userIds);
157  } else {
158  // If there are no group members -> use -1 as constraint to not find anything
159  $queryConstraints[] = $query->‪in('userid', [-1]);
160  }
161  } elseif (strpos($userOrGroup, 'us-') === 0) {
162  $queryConstraints[] = $query->‪equals('userid', (int)substr($userOrGroup, 3));
163  } elseif ($userOrGroup === '-1') {
164  $queryConstraints[] = $query->‪equals('userid', (int)‪$GLOBALS['BE_USER']->user['uid']);
165  }
166  }
167 
174  public function ‪deleteByMessageDetails(‪LogEntry $logEntry): int
175  {
176  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
177  ->getQueryBuilderForTable('sys_log');
178  $constraints = [];
179  $constraints[] = $queryBuilder->expr()->eq('details', $queryBuilder->createNamedParameter($logEntry->‪getDetails()));
180  // If the detailsNo is 11 or 12 we got messages that are heavily using placeholders. In this case
181  // we need to compare both the message and the actual log data to not remove too many log entries.
182  if (GeneralUtility::inList('11,12', (string)$logEntry->‪getDetailsNumber())) {
183  $constraints[] = $queryBuilder->expr()->eq('log_data', $queryBuilder->createNamedParameter($logEntry->‪getLogData()));
184  }
185  return $queryBuilder->delete('sys_log')
186  ->where(...$constraints)
187  ->execute();
188  }
189 
195  protected function ‪getBackendUsers()
196  {
198  }
199 }
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\findByConstraint
‪TYPO3 CMS Extbase Persistence QueryResultInterface findByConstraint(Constraint $constraint)
Definition: LogEntryRepository.php:60
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getAction
‪int getAction()
Definition: Constraint.php:189
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository
Definition: LogEntryRepository.php:35
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\initializeObject
‪initializeObject()
Definition: LogEntryRepository.php:45
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:29
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\equals
‪TYPO3 CMS Extbase Persistence Generic Qom ComparisonInterface equals($propertyName, $operand, $caseSensitive=true)
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getWorkspaceUid
‪string getWorkspaceUid()
Definition: Constraint.php:149
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_DESCENDING
‪const ORDER_DESCENDING
Definition: QueryInterface.php:99
‪TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface\setRespectStoragePage
‪TYPO3 CMS Extbase Persistence Generic QuerySettingsInterface setRespectStoragePage($respectStoragePage)
‪TYPO3\CMS\Belog\Domain\Model\Workspace
Definition: Workspace.php:27
‪TYPO3\CMS\Backend\Utility\BackendUtility\getUserNames
‪static array getUserNames($fields='username, usergroup, usergroup_cached_list, uid', $where='')
Definition: BackendUtility.php:818
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\addUsersAndGroupsToQueryConstraints
‪addUsersAndGroupsToQueryConstraints(Constraint $constraint, QueryInterface $query, array &$queryConstraints)
Definition: LogEntryRepository.php:139
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\$beUserList
‪array $beUserList
Definition: LogEntryRepository.php:40
‪TYPO3\CMS\Backend\Tree\View\PageTreeView
Definition: PageTreeView.php:24
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getDepth
‪int getDepth()
Definition: Constraint.php:289
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\lessThan
‪ComparisonInterface lessThan($propertyName, $operand)
‪TYPO3\CMS\Belog\Domain\Model\LogEntry\getLogData
‪array getLogData()
Definition: LogEntry.php:385
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\createQueryConstraints
‪array TYPO3 CMS Extbase Persistence Generic Qom ConstraintInterface[] createQueryConstraints(QueryInterface $query, Constraint $constraint)
Definition: LogEntryRepository.php:79
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\in
‪ComparisonInterface in($propertyName, $operand)
‪TYPO3\CMS\Belog\Domain\Model\LogEntry\getDetails
‪string getDetails()
Definition: LogEntry.php:282
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getEndTimestamp
‪int getEndTimestamp()
Definition: Constraint.php:249
‪TYPO3\CMS\Extbase\Persistence\Repository\createQuery
‪TYPO3 CMS Extbase Persistence QueryInterface createQuery()
Definition: Repository.php:204
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\getBackendUsers
‪array getBackendUsers()
Definition: LogEntryRepository.php:194
‪TYPO3\CMS\Extbase\Persistence\Repository\$defaultQuerySettings
‪TYPO3 CMS Extbase Persistence Generic QuerySettingsInterface $defaultQuerySettings
Definition: Repository.php:51
‪TYPO3\CMS\Extbase\Persistence\Repository
Definition: Repository.php:29
‪TYPO3\CMS\Extbase\Persistence\Repository\setDefaultQuerySettings
‪setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings)
Definition: Repository.php:194
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getStartTimestamp
‪int getStartTimestamp()
Definition: Constraint.php:229
‪TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
Definition: QuerySettingsInterface.php:22
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Belog\Domain\Model\LogEntry
Definition: LogEntry.php:28
‪TYPO3\CMS\Belog\Domain\Repository
Definition: LogEntryRepository.php:16
‪TYPO3\CMS\Belog\Domain\Model\Workspace\UID_ANY_WORKSPACE
‪const UID_ANY_WORKSPACE
Definition: Workspace.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\greaterThanOrEqual
‪ComparisonInterface greaterThanOrEqual($propertyName, $operand)
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getUserOrGroup
‪string getUserOrGroup()
Definition: Constraint.php:109
‪TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface
Definition: ConstraintInterface.php:25
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Belog\Domain\Model\Constraint
Definition: Constraint.php:23
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\addPageTreeConstraintsToQuery
‪addPageTreeConstraintsToQuery(Constraint $constraint, QueryInterface $query, array &$queryConstraints)
Definition: LogEntryRepository.php:111
‪TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository\deleteByMessageDetails
‪int deleteByMessageDetails(LogEntry $logEntry)
Definition: LogEntryRepository.php:173
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getNumber
‪int getNumber()
Definition: Constraint.php:129
‪TYPO3\CMS\Belog\Domain\Model\Constraint\getPageId
‪int getPageId()
Definition: Constraint.php:269
‪TYPO3\CMS\Belog\Domain\Model\LogEntry\getDetailsNumber
‪int getDetailsNumber()
Definition: LogEntry.php:345