Commit 3cb5ff17 authored by Benni Mack's avatar Benni Mack Committed by Frank Nägler
Browse files

[TASK] Remove further evaluations of pid=-1

There are a few spots in TYPO3 Core where manual
queries are built, and the WorkspaceRestriction
would just work as dropin now.

In addition, some few changes are adapted to check
for t3ver_oid instead of "pid".

Resolves: #89157
Releases: master
Change-Id: I9d3a6f132ba20c0c603a6ab1664adf9d1dc06fd9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61669


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
Reviewed-by: Achim Fritz's avatarAchim Fritz <af@achimfritz.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
parent 4989d5af
......@@ -40,6 +40,7 @@ use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Database\ReferenceIndex;
use TYPO3\CMS\Core\Database\RelationHandler;
use TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore;
......@@ -4440,7 +4441,9 @@ class DataHandler implements LoggerAwareInterface
// In case the parent record is the default language record, fetch the localization
if (empty($parentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']])) {
// Fetch the live record
$parentRecordLocalization = BackendUtility::getRecordLocalization($table, $id, $command['language'], 'AND pid<>-1');
// @todo: this needs to be revisited, as getRecordLocalization() does a BackendWorkspaceRestriction
// based on $GLOBALS[BE_USER], which could differ from the $this->BE_USER->workspace value
$parentRecordLocalization = BackendUtility::getRecordLocalization($table, $id, $command['language'], 'AND t3ver_oid=0');
if (empty($parentRecordLocalization)) {
if ($this->enableLogging) {
$this->log($table, $id, 0, 0, 0, 'Localization for parent record ' . $table . ':' . $id . '" cannot be fetched', -1, [], $this->eventPid($table, $id, $parentRecord['pid']));
......@@ -5163,9 +5166,9 @@ class DataHandler implements LoggerAwareInterface
return null;
}
// Record must be online record
if ($row['pid'] < 0) {
$this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in archive (pid=-1)!', 1);
// Record must be online record, otherwise we would create a version of a version
if ($row['t3ver_oid'] ?? 0 > 0) {
$this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in archive (record has an online ID)!', 1);
return null;
}
......@@ -6457,10 +6460,11 @@ class DataHandler implements LoggerAwareInterface
{
if ($GLOBALS['TCA'][$table]) {
BackendUtility::fixVersioningPid($table, $row);
$liveUid = ($row['t3ver_oid'] ?? null) ? $row['t3ver_oid'] : $row['uid'];
return [
'header' => BackendUtility::getRecordTitle($table, $row),
'pid' => $row['pid'],
'event_pid' => $this->eventPid($table, ((int)($row['t3ver_oid'] ?? 0) > 0 ? $row['t3ver_oid'] : $row['uid']), $row['pid']),
'event_pid' => $this->eventPid($table, (int)$liveUid, $row['pid']),
't3ver_state' => BackendUtility::isTableWorkspaceEnabled($table) ? $row['t3ver_state'] : '',
'_ORIG_pid' => $row['_ORIG_pid']
];
......@@ -6537,7 +6541,8 @@ class DataHandler implements LoggerAwareInterface
}
// Set log entry:
$propArr = $this->getRecordPropertiesFromRow($table, $newRow);
$this->log($table, $id, 2, $propArr['pid'], 0, 'Record \'%s\' (%s) was updated.' . ($propArr['_ORIG_pid'] == -1 ? ' (Offline version).' : ' (Online).'), 10, [$propArr['header'], $table . ':' . $id, 'history' => $historyEntryId], $propArr['event_pid']);
$isOfflineVersion = (bool)($newRow['t3ver_oid'] ?? 0);
$this->log($table, $id, 2, $propArr['pid'], 0, 'Record \'%s\' (%s) was updated.' . ($isOfflineVersion ? ' (Offline version).' : ' (Online).'), 10, [$propArr['header'], $table . ':' . $id, 'history' => $historyEntryId], $propArr['event_pid']);
}
// Clear cache for relevant pages:
$this->registerRecordIdForPageCacheClearing($table, $id);
......@@ -6824,6 +6829,7 @@ class DataHandler implements LoggerAwareInterface
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($table);
$this->addDeleteRestriction($queryBuilder->getRestrictions()->removeAll());
$queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->BE_USER->workspace));
$queryBuilder
->select($sortColumn, 'pid', 'uid')
......@@ -6886,6 +6892,7 @@ class DataHandler implements LoggerAwareInterface
} else {
$queryBuilder = $connectionPool->getQueryBuilderForTable($table);
$this->addDeleteRestriction($queryBuilder->getRestrictions()->removeAll());
$queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->BE_USER->workspace));
$subResults = $queryBuilder
->select($sortColumn, 'pid', 'uid')
......
......@@ -18,6 +18,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\Platform\PlatformInformation;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\DataHandling\PlainDataResolver;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
......@@ -969,15 +970,8 @@ class RelationHandler
}
// Select children from the live(!) workspace only
if (BackendUtility::isTableWorkspaceEnabled($foreign_table)) {
$queryBuilder->andWhere(
$queryBuilder->expr()->in(
$foreign_table . '.t3ver_wsid',
$queryBuilder->createNamedParameter([0, (int)$this->getWorkspaceId()], Connection::PARAM_INT_ARRAY)
),
$queryBuilder->expr()->eq(
$foreign_table . '.t3ver_oid',
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
)
$queryBuilder->getRestrictions()->add(
GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getWorkspaceId())
);
}
// Get the correct sorting field
......
......@@ -234,7 +234,7 @@ class DataHandlerHook
$dataHandler->newlog('Tried to delete record from another workspace', 1);
}
} else {
$dataHandler->newlog('Versioning not enabled for record with PID = -1!', 2);
$dataHandler->newlog('Versioning not enabled for record with an online ID (t3ver_oid) given', 2);
}
} elseif ($res = $dataHandler->BE_USER->workspaceAllowLiveRecordsInPID($record['pid'], $table)) {
// Look, if record is "online" or in a versionized branch, then delete directly.
......@@ -1025,7 +1025,7 @@ class DataHandlerHook
$dataHandler->addRemapStackRefIndex($table, $id);
// Set log entry for live record:
$propArr = $dataHandler->getRecordPropertiesFromRow($table, $swapVersion);
if ($propArr['_ORIG_pid'] == -1) {
if ($propArr['t3ver_oid'] ?? 0 > 0) {
$label = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_tcemain.xlf:version_swap.offline_record_updated');
} else {
$label = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_tcemain.xlf:version_swap.online_record_updated');
......@@ -1036,7 +1036,7 @@ class DataHandlerHook
$dataHandler->addRemapStackRefIndex($table, $swapWith);
// Set log entry for offline record:
$propArr = $dataHandler->getRecordPropertiesFromRow($table, $curVersion);
if ($propArr['_ORIG_pid'] == -1) {
if ($propArr['t3ver_oid'] ?? 0 > 0) {
$label = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_tcemain.xlf:version_swap.offline_record_updated');
} else {
$label = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_tcemain.xlf:version_swap.online_record_updated');
......
......@@ -884,8 +884,8 @@ class WorkspaceService implements SingletonInterface
$workspaceId,
\PDO::PARAM_INT
);
$pageIdParameter = $queryBuilder->createNamedParameter(
-1,
$onlineVersionParameter = $queryBuilder->createNamedParameter(
0,
\PDO::PARAM_INT
);
// create sub-queries, parameters are available for main query
......@@ -894,7 +894,7 @@ class WorkspaceService implements SingletonInterface
->from($tableName, 'B')
->join('B', $tableName, 'A', $queryBuilder->expr()->eq('B.uid', $queryBuilder->quoteIdentifier('A.t3ver_oid')))
->where(
$queryBuilder->expr()->eq('A.pid', $pageIdParameter),
$queryBuilder->expr()->gt('A.t3ver_oid', $onlineVersionParameter),
$queryBuilder->expr()->eq('A.t3ver_wsid', $workspaceIdParameter),
$queryBuilder->expr()->neq('A.t3ver_state', $movePointerParameter)
)
......@@ -904,7 +904,7 @@ class WorkspaceService implements SingletonInterface
->from($tableName, 'B')
->join('B', $tableName, 'A', $queryBuilder->expr()->eq('B.t3ver_move_id', $queryBuilder->quoteIdentifier('A.t3ver_oid')))
->where(
$queryBuilder->expr()->eq('A.pid', $pageIdParameter),
$queryBuilder->expr()->gt('A.t3ver_oid', $onlineVersionParameter),
$queryBuilder->expr()->eq('A.t3ver_wsid', $workspaceIdParameter),
$queryBuilder->expr()->eq('A.t3ver_state', $movePointerParameter)
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment