[TASK] Introduce Enum constants for t3ver_state 10/24410/9
authorSascha Egerer <sascha.egerer@dkd.de>
Sat, 5 Oct 2013 15:33:44 +0000 (17:33 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 12 Oct 2013 16:37:18 +0000 (18:37 +0200)
Currently the t3ver_state field can have 6
different integer values.
To clean up the code and make it better
understandable a Enum object is implemented.

Resolves: #52551
Releases: 6.2
Change-Id: I2f41d6bbf6575aec4a5c2b6d86495700d61bf5b7
Reviewed-on: https://review.typo3.org/24410
Reviewed-by: Sebastian Fischer
Tested-by: Sebastian Fischer
Reviewed-by: Thorsten Kahler
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
18 files changed:
typo3/sysext/backend/Classes/Tree/Pagetree/Commands.php
typo3/sysext/backend/Classes/Tree/Pagetree/PagetreeNode.php
typo3/sysext/backend/Classes/Tree/View/BrowseTreeView.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Classes/Utility/IconUtility.php
typo3/sysext/backend/Classes/View/PageLayoutView.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Database/RelationHandler.php
typo3/sysext/core/Classes/Type/Enumeration.php
typo3/sysext/core/Classes/Versioning/VersionState.php [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/lowlevel/Classes/VersionsCommand.php
typo3/sysext/version/Classes/DataHandler/CommandMap.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php
typo3/sysext/version/Classes/Hook/IconUtilityHook.php
typo3/sysext/workspaces/Classes/Service/IntegrityService.php
typo3/sysext/workspaces/Classes/Service/WorkspaceService.php

index 4776e26..491b419 100644 (file)
@@ -31,6 +31,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Page Tree and Context Menu Commands
@@ -363,10 +364,17 @@ class Commands {
                        $spriteIconCode = IconUtility::getSpriteIcon('apps-pagetree-root');
                }
                $subNode->setSpriteIconCode($spriteIconCode);
-               if (!$subNode->canCreateNewPages() || intval($record['t3ver_state']) === 2) {
+               if (
+                       !$subNode->canCreateNewPages()
+                       || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+               ) {
                        $subNode->setIsDropTarget(FALSE);
                }
-               if (!$subNode->canBeEdited() || !$subNode->canBeRemoved() || intval($record['t3ver_state']) === 2) {
+               if (
+                       !$subNode->canBeEdited()
+                       || !$subNode->canBeRemoved()
+                       || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+               ) {
                        $subNode->setDraggable(FALSE);
                }
                return $subNode;
index 167bd7b..27e3c34 100644 (file)
@@ -26,7 +26,10 @@ namespace TYPO3\CMS\Backend\Tree\Pagetree;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
-/**
+
+ use TYPO3\CMS\Core\Versioning\VersionState;
+
+ /**
  * Node designated for the page tree
  *
  * @author Stefan Galinski <stefan.galinski@gmail.com>
@@ -224,7 +227,11 @@ class PagetreeNode extends \TYPO3\CMS\Backend\Tree\ExtDirectNode {
         * @return boolean
         */
        public function canBeCut() {
-               return $this->canEdit($this->record) && intval($this->record['t3ver_state']) !== 2 && $GLOBALS['BE_USER']->checkLanguageAccess(0);
+               return (
+                       $this->canEdit($this->record)
+                       && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+                       && $GLOBALS['BE_USER']->checkLanguageAccess(0)
+               );
        }
 
        /**
@@ -242,7 +249,12 @@ class PagetreeNode extends \TYPO3\CMS\Backend\Tree\ExtDirectNode {
         * @return boolean
         */
        public function canBeCopied() {
-               return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2 && $GLOBALS['BE_USER']->checkLanguageAccess(0);
+               return (
+                       $this->canCreate($this->record)
+                       && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+                       && $GLOBALS['BE_USER']->checkLanguageAccess(0)
+
+               );
        }
 
        /**
@@ -260,7 +272,11 @@ class PagetreeNode extends \TYPO3\CMS\Backend\Tree\ExtDirectNode {
         * @return boolean
         */
        public function canBeRemoved() {
-               return $this->canRemove($this->record) && intval($this->record['t3ver_state']) !== 2 && $GLOBALS['BE_USER']->checkLanguageAccess(0);
+               return (
+                       $this->canRemove($this->record)
+                       && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+                       && $GLOBALS['BE_USER']->checkLanguageAccess(0)
+               );
        }
 
        /**
@@ -269,7 +285,11 @@ class PagetreeNode extends \TYPO3\CMS\Backend\Tree\ExtDirectNode {
         * @return boolean
         */
        public function canBePastedInto() {
-               return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2 && $GLOBALS['BE_USER']->checkLanguageAccess(0);
+               return (
+                       $this->canCreate($this->record)
+                       && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+                       && $GLOBALS['BE_USER']->checkLanguageAccess(0)
+               );
        }
 
        /**
@@ -278,7 +298,11 @@ class PagetreeNode extends \TYPO3\CMS\Backend\Tree\ExtDirectNode {
         * @return boolean
         */
        public function canBePastedAfter() {
-               return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2 && $GLOBALS['BE_USER']->checkLanguageAccess(0);
+               return (
+                       $this->canCreate($this->record)
+                       && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+                       && $GLOBALS['BE_USER']->checkLanguageAccess(0)
+               );
        }
 
        /**
index ce0280c..4c3eff9 100644 (file)
@@ -67,7 +67,7 @@ class BrowseTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
                        $hideList = explode(',', $pidList);
                        $this->MOUNTS = array_diff($this->MOUNTS, $hideList);
                }
-               $this->fieldArray = array_merge($this->fieldArray, array('doktype', 'php_tree_stop', 't3ver_id', 't3ver_state', 't3ver_wsid', 't3ver_state', 't3ver_move_id'));
+               $this->fieldArray = array_merge($this->fieldArray, array('doktype', 'php_tree_stop', 't3ver_id', 't3ver_state', 't3ver_wsid', 't3ver_move_id'));
                if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
                        $this->fieldArray = array_merge($this->fieldArray, array('hidden', 'starttime', 'endtime', 'fe_group', 'module', 'extendToSubpages', 'is_siteroot', 'nav_hide'));
                }
index 38b9193..bc14e4b 100644 (file)
@@ -35,6 +35,7 @@ use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
@@ -1649,20 +1650,20 @@ class BackendUtility {
                if ($row['pid'] < 0) {
                        $parts[] = 'v#1.' . $row['t3ver_id'];
                }
-               switch ($row['t3ver_state']) {
-                       case 1:
+               switch (VersionState::cast($row['t3ver_state'])) {
+                       case new VersionState(VersionState::NEW_PLACEHOLDER):
                                $parts[] = 'PLH WSID#' . $row['t3ver_wsid'];
                                break;
-                       case 2:
+                       case new VersionState(VersionState::DELETE_PLACEHOLDER):
                                $parts[] = 'Deleted element!';
                                break;
-                       case 3:
+                       case new VersionState(VersionState::MOVE_PLACEHOLDER):
                                $parts[] = 'NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
                                break;
-                       case 4:
+                       case new VersionState(VersionState::MOVE_POINTER):
                                $parts[] = 'OLD LOCATION (PNT) WSID#' . $row['t3ver_wsid'];
                                break;
-                       case -1:
+                       case new VersionState(VersionState::NEW_PLACEHOLDER_VERSION):
                                $parts[] = 'New element!';
                                break;
                }
@@ -1744,20 +1745,20 @@ class BackendUtility {
                                $out .= ' - v#1.' . $row['t3ver_id'];
                        }
                        if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
-                               switch ($row['t3ver_state']) {
-                                       case 1:
+                               switch (VersionState::cast($row['t3ver_state'])) {
+                                       case new VersionState(VersionState::NEW_PLACEHOLDER):
                                                $out .= ' - PLH WSID#' . $row['t3ver_wsid'];
                                                break;
-                                       case 2:
+                                       case new VersionState(VersionState::DELETE_PLACEHOLDER):
                                                $out .= ' - Deleted element!';
                                                break;
-                                       case 3:
+                                       case new VersionState(VersionState::MOVE_PLACEHOLDER):
                                                $out .= ' - NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
                                                break;
-                                       case 4:
+                                       case new VersionState(VersionState::MOVE_POINTER):
                                                $out .= ' - OLD LOCATION (PNT)  WSID#' . $row['t3ver_wsid'];
                                                break;
-                                       case -1:
+                                       case new VersionState(VersionState::NEW_PLACEHOLDER_VERSION):
                                                $out .= ' - New element!';
                                                break;
                                }
@@ -3670,11 +3671,11 @@ class BackendUtility {
                                                // If t3ver_state is not found, then find it... (but we like best if it is here...)
                                                if (!isset($wsAlt['t3ver_state'])) {
                                                        $stateRec = self::getRecord($table, $wsAlt['uid'], 't3ver_state');
-                                                       $state = $stateRec['t3ver_state'];
+                                                       $versionState = VersionState::cast($stateRec['t3ver_state']);
                                                } else {
-                                                       $state = $wsAlt['t3ver_state'];
+                                                       $versionState = VersionState::cast($wsAlt['t3ver_state']);
                                                }
-                                               if ((int) $state === 4) {
+                                               if ($versionState->equals(VersionState::MOVE_POINTER)) {
                                                        // TODO: Same problem as frontend in versionOL(). See TODO point there.
                                                        $row = FALSE;
                                                        return;
@@ -3701,14 +3702,15 @@ class BackendUtility {
                                        $row['_MOVE_PLH_uid'] = $orig_uid;
                                        $row['_MOVE_PLH_pid'] = $orig_pid;
                                        // For display; To make the icon right for the placeholder vs. the original
-                                       $row['t3ver_state'] = 3;
+                                       $row['t3ver_state'] = (string)new VersionState(VersionState::MOVE_PLACEHOLDER);
                                }
                        }
                }
        }
 
        /**
-        * Checks if record is a move-placeholder (t3ver_state==3) and if so it will set $row to be the pointed-to live record (and return TRUE)
+        * Checks if record is a move-placeholder (t3ver_state==VersionState::MOVE_PLACEHOLDER) and if so
+        * it will set $row to be the pointed-to live record (and return TRUE)
         *
         * @param string $table Table name
         * @param array $row Row (passed by reference) - must be online record!
@@ -3722,13 +3724,13 @@ class BackendUtility {
                        if (!isset($row['t3ver_move_id']) || !isset($row['t3ver_state'])) {
                                $moveIDRec = self::getRecord($table, $row['uid'], 't3ver_move_id, t3ver_state');
                                $moveID = $moveIDRec['t3ver_move_id'];
-                               $state = $moveIDRec['t3ver_state'];
+                               $versionState = VersionState::cast($moveIDRec['t3ver_state']);
                        } else {
                                $moveID = $row['t3ver_move_id'];
-                               $state = $row['t3ver_state'];
+                               $versionState = VersionState::cast($row['t3ver_state']);
                        }
                        // Find pointed-to record.
-                       if ((int) $state === 3 && $moveID) {
+                       if ($versionState->equals(VersionState::MOVE_PLACEHOLDER) && $moveID) {
                                if ($origRow = self::getRecord($table, $moveID, implode(',', array_keys($row)))) {
                                        $row = $origRow;
                                        return TRUE;
@@ -3803,7 +3805,7 @@ class BackendUtility {
        static public function versioningPlaceholderClause($table) {
                if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                        $currentWorkspace = intval($GLOBALS['BE_USER']->workspace);
-                       return ' AND (' . $table . '.t3ver_state <= 0 OR ' . $table . '.t3ver_wsid = ' . $currentWorkspace . ')';
+                       return ' AND (' . $table . '.t3ver_state <= ' . new VersionState(VersionState::DEFAULT_STATE) . ' OR ' . $table . '.t3ver_wsid = ' . $currentWorkspace . ')';
                }
        }
 
@@ -3878,7 +3880,12 @@ class BackendUtility {
                $workspace = $GLOBALS['BE_USER']->workspace;
                if ($workspace !== 0 && $GLOBALS['TCA'][$table] && (int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) {
                        // Select workspace version of record:
-                       $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow($fields, $table, 'pid<>-1 AND ' . 't3ver_state=3 AND ' . 't3ver_move_id=' . intval($uid) . ' AND ' . 't3ver_wsid=' . intval($workspace) . self::deleteClause($table));
+                       $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
+                               $fields,
+                               $table,
+                               'pid<>-1 AND t3ver_state=' . new VersionState(VersionState::MOVE_PLACEHOLDER) . ' AND t3ver_move_id='
+                                       . intval($uid) . ' AND t3ver_wsid=' . intval($workspace) . self::deleteClause($table)
+                       );
                        if (is_array($row)) {
                                return $row;
                        }
index 3ebb6dc..bbba820 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Backend\Utility;
  ***************************************************************/
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Contains class for icon generation in the backend
@@ -155,17 +156,17 @@ class IconUtility {
                $doNotRenderUserGroupNumber = TRUE;
                // Shadow
                if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
-                       switch ((int) $row['t3ver_state']) {
-                               case 1:
+                       switch (VersionState::cast($row['t3ver_state'])) {
+                               case new VersionState(VersionState::NEW_PLACEHOLDER):
                                        return 'gfx/i/shadow_hide.png';
                                        break;
-                               case 2:
+                               case new VersionState(VersionState::DELETE_PLACEHOLDER):
                                        return 'gfx/i/shadow_delete.png';
                                        break;
-                               case 3:
+                               case new VersionState(VersionState::MOVE_PLACEHOLDER):
                                        return 'gfx/i/shadow_moveto_plh.png';
                                        break;
-                               case 4:
+                               case new VersionState(VersionState::MOVE_POINTER):
                                        return 'gfx/i/shadow_moveto_pointer.png';
                                        break;
                        }
index d7f4726..1987ccc 100644 (file)
@@ -31,6 +31,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Child class for the Web > Page module
@@ -450,7 +451,7 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                                                                $languageColumn[$key][$lP] .= '<br /><br />' . $this->newLanguageButton($this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP), $lP);
                                                        }
                                                }
-                                               if (is_array($row) && (int) $row['t3ver_state'] != 2) {
+                                               if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
                                                        $singleElementHTML = '';
                                                        if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
                                                                $defLanguageCount[$key][] = $row['uid'];
@@ -696,7 +697,7 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                                        }
                                        // Traverse any selected elements:
                                        foreach ($rowArr as $rKey => $row) {
-                                               if (is_array($row) && (int) $row['t3ver_state'] != 2) {
+                                               if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
                                                        $c++;
                                                        $editUidList .= $row['uid'] . ',';
                                                        $isRTE = $RTE && $this->isRTEforField('tt_content', $row, 'bodytext');
index d6f4f65..2be5492 100644 (file)
@@ -26,9 +26,9 @@ namespace TYPO3\CMS\Core\DataHandling;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * The main data handler class which takes care of correctly updating and inserting records.
@@ -1193,7 +1193,7 @@ class DataHandler {
                                                                        if ($createNewVersion) {
                                                                                $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
                                                                                // Setting placeholder state value for temporary record
-                                                                               $newVersion_placeholderFieldArray['t3ver_state'] = 1;
+                                                                               $newVersion_placeholderFieldArray['t3ver_state'] = (string)new VersionState(VersionState::NEW_PLACEHOLDER);
                                                                                // Setting workspace - only so display of place holders can filter out those from other workspaces.
                                                                                $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
                                                                                $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = '[PLACEHOLDER, WS#' . $this->BE_USER->workspace . ']';
@@ -1204,7 +1204,7 @@ class DataHandler {
                                                                                $fieldArray['t3ver_oid'] = $this->substNEWwithIDs[$id];
                                                                                $fieldArray['t3ver_id'] = 1;
                                                                                // Setting placeholder state value for version (so it can know it is currently a new version...)
-                                                                               $fieldArray['t3ver_state'] = -1;
+                                                                               $fieldArray['t3ver_state'] = (string)new VersionState(VersionState::NEW_PLACEHOLDER_VERSION);
                                                                                $fieldArray['t3ver_label'] = 'First draft version';
                                                                                $fieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
                                                                                // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice!
@@ -1258,7 +1258,7 @@ class DataHandler {
         */
        public function placeholderShadowing($table, $id) {
                if ($liveRec = BackendUtility::getLiveVersionOfRecord($table, $id, '*')) {
-                       if ((int) $liveRec['t3ver_state'] > 0) {
+                       if (VersionState::cast($liveRec['t3ver_state'])->indicatesPlaceholder()) {
                                $justStoredRecord = BackendUtility::getRecord($table, $id);
                                $newRecord = array();
                                $shadowCols = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'];
@@ -4664,7 +4664,7 @@ class DataHandler {
                                        // Record must be online record
                                        if ($row['pid'] >= 0) {
                                                // Record must not be placeholder for moving.
-                                               if ($row['t3ver_state'] != 3) {
+                                               if (!VersionState::cast($row['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)) {
                                                        if (!$delete || !$this->cannotDeleteRecord($table, $id)) {
                                                                // Look for next version number:
                                                                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('t3ver_id', $table, '((pid=-1 && t3ver_oid=' . $id . ') OR uid=' . $id . ')' . $this->deleteClause($table), '', 't3ver_id DESC', '1');
@@ -4678,7 +4678,7 @@ class DataHandler {
                                                                        't3ver_oid' => $id,
                                                                        't3ver_label' => $label ? $label : $subVer . ' / ' . date('d-m-Y H:m:s'),
                                                                        't3ver_wsid' => $this->BE_USER->workspace,
-                                                                       't3ver_state' => $delete ? 2 : 0,
+                                                                       't3ver_state' => (string)($delete ? new VersionState(VersionState::DELETE_PLACEHOLDER) : new VersionState(VersionState::DEFAULT_STATE)),
                                                                        't3ver_count' => 0,
                                                                        't3ver_stage' => 0,
                                                                        't3ver_tstamp' => 0
index feaf310..e37dabd 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Core\Database;
  ***************************************************************/
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Load database groups (relations)
@@ -772,7 +773,11 @@ class RelationHandler {
                                }
                                // Update accordant fields in the database for workspaces overlays/placeholders:
                                if (count($workspaceValues) && $considerWorkspaces) {
-                                       if (isset($row['t3ver_oid']) && $row['t3ver_oid'] && $row['t3ver_state'] == -1) {
+                                       if (
+                                               isset($row['t3ver_oid'])
+                                               && $row['t3ver_oid']
+                                               && VersionState::cast($row['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER_VERSION)
+                                       ) {
                                                $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($row['t3ver_oid']), $workspaceValues);
                                        }
                                }
index 040d6af..1fd7fb1 100644 (file)
@@ -151,6 +151,20 @@ abstract class Enumeration {
        }
 
        /**
+        * Compare if the value of the current object value equals the given value
+        *
+        * @param mixed $value default
+        * @return boolean
+        */
+       public function equals($value) {
+               $currentClass = get_class($this);
+               if (!is_object($value) || get_class($value) !== $currentClass) {
+                       $value = new $currentClass($value);
+               }
+               return $this === $value;
+       }
+
+       /**
         * @return string
         */
        public function __toString() {
diff --git a/typo3/sysext/core/Classes/Versioning/VersionState.php b/typo3/sysext/core/Classes/Versioning/VersionState.php
new file mode 100644 (file)
index 0000000..e5e7807
--- /dev/null
@@ -0,0 +1,116 @@
+<?php
+namespace TYPO3\CMS\Core\Versioning;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2013 Sascha Egerer <sascha.egerer@dkd.de>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ * A copy is found in the textfile GPL.txt and important notices to the license
+ * from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Enumeration object for VersionState
+ *
+ * @package TYPO3\CMS\Core\Versioning
+ */
+class VersionState extends \TYPO3\CMS\Core\Type\Enumeration {
+
+       const __default = self::DEFAULT_STATE;
+
+       /**
+        * If a new record is created in a workspace a version
+        * with t3ver_state -1 is created with pid=-1. This
+        * record is the version of the "live" record
+        * (t3ver_state=1) where changes are stored.
+        */
+       const NEW_PLACEHOLDER_VERSION = -1;
+
+       /**
+        * The t3ver_state 0 is used for the live version
+        * of a record and for draft records with pid -1
+        */
+       const DEFAULT_STATE = 0;
+
+       /**
+        * Creating elements is done by first creating a
+        * placeholder element which is in fact live but
+        * carrying a flag (t3ver_state=1) that makes it
+        * invisible online.
+        */
+       const NEW_PLACEHOLDER = 1;
+
+       /**
+        * Deleting elements is done by actually creating a
+        * new version of the element and setting t3ver_state=2
+        * that indicates the live element must be deleted upon
+        * swapping the versions.
+        */
+       const DELETE_PLACEHOLDER = 2;
+
+       /**
+        * Moving elements is done by first creating a placeholder
+        * element which is in fact live but carrying a flag
+        * (t3ver_state=3) that makes it invisible online.
+        * It also has a field, "t3ver_move_id", holding the
+        * uid of the record to move (source record).
+        * In addition, a new version of the source record is made
+        * and has "t3ver_state" = 4 (move-to pointer). This version
+        * is simply necessary in order for the versioning system to
+        * have something to publish for the move operation. So in
+        * summary, two records are created for a move operation in
+        * a workspace: The placeholder (online, with state=3 and
+        * t3ver_move_id set) and a new version (state=4) of the
+        * online source record (the one being moved).
+        */
+       const MOVE_PLACEHOLDER = 3;
+       const MOVE_POINTER = 4;
+
+       /**
+        * @param mixed $value
+        */
+       public function __construct($value = NULL) {
+               if($value !== NULL) {
+                       $value = (int)$value;
+               }
+               parent::__construct($value);
+       }
+
+       /**
+        * Cast value to VersionState Object
+        *
+        * @param mixed $versionState A value that is casted to a VersionState or a VersionState object that is returned
+        * @return VersionState
+        */
+       public static function cast($versionState) {
+               if (!$versionState instanceof VersionState) {
+                       $versionState = new VersionState($versionState);
+               }
+               return $versionState;
+       }
+
+       /**
+        * @return boolean
+        */
+       public function indicatesPlaceholder() {
+               return intval($this->__toString()) > self::DEFAULT_STATE;
+       }
+}
index 32035be..42ad334 100644 (file)
@@ -29,6 +29,7 @@ namespace TYPO3\CMS\Frontend\ContentObject;
  ***************************************************************/
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * This class contains all main TypoScript features.
@@ -7416,10 +7417,11 @@ class ContentObjectRenderer {
                        );
                        if (is_array($rows)) {
                                foreach ($rows as $row) {
+                                       $versionState = VersionState::cast($row['t3ver_state']);
                                        $GLOBALS['TSFE']->sys_page->versionOL('pages', $row);
                                        if ($row['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_RECYCLER
                                                || $row['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_BE_USER_SECTION
-                                               || $row['t3ver_state'] > 0
+                                               || $versionState->indicatesPlaceholder()
                                        ) {
                                                // Doing this after the overlay to make sure changes
                                                // in the overlay are respected.
@@ -7443,7 +7445,7 @@ class ContentObjectRenderer {
                                                $GLOBALS['TSFE']->sys_page->versionOL('pages', $row);
                                                if ($row['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_RECYCLER
                                                        || $row['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_BE_USER_SECTION
-                                                       || $row['t3ver_state'] > 0
+                                                       || $versionState->indicatesPlaceholder()
                                                ) {
                                                        // Doing this after the overlay to make sure
                                                        // changes in the overlay are respected.
index fe010d7..f095070 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Frontend\Page;
  ***************************************************************/
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Page functions, a lot of sql/pages-related functions
@@ -139,7 +140,7 @@ class PageRepository {
                $this->where_hid_del .= 'AND pages.starttime<=' . $GLOBALS['SIM_ACCESS_TIME'] . ' AND (pages.endtime=0 OR pages.endtime>' . $GLOBALS['SIM_ACCESS_TIME'] . ') ';
                // Filter out new/deleted place-holder pages in case we are NOT in a versioning preview (that means we are online!)
                if (!$this->versioningPreview) {
-                       $this->where_hid_del .= ' AND NOT pages.t3ver_state>0';
+                       $this->where_hid_del .= ' AND NOT pages.t3ver_state>' . new VersionState(VersionState::DEFAULT_STATE);
                } else {
                        // For version previewing, make sure that enable-fields are not de-selecting hidden
                        // pages - we need versionOL() to unset them only if the overlay record instructs us to.
@@ -874,7 +875,7 @@ class PageRepository {
                                if (!$this->versioningPreview) {
                                        // Filter out placeholder records (new/moved/deleted items)
                                        // in case we are NOT in a versioning preview (that means we are online!)
-                                       $query .= ' AND ' . $table . '.t3ver_state<=0';
+                                       $query .= ' AND ' . $table . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE);
                                } else {
                                        if ($table !== 'pages') {
                                                // show only records of live and of the current workspace
@@ -1045,20 +1046,28 @@ class PageRepository {
                                        // Changing input record to the workspace version alternative:
                                        $row = $wsAlt;
                                        // Check if it is deleted/new
-                                       if ((int) $row['t3ver_state'] === 1 || (int) $row['t3ver_state'] === 2) {
+                                       $rowVersionState = VersionState::cast($row['t3ver_state']);
+                                       if (
+                                               $rowVersionState->equals(VersionState::NEW_PLACEHOLDER)
+                                               || $rowVersionState->equals(VersionState::DELETE_PLACEHOLDER)
+                                       ) {
                                                // Unset record if it turned out to be deleted in workspace
                                                $row = FALSE;
                                        }
                                        // Check if move-pointer in workspace (unless if a move-placeholder is the reason why it appears!):
                                        // You have to specifically set $unsetMovePointers in order to clear these because it is normally a display issue if it should be shown or not.
-                                       if (((int) $row['t3ver_state'] === 4 && !$movePldSwap) && $unsetMovePointers) {
+                                       if (
+                                               ($rowVersionState->equals(VersionState::MOVE_POINTER)
+                                                       && !$movePldSwap
+                                               ) && $unsetMovePointers
+                                       ) {
                                                // Unset record if it turned out to be deleted in workspace
                                                $row = FALSE;
                                        }
                                } else {
-                                       // No version found, then check if t3ver_state =1 (online version is dummy-representation)
+                                       // No version found, then check if t3ver_state = VersionState::NEW_PLACEHOLDER (online version is dummy-representation)
                                        // Notice, that unless $bypassEnableFieldsCheck is TRUE, the $row is unset if enablefields for BOTH the version AND the online record deselects it. See note for $bypassEnableFieldsCheck
-                                       if ($wsAlt <= -1 || (int) $row['t3ver_state'] > 0) {
+                                       if ($wsAlt <= -1 || VersionState::cast($row['t3ver_state'])->indicatesPlaceholder()) {
                                                // Unset record if it turned out to be "hidden"
                                                $row = FALSE;
                                        }
@@ -1068,8 +1077,8 @@ class PageRepository {
        }
 
        /**
-        * Checks if record is a move-placeholder (t3ver_state==3) and if so it will set $row to be the pointed-to live record (and return TRUE)
-        * Used from versionOL
+        * Checks if record is a move-placeholder (t3ver_state==VersionState::MOVE_PLACEHOLDER) and if so
+        * it will set $row to be the pointed-to live record (and return TRUE) Used from versionOL
         *
         * @param string $table Table name
         * @param array $row Row (passed by reference) - only online records...
@@ -1078,7 +1087,11 @@ class PageRepository {
         * @todo Define visibility
         */
        public function movePlhOL($table, &$row) {
-               if (($table == 'pages' || (int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) && (int) $row['t3ver_state'] === 3) {
+               if (
+                       ($table == 'pages'
+                               || (int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2
+                       ) && (int) VersionState::cast($row['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)
+               ) {
                        // Only for WS ver 2... (moving)
                        // If t3ver_move_id is not found, then find it... (but we like best if it is here...)
                        if (!isset($row['t3ver_move_id'])) {
@@ -1117,7 +1130,7 @@ class PageRepository {
                        if (($table == 'pages' || (int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) && $workspace !== 0) {
                                // Select workspace version of record:
                                $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow($fields, $table, 'pid<>-1 AND
-                                               t3ver_state=3 AND
+                                               t3ver_state=' . new VersionState(VersionState::MOVE_PLACEHOLDER) . ' AND
                                                t3ver_move_id=' . intval($uid) . ' AND
                                                t3ver_wsid=' . intval($workspace) . $this->deleteClause($table));
                                if (is_array($row)) {
index 4a11d94..772f8fa 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Lowlevel;
  ***************************************************************/
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Looking for versions of records
@@ -98,7 +99,11 @@ Automatic Repair:
                $resultArray['versions_unused_placeholders'] = array();
                foreach ($GLOBALS['TCA'] as $table => $cfg) {
                        if ($cfg['ctrl']['versioningWS']) {
-                               $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid', $table, 't3ver_state=1 AND pid>=0' . BackendUtility::deleteClause($table));
+                               $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                       'uid,pid',
+                                       $table,
+                                       't3ver_state=' . new VersionState(VersionState::NEW_PLACEHOLDER) . ' AND pid>=0' . BackendUtility::deleteClause($table)
+                               );
                                foreach ($placeHolders as $phrec) {
                                        if (count(BackendUtility::selectVersionsOfRecord($table, $phrec['uid'], 'uid')) <= 1) {
                                                $resultArray['versions_unused_placeholders'][\TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($table . ':' . $phrec['uid'])] = $table . ':' . $phrec['uid'];
@@ -112,14 +117,18 @@ Automatic Repair:
                $resultArray['versions_move_placeholders_bad'] = array();
                foreach ($GLOBALS['TCA'] as $table => $cfg) {
                        if ((int) $cfg['ctrl']['versioningWS'] >= 2) {
-                               $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid,t3ver_move_id,t3ver_wsid,t3ver_state', $table, 't3ver_state=3 AND pid>=0' . BackendUtility::deleteClause($table));
+                               $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                       'uid,pid,t3ver_move_id,t3ver_wsid,t3ver_state',
+                                       $table,
+                                       't3ver_state=' . new VersionState(VersionState::MOVE_PLACEHOLDER) . ' AND pid>=0' . BackendUtility::deleteClause($table)
+                               );
                                foreach ($placeHolders as $phrec) {
                                        $shortID = \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($table . ':' . $phrec['uid']);
                                        if ((int) $phrec['t3ver_wsid'] != 0) {
                                                $phrecCopy = $phrec;
                                                if (BackendUtility::movePlhOL($table, $phrec)) {
                                                        if ($wsAlt = BackendUtility::getWorkspaceVersionOfRecord($phrecCopy['t3ver_wsid'], $table, $phrec['uid'], 'uid,pid,t3ver_state')) {
-                                                               if ($wsAlt['t3ver_state'] != 4) {
+                                                               if (!VersionState::cast($wsAlt['t3ver_state'])->equals(VersionState::MOVE_POINTER)) {
                                                                        $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'State for version was not "4" as it should be!', $phrecCopy);
                                                                } else {
                                                                        $resultArray['versions_move_placeholders_ok'][$shortID] = array(
@@ -149,7 +158,7 @@ Automatic Repair:
                        if ((int) $cfg['ctrl']['versioningWS'] >= 2) {
                                $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid,t3ver_move_id,t3ver_wsid,t3ver_state', $table, 't3ver_move_id<>0' . BackendUtility::deleteClause($table));
                                foreach ($placeHolders as $phrec) {
-                                       if ((int) $phrec['t3ver_state'] == 3) {
+                                       if (VersionState::cast($phrec['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)) {
                                                if ($phrec['pid'] != -1) {
 
                                                } else {
index 9ac0cbd..a693bc7 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Version\DataHandler;
  ***************************************************************/
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Handles the \TYPO3\CMS\Core\DataHandling\DataHandler command map and is
@@ -740,7 +741,7 @@ class CommandMap {
                        /** @var $reference \TYPO3\CMS\Version\Dependency\ReferenceEntity */
                        $reference = $callerArguments['reference'];
                        $record = $reference->getElement()->getRecord();
-                       if ($record['t3ver_state'] != 2) {
+                       if (!VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
                                $response = \TYPO3\CMS\Version\Dependency\ElementEntity::RESPONSE_Skip;
                        }
                }
@@ -763,7 +764,7 @@ class CommandMap {
                        /** @var $reference \TYPO3\CMS\Version\Dependency\ReferenceEntity */
                        $reference = $callerArguments['reference'];
                        $record = $reference->getElement()->getRecord();
-                       if ($record['t3ver_state'] != 2) {
+                       if (!VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
                                $response = \TYPO3\CMS\Version\Dependency\ElementEntity::RESPONSE_Skip;
                        }
                }
index 12d14ce..eb113e8 100644 (file)
@@ -29,8 +29,10 @@ namespace TYPO3\CMS\Version\Hook;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Contains some parts for staging, versioning and workspaces
@@ -67,10 +69,10 @@ class DataHandlerHook {
        /**
         * hook that is called before any cmd of the commandmap is executed
         *
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj reference to the main tcemain object
+        * @param DataHandler $tcemainObj reference to the main tcemain object
         * @return void
         */
-       public function processCmdmap_beforeStart(\TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       public function processCmdmap_beforeStart(DataHandler $tcemainObj) {
                // Reset notification array
                $this->notificationEmailInfo = array();
                // Resolve dependencies of version/workspaces actions:
@@ -85,10 +87,10 @@ class DataHandlerHook {
         * @param integer $id the ID of the record
         * @param mixed $value the value containing the data
         * @param boolean $commandIsProcessed can be set so that other hooks or
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj reference to the main tcemain object
+        * @param DataHandler $tcemainObj reference to the main tcemain object
         * @return      void
         */
-       public function processCmdmap($command, $table, $id, $value, &$commandIsProcessed, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       public function processCmdmap($command, $table, $id, $value, &$commandIsProcessed, DataHandler $tcemainObj) {
                // custom command "version"
                if ($command == 'version') {
                        $commandIsProcessed = TRUE;
@@ -152,9 +154,9 @@ class DataHandlerHook {
         * @param string $table
         * @param integer $id
         * @param mixed $value
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemain
+        * @param DataHandler $tcemain
         */
-       public function processCmdmap_postProcess($command, $table, $id, $value, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemain) {
+       public function processCmdmap_postProcess($command, $table, $id, $value, DataHandler $tcemain) {
                if ($command === 'move') {
                        if ($value < 0) {
                                $movePlaceHolder = BackendUtility::getMovePlaceholder($table, abs($value), 'uid');
@@ -170,10 +172,10 @@ class DataHandlerHook {
         * hook that is called AFTER all commands of the commandmap was
         * executed
         *
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj reference to the main tcemain object
+        * @param DataHandler $tcemainObj reference to the main tcemain object
         * @return      void
         */
-       public function processCmdmap_afterFinish(\TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       public function processCmdmap_afterFinish(DataHandler $tcemainObj) {
                // Empty accumulation array:
                foreach ($this->notificationEmailInfo as $notifItem) {
                        $this->notifyStageChange($notifItem['shared'][0], $notifItem['shared'][1], implode(', ', $notifItem['elements']), 0, $notifItem['shared'][2], $tcemainObj, $notifItem['alternativeRecipients']);
@@ -192,10 +194,10 @@ class DataHandlerHook {
         * @param integer $id the ID of the record
         * @param array $record The accordant database record
         * @param boolean $recordWasDeleted can be set so that other hooks or
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj reference to the main tcemain object
+        * @param DataHandler $tcemainObj reference to the main tcemain object
         * @return      void
         */
-       public function processCmdmap_deleteAction($table, $id, array $record, &$recordWasDeleted, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       public function processCmdmap_deleteAction($table, $id, array $record, &$recordWasDeleted, DataHandler $tcemainObj) {
                // only process the hook if it wasn't processed
                // by someone else before
                if (!$recordWasDeleted) {
@@ -208,6 +210,7 @@ class DataHandlerHook {
                                        $id = $record['uid'];
                                }
                        }
+                       $recordVersionState = VersionState::cast($record['t3ver_state']);
                        // Look, if record is an offline version, then delete directly:
                        if ($record['pid'] == -1) {
                                if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
@@ -216,16 +219,17 @@ class DataHandlerHook {
                                                $liveRec = BackendUtility::getLiveVersionOfRecord($table, $id, 'uid,t3ver_state');
                                                // Processing can be skipped if a delete placeholder shall be swapped/published
                                                // during the current request. Thus it will be deleted later on...
-                                               if ($record['t3ver_state'] == 2 && !empty($liveRec['uid'])
+                                               $liveRecordVersionState = VersionState::cast($liveRec['t3ver_state']);
+                                               if ($recordVersionState->equals(VersionState::DELETE_PLACEHOLDER) && !empty($liveRec['uid'])
                                                        && !empty($tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['action'])
                                                        && !empty($tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['swapWith'])
                                                        && $tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['action'] === 'swap'
-                                                       && $tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['swapWith'] == $id) {
-
+                                                       && $tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['swapWith'] == $id
+                                               ) {
                                                        return NULL;
                                                }
 
-                                               if ($record['t3ver_wsid'] > 0 && $record['t3ver_state'] == 0) {
+                                               if ($record['t3ver_wsid'] > 0 && $recordVersionState->equals(VersionState::DEFAULT_STATE)) {
                                                        // Change normal versioned record to delete placeholder
                                                        // Happens when an edited record is deleted
                                                        $updateFields = array(
@@ -236,7 +240,7 @@ class DataHandlerHook {
                                                        // Delete localization overlays:
                                                        $tcemainObj->deleteL10nOverlayRecords($table, $id);
 
-                                               } elseif ($record['t3ver_wsid'] == 0 || (int) $liveRec['t3ver_state'] <= 0) {
+                                               } elseif ($record['t3ver_wsid'] == 0 || !$liveRecordVersionState->indicatesPlaceholder()) {
                                                        // Delete those in WS 0 + if their live records state was not "Placeholder".
                                                        $tcemainObj->deleteEl($table, $id);
                                                } else {
@@ -257,14 +261,14 @@ class DataHandlerHook {
                                } else {
                                        $tcemainObj->newlog('Stage of root point did not allow for deletion', 1);
                                }
-                       } elseif ((int) $record['t3ver_state'] === 3) {
+                       } elseif ($recordVersionState->equals(VersionState::MOVE_PLACEHOLDER)) {
                                // Placeholders for moving operations are deletable directly.
                                // Get record which its a placeholder for and reset the t3ver_state of that:
                                if ($wsRec = BackendUtility::getWorkspaceVersionOfRecord($record['t3ver_wsid'], $table, $record['t3ver_move_id'], 'uid')) {
                                        // Clear the state flag of the workspace version of the record
                                        // Setting placeholder state value for version (so it can know it is currently a new version...)
                                        $updateFields = array(
-                                               't3ver_state' => 0
+                                               't3ver_state' => (string)new VersionState(VersionState::DEFAULT_STATE)
                                        );
                                        $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($wsRec['uid']), $updateFields);
                                }
@@ -299,21 +303,26 @@ class DataHandlerHook {
         * @param boolean $recordWasMoved can be set so that other hooks or
         * @param       $table  the table
         */
-       public function moveRecord($table, $uid, $destPid, array $propArr, array $moveRec, $resolvedPid, &$recordWasMoved, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       public function moveRecord($table, $uid, $destPid, array $propArr, array $moveRec, $resolvedPid, &$recordWasMoved, DataHandler $tcemainObj) {
                // Only do something in Draft workspace
                if ($tcemainObj->BE_USER->workspace !== 0) {
                        $recordWasMoved = TRUE;
+                       $moveRecVersionState = VersionState::cast($moveRec['t3ver_state']);
                        // Get workspace version of the source record, if any:
                        $WSversion = BackendUtility::getWorkspaceVersionOfRecord($tcemainObj->BE_USER->workspace, $table, $uid, 'uid,t3ver_oid');
                        // If no version exists and versioningWS is in version 2, a new placeholder is made automatically:
-                       if (!$WSversion['uid'] && (int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2 && (int) $moveRec['t3ver_state'] != 3) {
+                       if (
+                               !$WSversion['uid']
+                               && (int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2
+                               && !$moveRecVersionState->equals(VersionState::MOVE_PLACEHOLDER)
+                       ) {
                                $tcemainObj->versionizeRecord($table, $uid, 'Placeholder version for moving record');
                                $WSversion = BackendUtility::getWorkspaceVersionOfRecord($tcemainObj->BE_USER->workspace, $table, $uid, 'uid,t3ver_oid');
                        }
                        // Check workspace permissions:
                        $workspaceAccessBlocked = array();
                        // Element was in "New/Deleted/Moved" so it can be moved...
-                       $recIsNewVersion = (int) $moveRec['t3ver_state'] > 0;
+                       $recIsNewVersion = $moveRecVersionState->indicatesPlaceholder();
                        $destRes = $tcemainObj->BE_USER->workspaceAllowLiveRecordsInPID($resolvedPid, $table);
                        $canMoveRecord = $recIsNewVersion || (int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2;
                        // Workspace source check:
@@ -361,11 +370,11 @@ class DataHandlerHook {
         * @param string $table Table name of element (or list of element names if $id is zero)
         * @param integer $id Record uid of element (if zero, then $table is used as reference to element(s) alone)
         * @param string $comment User comment sent along with action
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @param array $notificationAlternativeRecipients List of recipients to notify instead of be_users selected by sys_workspace, list is generated by workspace extension module
         * @return void
         */
-       protected function notifyStageChange(array $stat, $stageId, $table, $id, $comment, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj, array $notificationAlternativeRecipients = array()) {
+       protected function notifyStageChange(array $stat, $stageId, $table, $id, $comment, DataHandler $tcemainObj, array $notificationAlternativeRecipients = array()) {
                $workspaceRec = BackendUtility::getRecord('sys_workspace', $stat['uid']);
                // So, if $id is not set, then $table is taken to be the complete element name!
                $elementName = $id ? $table . ':' . $id : $table;
@@ -601,11 +610,11 @@ class DataHandlerHook {
         * @param integer $stageId Stage ID to set
         * @param string $comment Comment that goes into log
         * @param boolean $notificationEmailInfo Accumulate state changes in memory for compiled notification email?
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @param array $notificationAlternativeRecipients comma separated list of recipients to notify instead of normal be_users
         * @return void
         */
-       protected function version_setStage($table, $id, $stageId, $comment = '', $notificationEmailInfo = FALSE, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj, array $notificationAlternativeRecipients = array()) {
+       protected function version_setStage($table, $id, $stageId, $comment = '', $notificationEmailInfo = FALSE, DataHandler $tcemainObj, array $notificationAlternativeRecipients = array()) {
                if ($errorCode = $tcemainObj->BE_USER->workspaceCannotEditOfflineVersion($table, $id)) {
                        $tcemainObj->newlog('Attempt to set stage for record failed: ' . $errorCode, 1);
                } elseif ($tcemainObj->checkRecordUpdateAccess($table, $id)) {
@@ -647,11 +656,11 @@ class DataHandlerHook {
         * @param integer $uid Page uid to create new version of.
         * @param string $label Version label
         * @param integer $versionizeTree Indicating "treeLevel" - "page" (0) or "branch" (>=1) ["element" type must call versionizeRecord() directly]
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @return void
         * @see copyPages()
         */
-       protected function versionizePages($uid, $label, $versionizeTree, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       protected function versionizePages($uid, $label, $versionizeTree, DataHandler $tcemainObj) {
                $uid = intval($uid);
                // returns the branch
                $brExist = $tcemainObj->doesBranchExist('', $uid, $tcemainObj->pMap['show'], 1);
@@ -708,13 +717,13 @@ class DataHandlerHook {
         * @param integer $id UID of the online record to swap
         * @param integer $swapWith UID of the archived version to swap with!
         * @param boolean $swapIntoWS If set, swaps online into workspace instead of publishing out of workspace.
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @param string $comment Notification comment
         * @param boolean $notificationEmailInfo Accumulate state changes in memory for compiled notification email?
         * @param array $notificationAlternativeRecipients comma separated list of recipients to notificate instead of normal be_users
         * @return void
         */
-       protected function version_swap($table, $id, $swapWith, $swapIntoWS = 0, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj, $comment = '', $notificationEmailInfo = FALSE, $notificationAlternativeRecipients = array()) {
+       protected function version_swap($table, $id, $swapWith, $swapIntoWS = 0, DataHandler $tcemainObj, $comment = '', $notificationEmailInfo = FALSE, $notificationAlternativeRecipients = array()) {
                // First, check if we may actually edit the online record
                if ($tcemainObj->checkRecordUpdateAccess($table, $id)) {
                        // Select the two versions:
@@ -783,7 +792,7 @@ class DataHandlerHook {
                                                                                $swapVersion['t3ver_tstamp'] = $GLOBALS['EXEC_TIME'];
                                                                                $swapVersion['t3ver_stage'] = 0;
                                                                                if (!$swapIntoWS) {
-                                                                                       $swapVersion['t3ver_state'] = 0;
+                                                                                       $swapVersion['t3ver_state'] = (string)new VersionState(VersionState::DEFAULT_STATE);
                                                                                }
                                                                                // Moving element.
                                                                                if ((int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) {
@@ -793,7 +802,7 @@ class DataHandlerHook {
                                                                                                $movePlh['pid'] = $swapVersion['pid'];
                                                                                                $swapVersion['pid'] = intval($plhRec['pid']);
                                                                                                $curVersion['t3ver_state'] = intval($swapVersion['t3ver_state']);
-                                                                                               $swapVersion['t3ver_state'] = 0;
+                                                                                               $swapVersion['t3ver_state'] = (string)new VersionState(VersionState::DEFAULT_STATE);
                                                                                                if ($GLOBALS['TCA'][$table]['ctrl']['sortby']) {
                                                                                                        // sortby is a "keepFields" which is why this will work...
                                                                                                        $movePlh[$GLOBALS['TCA'][$table]['ctrl']['sortby']] = $swapVersion[$GLOBALS['TCA'][$table]['ctrl']['sortby']];
@@ -819,7 +828,7 @@ class DataHandlerHook {
                                                                                // Increment lifecycle counter
                                                                                $curVersion['t3ver_stage'] = 0;
                                                                                if (!$swapIntoWS) {
-                                                                                       $curVersion['t3ver_state'] = 0;
+                                                                                       $curVersion['t3ver_state'] = (string)new VersionState(VersionState::DEFAULT_STATE);
                                                                                }
                                                                                // Registering and swapping MM relations in current and swap records:
                                                                                $tcemainObj->version_remapMMForVersionSwap($table, $id, $swapWith);
@@ -942,10 +951,10 @@ class DataHandlerHook {
         * @param array $conf: TCA configuration of current field
         * @param array $curVersion: Reference to the current (original) record
         * @param array $swapVersion: Reference to the record (workspace/versionized) to publish in or swap with
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @return void
         */
-       protected function version_swap_procBasedOnFieldType($table, $field, array $conf, array &$curVersion, array &$swapVersion, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       protected function version_swap_procBasedOnFieldType($table, $field, array $conf, array &$curVersion, array &$swapVersion, DataHandler $tcemainObj) {
                $inlineType = $tcemainObj->getInlineFieldType($conf);
                // Process pointer fields on normalized database:
                if ($inlineType == 'field') {
@@ -1002,10 +1011,10 @@ class DataHandlerHook {
         * @param string $table Table name
         * @param integer $id Record UID
         * @param boolean $flush If set, will completely delete element
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @return      void
         */
-       protected function version_clearWSID($table, $id, $flush = FALSE, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       protected function version_clearWSID($table, $id, $flush = FALSE, DataHandler $tcemainObj) {
                if ($errorCode = $tcemainObj->BE_USER->workspaceCannotEditOfflineVersion($table, $id)) {
                        $tcemainObj->newlog('Attempt to reset workspace for record failed: ' . $errorCode, 1);
                } elseif ($tcemainObj->checkRecordUpdateAccess($table, $id)) {
@@ -1017,7 +1026,10 @@ class DataHandlerHook {
                                );
                                $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($id), $updateData);
                                // Clear workspace ID for live version AND DELETE IT as well because it is a new record!
-                               if ((int) $liveRec['t3ver_state'] == 1 || (int) $liveRec['t3ver_state'] == 2) {
+                               if (
+                                       VersionState::cast($liveRec['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER)
+                                       || VersionState::cast($liveRec['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+                               ) {
                                        $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($liveRec['uid']), $updateData);
                                        // THIS assumes that the record was placeholder ONLY for ONE record (namely $id)
                                        $tcemainObj->deleteEl($table, $liveRec['uid'], TRUE);
@@ -1025,7 +1037,13 @@ class DataHandlerHook {
                                // If "deleted" flag is set for the version that got released
                                // it doesn't make sense to keep that "placeholder" anymore and we delete it completly.
                                $wsRec = BackendUtility::getRecord($table, $id);
-                               if ($flush || ((int) $wsRec['t3ver_state'] == 1 || (int) $wsRec['t3ver_state'] == 2)) {
+                               if (
+                                       $flush
+                                       || (
+                                               VersionState::cast($wsRec['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER)
+                                               || VersionState::cast($wsRec['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
+                                       )
+                               ) {
                                        $tcemainObj->deleteEl($table, $id, TRUE, TRUE);
                                }
                                // Remove the move-placeholder if found for live record.
@@ -1050,11 +1068,11 @@ class DataHandlerHook {
         * @param integer $oldPageId Current page id.
         * @param integer $newPageId New page id
         * @param array $copyTablesArray Array of tables from which to copy
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @return void
         * @see versionizePages()
         */
-       protected function rawCopyPageContent($oldPageId, $newPageId, array $copyTablesArray, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       protected function rawCopyPageContent($oldPageId, $newPageId, array $copyTablesArray, DataHandler $tcemainObj) {
                if ($newPageId) {
                        foreach ($copyTablesArray as $table) {
                                // all records under the page is copied.
@@ -1191,18 +1209,18 @@ class DataHandlerHook {
        /**
         * Creates a move placeholder for workspaces.
         * USE ONLY INTERNALLY
-        * Moving placeholder: Can be done because the system sees it as a placeholder for NEW elements like t3ver_state=1
+        * Moving placeholder: Can be done because the system sees it as a placeholder for NEW elements like t3ver_state=VersionState::NEW_PLACEHOLDER
         * Moving original: Will either create the placeholder if it doesn't exist or move existing placeholder in workspace.
         *
         * @param string $table Table name to move
         * @param integer $uid Record uid to move (online record)
         * @param integer $destPid Position to move to: $destPid: >=0 then it points to a page-id on which to insert the record (as the first element). <0 then it points to a uid from its own table after which to insert it (works if
         * @param integer $wsUid UID of offline version of online record
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj TCEmain object
+        * @param DataHandler $tcemainObj TCEmain object
         * @return void
         * @see moveRecord()
         */
-       protected function moveRecord_wsPlaceholders($table, $uid, $destPid, $wsUid, \TYPO3\CMS\Core\DataHandling\DataHandler $tcemainObj) {
+       protected function moveRecord_wsPlaceholders($table, $uid, $destPid, $wsUid, DataHandler $tcemainObj) {
                // If a record gets moved after a record that already has a placeholder record
                // then the new placeholder record needs to be after the existing one
                $originalRecordDestinationPid = $destPid;
@@ -1241,7 +1259,7 @@ class DataHandlerHook {
                        $newVersion_placeholderFieldArray['t3ver_label'] = 'MOVE-TO PLACEHOLDER for #' . $uid;
                        $newVersion_placeholderFieldArray['t3ver_move_id'] = $uid;
                        // Setting placeholder state value for temporary record
-                       $newVersion_placeholderFieldArray['t3ver_state'] = 3;
+                       $newVersion_placeholderFieldArray['t3ver_state'] = (string)new VersionState(VersionState::MOVE_PLACEHOLDER);
                        // Setting workspace - only so display of place holders can filter out those from other workspaces.
                        $newVersion_placeholderFieldArray['t3ver_wsid'] = $tcemainObj->BE_USER->workspace;
                        $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = '[MOVE-TO PLACEHOLDER for #' . $uid . ', WS#' . $tcemainObj->BE_USER->workspace . ']';
@@ -1262,7 +1280,7 @@ class DataHandlerHook {
                        // Move the workspace-version of the original to be the version of the move-to-placeholder:
                        // Setting placeholder state value for version (so it can know it is currently a new version...)
                        $updateFields = array(
-                               't3ver_state' => 4
+                               't3ver_state' => (string)new VersionState(VersionState::MOVE_POINTER)
                        );
                        $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($wsUid), $updateFields);
                }
@@ -1294,11 +1312,11 @@ class DataHandlerHook {
        /**
         * Gets an instance of the command map helper.
         *
-        * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain TCEmain object
+        * @param DataHandler $tceMain TCEmain object
         * @param array $commandMap The command map as submitted to \TYPO3\CMS\Core\DataHandling\DataHandler
         * @return \TYPO3\CMS\Version\DataHandler\CommandMap
         */
-       public function getCommandMap(\TYPO3\CMS\Core\DataHandling\DataHandler $tceMain, array $commandMap) {
+       public function getCommandMap(DataHandler $tceMain, array $commandMap) {
                return GeneralUtility::makeInstance('TYPO3\\CMS\\Version\\DataHandler\\CommandMap', $this, $tceMain, $commandMap);
        }
 
index 1241e77..5ed832c 100644 (file)
@@ -27,6 +27,7 @@ namespace TYPO3\CMS\Version\Hook;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Implements a hook for \TYPO3\CMS\Backend\Utility\IconUtility
@@ -42,7 +43,12 @@ class IconUtilityHook {
         * @return void
         */
        public function overrideIconOverlay($table, array $row, array &$status) {
-               if (isset($row['t3ver_state']) && $row['t3ver_state'] == 2) {
+               if (
+                       isset($row['t3ver_state'])
+                       && VersionState::cast($row['t3ver_state'])->equals(
+                               \TYPO3\CMS\Core\Versioning\VersionState::DELETE_PLACEHOLDER
+                       )
+               ) {
                        $status['deleted'] = TRUE;
                }
        }
index cca2405..dc340f8 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Workspaces\Service;
  ***************************************************************/
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Service for integrity
@@ -142,7 +143,7 @@ class IntegrityService {
                                // Get localization parent from live workspace:
                                $languageParentRecord = BackendUtility::getRecord($table, $versionRow[$languageParentField], 'uid,t3ver_state');
                                // If localization parent is a "new placeholder" record:
-                               if ($languageParentRecord['t3ver_state'] == 1) {
+                               if (VersionState::cast($languageParentRecord['t3ver_state'])->equals(\TYPO3\CMS\Core\Type\VersionState::NEW_PLACEHOLDER)) {
                                        $title = BackendUtility::getRecordTitle($table, $versionRow);
                                        // Add warning for current versionized record:
                                        $this->addIssue($element->getLiveRecord()->getIdentifier(), self::STATUS_Warning, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.dependsOnDefaultLanguageRecord', 'workspaces'), $title));
index c958ed9..370a772 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Workspaces\Service;
  ***************************************************************/
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
  * Workspace service
@@ -253,7 +254,7 @@ class WorkspaceService implements \TYPO3\CMS\Core\SingletonInterface {
                }
                $from = $table . ' A,' . $table . ' B';
                // Table A is the offline version and pid=-1 defines offline
-               $where = 'A.pid=-1 AND A.t3ver_state!=4';
+               $where = 'A.pid=-1 AND A.t3ver_state!=' . new VersionState(VersionState::MOVE_POINTER);
                if ($pageList) {
                        $pidField = $table === 'pages' ? 'uid' : 'pid';
                        $pidConstraint = strstr($pageList, ',') ? ' IN (' . $pageList . ')' : '=' . $pageList;
@@ -309,7 +310,9 @@ class WorkspaceService implements \TYPO3\CMS\Core\SingletonInterface {
                // C - moveFrom placeholder
                $fields = 'A.pid AS wspid, B.uid AS t3ver_oid, C.uid AS uid, B.pid AS livepid';
                $from = $table . ' A, ' . $table . ' B,' . $table . ' C';
-               $where = 'A.t3ver_state=3 AND B.pid>0 AND B.t3ver_state=0 AND B.t3ver_wsid=0 AND C.pid=-1 AND C.t3ver_state=4';
+               $where = 'A.t3ver_state=' . new VersionState(VersionState::MOVE_PLACEHOLDER) . ' AND B.pid>0 AND B.t3ver_state='
+                       . new VersionState(VersionState::DEFAULT_STATE) . ' AND B.t3ver_wsid=0 AND C.pid=-1 AND C.t3ver_state='
+                       . new VersionState(VersionState::MOVE_POINTER);
                if ($wsid > self::SELECT_ALL_WORKSPACES) {
                        $where .= ' AND A.t3ver_wsid=' . $wsid . ' AND C.t3ver_wsid=' . $wsid;
                } elseif ($wsid === self::SELECT_ALL_WORKSPACES) {
@@ -481,12 +484,12 @@ class WorkspaceService implements \TYPO3\CMS\Core\SingletonInterface {
                        $whereClause .= BackendUtility::deleteClause('pages_language_overlay');
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('t3ver_state', 'pages_language_overlay', $whereClause);
                        if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                               $isNewPage = (int) $row['t3ver_state'] === 1;
+                               $isNewPage = VersionState::cast($row['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER);
                        }
                } else {
                        $rec = BackendUtility::getRecord('pages', $id, 't3ver_state');
                        if (is_array($rec)) {
-                               $isNewPage = (int) $rec['t3ver_state'] === 1;
+                               $isNewPage = VersionState::cast($rec['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER);
                        }
                }
                return $isNewPage;