first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -0,0 +1,344 @@
<?php
namespace TYPO3\CMS\Belog\Domain\Model;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Constraints for log entries
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
*/
class Constraint
{
/**
* Selected user/group; possible values are "gr-<uid>" for a group, "us-<uid>" for a user or -1 for "all users"
*
* @var string
*/
protected $userOrGroup = '0';
/**
* Number of log rows to show
*
* @var int
*/
protected $number = 20;
/**
* UID of selected workspace
*
* @var int
*/
protected $workspaceUid = \TYPO3\CMS\Belog\Domain\Model\Workspace::UID_ANY_WORKSPACE;
/**
* Selected time frame
*
* @var int
*/
protected $timeFrame = 0;
/**
* Selected action
*
* @var int
*/
protected $action = 0;
/**
* Whether rows should be grouped by page
*
* @var bool
*/
protected $groupByPage = false;
/**
* Calculated start timestamp
*
* @var int
*/
protected $startTimestamp = 0;
/**
* Calculated end timestamp
*
* @var int
*/
protected $endTimestamp = 0;
/**
* Manual date start
* @var \DateTime
*/
protected $manualDateStart;
/**
* Manual date stop
* @var \DateTime
*/
protected $manualDateStop;
/**
* Selected page ID in page context
*
* @var int
*/
protected $pageId = 0;
/**
* Page level depth
*
* @var int
*/
protected $depth = 0;
/**
* Set user
*
* @param string $user
*/
public function setUserOrGroup($user)
{
$this->userOrGroup = $user;
}
/**
* Get user
*
* @return string
*/
public function getUserOrGroup()
{
return $this->userOrGroup;
}
/**
* Set number of log rows to show
*
* @param int $number
*/
public function setNumber($number)
{
$this->number = (int)$number;
}
/**
* Get number of log entries to show
*
* @return int
*/
public function getNumber()
{
return $this->number;
}
/**
* Set workspace
*
* @param string $workspace
*/
public function setWorkspaceUid($workspace)
{
$this->workspaceUid = $workspace;
}
/**
* Get workspace
*
* @return string
*/
public function getWorkspaceUid()
{
return $this->workspaceUid;
}
/**
* Set time frame
*
* @param int $timeFrame
*/
public function setTimeFrame($timeFrame)
{
$this->timeFrame = $timeFrame;
}
/**
* Get time frame
*
* @return int
*/
public function getTimeFrame()
{
return (int)$this->timeFrame;
}
/**
* Set action
*
* @param int $action
*/
public function setAction($action)
{
$this->action = $action;
}
/**
* Get action
*
* @return int
*/
public function getAction()
{
return (int)$this->action;
}
/**
* Set group by page
*
* @param bool $groupByPage
*/
public function setGroupByPage($groupByPage)
{
$this->groupByPage = $groupByPage;
}
/**
* Get group by page
*
* @return bool
*/
public function getGroupByPage()
{
return (bool)$this->groupByPage;
}
/**
* Set calculated start timestamp from query constraints
*
* @param int $timestamp
*/
public function setStartTimestamp($timestamp)
{
$this->startTimestamp = (int)$timestamp;
}
/**
* Get calculated start timestamp from query constraints
*
* @return int
*/
public function getStartTimestamp()
{
return $this->startTimestamp;
}
/**
* Set calculated end timestamp from query constraints
*
* @param int $timestamp
*/
public function setEndTimestamp($timestamp)
{
$this->endTimestamp = (int)$timestamp;
}
/**
* Get calculated end timestamp from query constraints
*
* @return int
*/
public function getEndTimestamp()
{
return $this->endTimestamp;
}
/**
* Set page id
*
* @param int $id
*/
public function setPageId($id)
{
$this->pageId = (int)$id;
}
/**
* Get page id
*
* @return int
*/
public function getPageId()
{
return $this->pageId;
}
/**
* Set page level depth
*
* @param int $depth
*/
public function setDepth($depth)
{
$this->depth = $depth;
}
/**
* Get page level depth
*
* @return int
*/
public function getDepth()
{
return (int)$this->depth;
}
/**
* Set manual date start
*
* @param \DateTime $manualDateStart
*/
public function setManualDateStart(\DateTime $manualDateStart = null)
{
$this->manualDateStart = $manualDateStart;
}
/**
* Get manual date start
*
* @return \DateTime
*/
public function getManualDateStart()
{
return $this->manualDateStart;
}
/**
* Set manual date stop
*
* @param \DateTime $manualDateStop
*/
public function setManualDateStop(\DateTime $manualDateStop = null)
{
$this->manualDateStop = $manualDateStop;
}
/**
* Get manual date stop
*
* @return \DateTime
*/
public function getManualDateStop()
{
return $this->manualDateStop;
}
}
@@ -0,0 +1,489 @@
<?php
namespace TYPO3\CMS\Belog\Domain\Model;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* A sys log entry
* This model is 'complete': All current database properties are in there.
*
* @todo : This should be stuffed to some more central place
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
*/
class LogEntry extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* Storage page ID of the log entry
*
* @var int
*/
protected $pid = 0;
/**
* This is not a relation to BeUser model, since the user does
* not always exist, but we want the uid in then anyway.
* This case is ugly in extbase, the best way we
* have found now is to resolve the username (if it exists) in a
* view helper and just use the uid of the be user here.
*
* @var int
*/
protected $backendUserUid = 0;
/**
* Action ID of the action that happened, for example 3 was a file action
*
* @var int
*/
protected $action = 0;
/**
* UID of the record the event happened to
*
* @var int
*/
protected $recordUid = 0;
/**
* Table name
*
* @var string
*/
protected $tableName = 0;
/**
* PID of the record the event happened to
*
* @var int
*/
protected $recordPid = 0;
/**
* Error code
*
* @var int
*/
protected $error = 0;
/**
* This is the log message itself, but possibly with %s substitutions.
*
* @var string
*/
protected $details = '';
/**
* Timestamp when the log entry was written
*
* @var int
*/
protected $tstamp = 0;
/**
* Type code
*
* @var int
*/
protected $type = 0;
/**
* Details number
*
* @var int
*/
protected $detailsNumber = 0;
/**
* IP address of client
*
* @var string
*/
protected $ip = '';
/**
* Serialized log data. This is a serialized array with substitutions for $this->details.
*
* @var string
*/
protected $logData = '';
/**
* Event PID
*
* @var int
*/
protected $eventPid = 0;
/**
* This is only the UID and not the full workspace object for the same reason as in $beUserUid.
*
* @var int
*/
protected $workspaceUid = 0;
/**
* New ID
*
* @var string
*/
protected $newId = 0;
/**
* Set pid
*
* @param int $pid
*/
public function setPid($pid)
{
$this->pid = (int)$pid;
}
/**
* Get pid
*
* @return int
*/
public function getPid()
{
return $this->pid;
}
/**
* Set backend user uid
*
* @param int $beUserUid
*/
public function setBackendUserUid($beUserUid)
{
$this->backendUserUid = $beUserUid;
}
/**
* Get backend user id
*
* @return int
*/
public function getBackendUserUid()
{
return $this->backendUserUid;
}
/**
* Set action
*
* @param int $action
*/
public function setAction($action)
{
$this->action = $action;
}
/**
* Get action
*
* @return int
*/
public function getAction()
{
return (int)$this->action;
}
/**
* Set record uid
*
* @param int $recordUid
*/
public function setRecordUid($recordUid)
{
$this->recordUid = $recordUid;
}
/**
* Get record uid
*
* @return int
*/
public function getRecordUid()
{
return (int)$this->recordUid;
}
/**
* Set table name
*
* @param string $tableName
*/
public function setTableName($tableName)
{
$this->tableName = $tableName;
}
/**
* Get table name
*
* @return string
*/
public function getTableName()
{
return $this->tableName;
}
/**
* Set record pid
*
* @param int $recordPid
*/
public function setRecordPid($recordPid)
{
$this->recordPid = $recordPid;
}
/**
* Get record pid
*
* @return int
*/
public function getRecordPid()
{
return (int)$this->recordPid;
}
/**
* Set error
*
* @param int $error
*/
public function setError($error)
{
$this->error = $error;
}
/**
* Get error
*
* @return int
*/
public function getError()
{
return (int)$this->error;
}
/**
* Get class name for the error code
*
* @return string
*/
public function getErrorIconClass(): string
{
switch ($this->getError()) {
case 1:
return 'status-dialog-warning';
case 2:
case 3:
return 'status-dialog-error';
default:
return 'empty-empty';
}
}
/**
* Set details
*
* @param string $details
*/
public function setDetails($details)
{
$this->details = $details;
}
/**
* Get details
*
* @return string
*/
public function getDetails()
{
if ($this->type === 255) {
return str_replace('###IP###', $this->ip, $this->details);
}
return $this->details;
}
/**
* Set tstamp
*
* @param int $tstamp
*/
public function setTstamp($tstamp)
{
$this->tstamp = $tstamp;
}
/**
* Get tstamp
*
* @return int
*/
public function getTstamp()
{
return (int)$this->tstamp;
}
/**
* Set type
*
* @param int $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* Get type
*
* @return int
*/
public function getType()
{
return (int)$this->type;
}
/**
* Set details number
*
* @param int $detailsNumber
*/
public function setDetailsNumber($detailsNumber)
{
$this->detailsNumber = $detailsNumber;
}
/**
* Get details number
*
* @return int
*/
public function getDetailsNumber()
{
return (int)$this->detailsNumber;
}
/**
* Set ip
*
* @param string $ip
*/
public function setIp($ip)
{
$this->ip = $ip;
}
/**
* Get ip
*
* @return string
*/
public function getIp()
{
return $this->ip;
}
/**
* Set log data
*
* @param string $logData
*/
public function setLogData($logData)
{
$this->logData = $logData;
}
/**
* Get log data
*
* @return array
*/
public function getLogData()
{
if ($this->logData === '') {
return [];
}
$logData = @unserialize($this->logData);
if (!is_array($logData)) {
$logData = [];
}
return $logData;
}
/**
* Set event pid
*
* @param int $eventPid
*/
public function setEventPid($eventPid)
{
$this->eventPid = $eventPid;
}
/**
* Get event pid
*
* @return int
*/
public function getEventPid()
{
return (int)$this->eventPid;
}
/**
* Set workspace uid
*
* @param int $workspaceUid
*/
public function setWorkspaceUid($workspaceUid)
{
$this->workspaceUid = $workspaceUid;
}
/**
* Get workspace
*
* @return int
*/
public function getWorkspaceUid()
{
return (int)$this->workspaceUid;
}
/**
* Set new id
*
* @param string $newId
*/
public function setNewId($newId)
{
$this->newId = $newId;
}
/**
* Get new id
*
* @return string
*/
public function getNewId()
{
return $this->newId;
}
}
@@ -0,0 +1,61 @@
<?php
namespace TYPO3\CMS\Belog\Domain\Model;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Stub model for workspaces - only properties required for belog module are added currently
*
* @todo : This should be extended and put at some more central place
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
*/
class Workspace extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* @var int
*/
const UID_LIVE_WORKSPACE = 0;
/**
* @var int
*/
const UID_ANY_WORKSPACE = -99;
/**
* title of the workspace
*
* @var string
*/
protected $title = '';
/**
* Set workspace title
*
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get workspace title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
}
@@ -0,0 +1,190 @@
<?php
namespace TYPO3\CMS\Belog\Domain\Repository;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Belog\Domain\Model\LogEntry;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Sys log entry repository
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
*/
class LogEntryRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/**
* Backend users, with UID as key
*
* @var array
*/
protected $beUserList = [];
/**
* Initialize some local variables to be used during creation of objects
*/
public function initializeObject()
{
$this->beUserList = $this->getBackendUsers();
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings */
$defaultQuerySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
$defaultQuerySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($defaultQuerySettings);
}
/**
* Finds all log entries that match all given constraints.
*
* @param \TYPO3\CMS\Belog\Domain\Model\Constraint $constraint
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface<\TYPO3\CMS\Belog\Domain\Model\LogEntry>
*/
public function findByConstraint(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint)
{
$query = $this->createQuery();
$queryConstraints = $this->createQueryConstraints($query, $constraint);
if (!empty($queryConstraints)) {
$query->matching($query->logicalAnd($queryConstraints));
}
$query->setOrderings(['uid' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING]);
$query->setLimit($constraint->getNumber());
return $query->execute();
}
/**
* Create an array of query constraints from constraint object
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @param \TYPO3\CMS\Belog\Domain\Model\Constraint $constraint
* @return array<\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface>
*/
protected function createQueryConstraints(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, \TYPO3\CMS\Belog\Domain\Model\Constraint $constraint)
{
$queryConstraints = [];
// User / group handling
$this->addUsersAndGroupsToQueryConstraints($constraint, $query, $queryConstraints);
// Workspace
if ($constraint->getWorkspaceUid() != \TYPO3\CMS\Belog\Domain\Model\Workspace::UID_ANY_WORKSPACE) {
$queryConstraints[] = $query->equals('workspace', $constraint->getWorkspaceUid());
}
// Action (type):
if ($constraint->getAction() > 0) {
$queryConstraints[] = $query->equals('type', $constraint->getAction());
} elseif ($constraint->getAction() == -1) {
$queryConstraints[] = $query->equals('type', 5);
}
// Start / endtime handling: The timestamp calculation was already done
// in the controller, since we need those calculated values in the view as well.
$queryConstraints[] = $query->greaterThanOrEqual('tstamp', $constraint->getStartTimestamp());
$queryConstraints[] = $query->lessThan('tstamp', $constraint->getEndTimestamp());
// Page and level constraint if in page context
$this->addPageTreeConstraintsToQuery($constraint, $query, $queryConstraints);
return $queryConstraints;
}
/**
* Adds constraints for the page(s) to the query; this could be one single page or a whole subtree beneath a given
* page.
*
* @param \TYPO3\CMS\Belog\Domain\Model\Constraint $constraint
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @param array &$queryConstraints the query constraints to add to, will be modified
*/
protected function addPageTreeConstraintsToQuery(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$queryConstraints)
{
$pageIds = [];
// Check if we should get a whole tree of pages and not only a single page
if ($constraint->getDepth() > 0) {
/** @var \TYPO3\CMS\Backend\Tree\View\PageTreeView $pageTree */
$pageTree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageTreeView::class);
$pageTree->init('AND ' . $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW));
$pageTree->makeHTML = 0;
$pageTree->fieldArray = ['uid'];
$pageTree->getTree($constraint->getPageId(), $constraint->getDepth());
$pageIds = $pageTree->ids;
}
if (!empty($constraint->getPageId())) {
$pageIds[] = $constraint->getPageId();
}
if (!empty($pageIds)) {
$queryConstraints[] = $query->in('eventPid', $pageIds);
}
}
/**
* Adds users and groups to the query constraints.
*
* @param \TYPO3\CMS\Belog\Domain\Model\Constraint $constraint
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @param array &$queryConstraints the query constraints to add to, will be modified
*/
protected function addUsersAndGroupsToQueryConstraints(\TYPO3\CMS\Belog\Domain\Model\Constraint $constraint, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$queryConstraints)
{
$userOrGroup = $constraint->getUserOrGroup();
if ($userOrGroup === '') {
return;
}
// Constraint for a group
if (strpos($userOrGroup, 'gr-') === 0) {
$groupId = (int)substr($userOrGroup, 3);
$userIds = [];
foreach ($this->beUserList as $userId => $userData) {
if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($userData['usergroup_cached_list'], $groupId)) {
$userIds[] = $userId;
}
}
if (!empty($userIds)) {
$queryConstraints[] = $query->in('userid', $userIds);
} else {
// If there are no group members -> use -1 as constraint to not find anything
$queryConstraints[] = $query->in('userid', [-1]);
}
} elseif (strpos($userOrGroup, 'us-') === 0) {
$queryConstraints[] = $query->equals('userid', (int)substr($userOrGroup, 3));
} elseif ($userOrGroup === '-1') {
$queryConstraints[] = $query->equals('userid', (int)$GLOBALS['BE_USER']->user['uid']);
}
}
/**
* Deletes all messages which have the same message details
*
* @param LogEntry $logEntry
* @return int
*/
public function deleteByMessageDetails(LogEntry $logEntry): int
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_log');
$constraints = [];
$constraints[] = $queryBuilder->expr()->eq('details', $queryBuilder->createNamedParameter($logEntry->getDetails()));
// If the detailsNo is 11 or 12 we got messages that are heavily using placeholders. In this case
// we need to compare both the message and the actual log data to not remove too many log entries.
if (GeneralUtility::inList('11,12', $logEntry->getDetailsNumber())) {
$constraints[] = $queryBuilder->expr()->eq('log_data', $queryBuilder->createNamedParameter($logEntry->getLogData()));
}
return $queryBuilder->delete('sys_log')
->where(...$constraints)
->execute();
}
/**
* Get a list of all backend users that are not deleted
*
* @return array
*/
protected function getBackendUsers()
{
return \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
}
}
@@ -0,0 +1,34 @@
<?php
namespace TYPO3\CMS\Belog\Domain\Repository;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Repository for workspaces
* @todo This should be moved to EXT:workspaces if EXT:belog works no matter if workspaces are installed or not
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
*/
class WorkspaceRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/**
* Initializes the repository.
*/
public function initializeObject()
{
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings */
$querySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
$querySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($querySettings);
}
}