Fixed bug #11144: Records that belong to a particular workspace shall be removed...
authorohader <ohader@743128fe-103e-dd11-99c4-001b210b3e58>
Tue, 30 Nov 2010 13:49:15 +0000 (13:49 +0000)
committerohader <ohader@743128fe-103e-dd11-99c4-001b210b3e58>
Tue, 30 Nov 2010 13:49:15 +0000 (13:49 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/CoreProjects/workspaces/workspaces/trunk@3141 743128fe-103e-dd11-99c4-001b210b3e58

typo3/sysext/workspaces/ChangeLog
typo3/sysext/workspaces/Classes/Service/Tcemain.php
typo3/sysext/workspaces/Classes/Service/Workspaces.php

index fcf38f9..83b3398 100644 (file)
@@ -4,6 +4,7 @@
        * Cleanup: Fixed PHPdoc comments and exception timestamp
        * Fixed bug #11115: ExtDirect exception sendToNextStageWindow: StageId is supposed to be an integer
        * Fixed task #11161: Simplify outputting errors from PHP to the grid component
+       * Fixed bug #11144: Records that belong to a particular workspace shall be removed when the workspace is removed
 
 2010-11-29  Sonja Scholz <ss@cabag.ch>
 
index 4821d0f..b5a1357 100644 (file)
@@ -42,23 +42,36 @@ class tx_Workspaces_Service_Tcemain {
         * @param string $table
         * @param string $id
         * @param string $value
-        * @param object $tcemain
+        * @param t3lib_TCEmain $tcemain
         * @return void
         */
-       public function processCmdmap_postProcess($command, $table, $id, $value, $tcemain) {
-
-               if (strcmp($command, 'delete') || strcmp($table, Tx_Workspaces_Service_Stages::TABLE_STAGE)) {
-                       return;
+       public function processCmdmap_postProcess($command, $table, $id, $value, t3lib_TCEmain $tcemain) {
+               if ($command === 'delete') {
+                       if ($table === Tx_Workspaces_Service_Stages::TABLE_STAGE) {
+                               $this->resetStageOfElements($id);
+                       } elseif ($table === tx_Workspaces_Service_Workspaces::TABLE_WORKSPACE) {
+                               $this->flushWorkspaceElements($id);
+                       }
                }
+       }
 
+       /**
+        * In case a sys_workspace_stage record is deleted we do a hard reset
+        * for all existing records in that stage to avoid that any of these end up
+        * as orphan records.
+        *
+        * @param integer $stageId Elements with this stage are resetted
+        * @return void
+        */
+       protected function resetStageOfElements($stageId) {
                $service = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
                        // @todo: remove the encode/decode functionality
-               $pseudoStageId = $service->encodeStageUid($id);
+               $pseudoStageId = $service->encodeStageUid($stageId);
 
                $fields = array('t3ver_stage' => Tx_Workspaces_Service_Stages::STAGE_EDIT_ID);
 
-               foreach ($GLOBALS['TCA'] as $tcaTable => $cfg) {
-                       if ($GLOBALS['TCA'][$tcaTable]['ctrl']['versioningWS']) {
+               foreach ($this->getTcaTables() as $tcaTable) {
+                       if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) {
 
                                $where = 't3ver_stage = ' . intval($pseudoStageId);
                                $where .= ' AND t3ver_wsid > 0 AND pid=-1';
@@ -69,6 +82,57 @@ class tx_Workspaces_Service_Tcemain {
                }
        }
 
+       /**
+        * Flushes elements of a particular workspace to avoid orphan records.
+        *
+        * @param integer $workspaceId The workspace to be flushed
+        * @return void
+        */
+       protected function flushWorkspaceElements($workspaceId) {
+               $command = array();
+
+               foreach ($this->getTcaTables() as $tcaTable) {
+                       if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) {
+                               $where = '1=1';
+                               $where .= t3lib_BEfunc::getWorkspaceWhereClause($tcaTable, $workspaceId);
+                               $where .= t3lib_BEfunc::deleteClause($tcaTable);
+
+                               $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $tcaTable, $where, '', '', '', 'uid');
+                               if (is_array($records)) {
+                                       foreach (array_keys($records) as $recordId) {
+                                               $command[$tcaTable][$recordId]['version']['action'] = 'flush';
+                                       }
+                               }
+                       }
+               }
+
+               if (count($command)) {
+                       $tceMain = $this->getTceMain();
+                       $tceMain->start(array(), $command);
+                       $tceMain->process_cmdmap();
+               }
+       }
+
+       /**
+        * Gets all defined TCA tables.
+        *
+        * @return array
+        */
+       protected function getTcaTables() {
+               return array_keys($GLOBALS['TCA']);
+       }
+
+       /**
+        * Gets a new instance of t3lib_TCEmain.
+        *
+        * @return t3lib_TCEmain
+        */
+       protected function getTceMain() {
+               $tceMain = t3lib_div::makeInstance('t3lib_TCEmain');
+               $tceMain->stripslashes_values = 0;
+               return $tceMain;
+       }
+
 }
 
 
index 8e25205..4172c52 100644 (file)
@@ -31,6 +31,7 @@
  * @subpackage Service
  */
 class tx_Workspaces_Service_Workspaces {
+       const TABLE_WORKSPACE = 'sys_workspace';
        const SELECT_ALL_WORKSPACES = -98;
        const LIVE_WORKSPACE_ID = 0;
        const DRAFT_WORKSPACE_ID = -1;