Skip to content

Commit

Permalink
[TASK] Remove further evaluations of pid=-1
Browse files Browse the repository at this point in the history
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: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Achim Fritz <af@achimfritz.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
  • Loading branch information
bmack authored and NeoBlack committed Sep 13, 2019
1 parent 4989d5a commit 3cb5ff1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
19 changes: 13 additions & 6 deletions typo3/sysext/core/Classes/DataHandling/DataHandler.php
Expand Up @@ -40,6 +40,7 @@
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;
Expand Down Expand Up @@ -4440,7 +4441,9 @@ protected function inlineLocalizeSynchronize($table, $id, $command)
// 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']));
Expand Down Expand Up @@ -5163,9 +5166,9 @@ public function versionizeRecord($table, $id, $label, $delete = false)
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;
}

Expand Down Expand Up @@ -6457,10 +6460,11 @@ public function getRecordPropertiesFromRow($table, $row)
{
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']
];
Expand Down Expand Up @@ -6537,7 +6541,8 @@ public function updateDB($table, $id, $fieldArray)
}
// 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);
Expand Down Expand Up @@ -6824,6 +6829,7 @@ public function getSortNumber($table, $uid, $pid)
$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')
Expand Down Expand Up @@ -6886,6 +6892,7 @@ public function getSortNumber($table, $uid, $pid)
} 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')
Expand Down
12 changes: 3 additions & 9 deletions typo3/sysext/core/Classes/Database/RelationHandler.php
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -969,15 +970,8 @@ public function readForeignField($uid, $conf)
}
// 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
Expand Down
6 changes: 3 additions & 3 deletions typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
Expand Up @@ -234,7 +234,7 @@ public function processCmdmap_deleteAction($table, $id, array $record, &$recordW
$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.
Expand Down Expand Up @@ -1025,7 +1025,7 @@ protected function version_swap($table, $id, $swapWith, bool $swapIntoWS, DataHa
$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');
Expand All @@ -1036,7 +1036,7 @@ protected function version_swap($table, $id, $swapWith, bool $swapIntoWS, DataHa
$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');
Expand Down
8 changes: 4 additions & 4 deletions typo3/sysext/workspaces/Classes/Service/WorkspaceService.php
Expand Up @@ -884,8 +884,8 @@ protected function fetchPagesWithVersionsInTable($workspaceId, $tableName)
$workspaceId,
\PDO::PARAM_INT
);
$pageIdParameter = $queryBuilder->createNamedParameter(
-1,
$onlineVersionParameter = $queryBuilder->createNamedParameter(
0,
\PDO::PARAM_INT
);
// create sub-queries, parameters are available for main query
Expand All @@ -894,7 +894,7 @@ protected function fetchPagesWithVersionsInTable($workspaceId, $tableName)
->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)
)
Expand All @@ -904,7 +904,7 @@ protected function fetchPagesWithVersionsInTable($workspaceId, $tableName)
->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)
)
Expand Down

0 comments on commit 3cb5ff1

Please sign in to comment.