[BUGFIX] Delete move placeholders upon record deletion 96/13496/15
authorBart Dubelaar <bartdubelaar@gmail.com>
Tue, 7 Aug 2012 12:00:26 +0000 (14:00 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 22 Sep 2015 14:28:33 +0000 (16:28 +0200)
If a record was moved in a draft workspace and subsequently
removed in the live workspace, then the move placeholder would
remain and show up as an actual record in the backend. To the
end user it appears as if the record was not deleted as one
would now see the move-placeholder.

If the mentioned moved record would be removed instead in the
very same draft workspace, the move-to-pointer was removed
correctly, but the move-placeholder stayed as well.

Resolves: #39383
Releases: master, 6.2
Change-Id: I3b0593332650795539c2d7eac075515dbd981b45
Reviewed-on: http://review.typo3.org/13496
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Modify/DataSet/changeContentSortingNDeleteLiveRecord.csv
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Modify/DataSet/changeContentSortingNDeleteMovedRecord.csv

index a9dbd71..8c46936 100755 (executable)
@@ -4428,11 +4428,14 @@ class BackendUtility {
         * @param string $table Table name
         * @param int $uid Record UID of online version
         * @param string $fields Field list, default is *
+        * @param int|NULL $workspace The workspace to be used
         * @return array If found, the record, otherwise nothing.
         */
-       static public function getMovePlaceholder($table, $uid, $fields = '*') {
-               $workspace = static::getBackendUserAuthentication()->workspace;
-               if ($workspace !== 0 && $GLOBALS['TCA'][$table] && (int)$GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) {
+       static public function getMovePlaceholder($table, $uid, $fields = '*', $workspace = NULL) {
+               if ($workspace === NULL) {
+                       $workspace = static::getBackendUserAuthentication()->workspace;
+               }
+               if ((int)$workspace !== 0 && $GLOBALS['TCA'][$table] && (int)$GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) {
                        // Select workspace version of record:
                        $row = static::getDatabaseConnection()->exec_SELECTgetSingleRow(
                                $fields,
index 9ee9e70..256e719 100644 (file)
@@ -4729,7 +4729,7 @@ class DataHandler {
         * @return void
         */
        public function deleteVersionsForRecord($table, $uid, $forceHardDelete) {
-               $versions = BackendUtility::selectVersionsOfRecord($table, $uid, 'uid,pid', $this->BE_USER->workspace);
+               $versions = BackendUtility::selectVersionsOfRecord($table, $uid, 'uid,pid,t3ver_wsid,t3ver_state', $this->BE_USER->workspace ?: NULL);
                if (is_array($versions)) {
                        foreach ($versions as $verRec) {
                                if (!$verRec['_CURRENT_VERSION']) {
@@ -4738,6 +4738,13 @@ class DataHandler {
                                        } else {
                                                $this->deleteRecord($table, $verRec['uid'], TRUE, $forceHardDelete);
                                        }
+
+                                       // Delete move-placeholder
+                                       $versionState = VersionState::cast($verRec['t3ver_state']);
+                                       if ($versionState->equals(VersionState::MOVE_POINTER)) {
+                                               $versionMovePlaceholder = BackendUtility::getMovePlaceholder($table, $uid, 'uid', $verRec['t3ver_wsid']);
+                                               $this->deleteEl($table, $versionMovePlaceholder['uid'], TRUE, $forceHardDelete);
+                                       }
                                }
                        }
                }
index 50f5208..589d123 100644 (file)
@@ -199,6 +199,11 @@ class DataHandlerHook {
                                        } elseif ($record['t3ver_wsid'] == 0 || !$liveRecordVersionState->indicatesPlaceholder()) {
                                                // Delete those in WS 0 + if their live records state was not "Placeholder".
                                                $tcemainObj->deleteEl($table, $id);
+                                               // Delete move-placeholder if current version record is a move-to-pointer
+                                               if ($recordVersionState->equals(VersionState::MOVE_POINTER)) {
+                                                       $movePlaceholder = BackendUtility::getMovePlaceholder($table, $liveRec['uid'], 'uid');
+                                                       $tcemainObj->deleteEl($table, $movePlaceholder['uid']);
+                                               }
                                        } else {
                                                // If live record was placeholder (new/deleted), rather clear
                                                // it from workspace (because it clears both version and placeholder).
index 78a0d0b..5d39666 100644 (file)
@@ -5,5 +5,5 @@ tt_content
 ,299,89,768,0,0,0,0,0,0,0,0,"Regular Element #3"
 ,300,89,1024,0,1,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
 ,301,-1,512,0,0,0,2,2,0,298,0,"Regular Element #2"
-,302,-1,256,0,0,0,1,4,0,297,0,"Regular Element #1"
-,303,89,640,0,0,0,1,3,0,0,297,"[MOVE-TO PLACEHOLDER for #297, WS#1]"
+,302,-1,1000000000,1,0,0,1,4,0,297,0,"Regular Element #1"
+,303,89,1000000000,1,0,0,1,3,0,0,297,"[MOVE-TO PLACEHOLDER for #297, WS#1]"
index 612aa94..fa0a66c 100644 (file)
@@ -6,4 +6,4 @@ tt_content
 ,300,89,1024,0,1,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
 ,301,-1,512,0,0,0,2,2,0,298,0,"Regular Element #2"
 ,302,-1,1000000000,1,0,0,1,4,0,297,0,"Regular Element #1"
-,303,89,640,0,0,0,1,3,0,0,297,"[MOVE-TO PLACEHOLDER for #297, WS#1]"
+,303,89,1000000000,1,0,0,1,3,0,0,297,"[MOVE-TO PLACEHOLDER for #297, WS#1]"