From 02e81aebef92599e9c30b427e127c7f2c7fae9ee Mon Sep 17 00:00:00 2001 From: Sybille Peters <sypets@gmx.de> Date: Tue, 17 Mar 2020 14:20:33 +0100 Subject: [PATCH] [BUGFIX] Fix order of deleting page translations in DataHandler If a page translation exists, it should be deleted before the original page. It the translation is deleted after the deletion of the original page, this will result in an error because the existance and delete permissions of the original page is checked before deletion of the translated page. Resolves: #85824 Releases: master, 9.5 Change-Id: I74b333fd450ea4bf361efbcd39a4daa07002c930 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63757 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Benni Mack <benni@typo3.org> --- .../core/Classes/DataHandling/DataHandler.php | 6 +-- .../DataSet/TranslatedSubpages.csv | 10 ++++ .../DeleteTranslatedSubpagesTest.php | 54 +++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TranslatedSubpages.csv create mode 100644 typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DeleteTranslatedSubpagesTest.php diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index 885f63515087..66c7f7b32515 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -4776,14 +4776,14 @@ class DataHandler implements LoggerAwareInterface // before (un-)deleting this record, check for child records or references $this->deleteRecord_procFields($table, $uid, $undeleteRecord); try { - GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable($table) - ->update($table, $updateFields, ['uid' => (int)$uid]); // Delete all l10n records as well, impossible during undelete because it might bring too many records back to life if (!$undeleteRecord) { $this->deletedRecords[$table][] = (int)$uid; $this->deleteL10nOverlayRecords($table, $uid); } + GeneralUtility::makeInstance(ConnectionPool::class) + ->getConnectionForTable($table) + ->update($table, $updateFields, ['uid' => (int)$uid]); } catch (DBALException $e) { $databaseErrorMessage = $e->getPrevious()->getMessage(); } diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TranslatedSubpages.csv b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TranslatedSubpages.csv new file mode 100644 index 000000000000..93b6eb655040 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TranslatedSubpages.csv @@ -0,0 +1,10 @@ +"sys_language",,,,,,,,,,,,,,,,,, +,"uid","pid","hidden","title","flag",,,,,,,,,,,,, +,1,0,0,"Dansk","dk",,,,,,,,,,,,, +,2,0,0,"Deutsch","de",,,,,,,,,,,,, +"pages",,,,,,,,,,,,,,,,,, +,"uid","pid","title","sys_language_uid","l10n_parent",,,,,,,,,,,,, +,1,0,"Startpage",0,0,,,,,,,,,,,,, +,2,0,"Startpage - Dansk",1,1,,,,,,,,,,,,, +,3,1,"Subpage",0,0,,,,,,,,,,,,, +,4,1,"Subpage - Dansk",1,3,,,,,,,,,,,,, diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DeleteTranslatedSubpagesTest.php b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DeleteTranslatedSubpagesTest.php new file mode 100644 index 000000000000..bc863eee9742 --- /dev/null +++ b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DeleteTranslatedSubpagesTest.php @@ -0,0 +1,54 @@ +<?php + +namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler; + +/* + * 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\Core\DataHandling\DataHandler; +use TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +/** + * Functional test for deleting page with translated subpage + */ +class DeleteTranslatedSubpagesTest extends AbstractDataHandlerActionTestCase +{ + /** + * @var string + */ + protected $scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/'; + + protected function setUp(): void + { + parent::setUp(); + $this->importScenarioDataSet('TranslatedSubpages'); + $this->backendUser->workspace = 0; + $this->backendUser->uc['recursiveDelete'] = true; + } + + /** + * @test + */ + public function deletePageCausesNoErrorsWithTranslatedSubpage(): void + { + $uid = 1; + $cmd['pages'][$uid]['delete'] = 1; + + $dataHandler = GeneralUtility::makeInstance(DataHandler::class); + $dataHandler->start([], $cmd); + $dataHandler->process_cmdmap(); + + self::assertEquals($dataHandler->errorLog, []); + } +} -- GitLab