Project

General

Profile

Feature #2795 » patch-2795.txt

Sonja Schubert, 2009-03-09 15:08

 
### Eclipse Workspace Patch 1.0
#P igeworkspace42
Index: typo3/mod/user/ws/class.wsstagelib.php
===================================================================
--- typo3/mod/user/ws/class.wsstagelib.php (revision 0)
+++ typo3/mod/user/ws/class.wsstagelib.php (revision 0)
@@ -0,0 +1,182 @@
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2009 Sonja Scholz (ss@cabag.ch)
+* 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!
+***************************************************************/
+/**
+ * Library with Workspace related functionality
+ *
+ * @author Sonja Scholz <ss@cabag.ch>
+ */
+/**
+ * [CLASS/FUNCTION INDEX of SCRIPT]
+ *
+ *
+ *
+ * 68: class wsstagelib
+ * 81: function getCmdArrayForPublishWS($wsid, $doSwap,$pageId=0)
+ * 127: function selectVersionsInWorkspace($wsid,$filter=0,$stage=-99,$pageId=-1)
+ *
+ * SECTION: CLI functions
+ * 183: function CLI_main()
+ * 193: function autoPublishWorkspaces()
+ *
+ * TOTAL FUNCTIONS: 4
+ * (This index is automatically created/updated by the extension "extdeveval")
+ *
+ */
+
+
+
+
+
+
+
+
+
+
+
+
+/**
+ * Library with Workspace related functionality
+ *
+ * @author Sonja Scholz <ss@cabag.ch>
+ * @package TYPO3
+ * @subpackage core
+ */
+class wsstagelib {
+
+ /**
+ * Building an array with all stage ids and titles related to the given workspace
+ *
+ * @return array id and title of the stages
+ */
+ function getStagesForWS($wsid) {
+ $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace',$wsid);
+ if($workspaceRec['use_custom_staging'] == '1') {
+ // Get all stage records for this workspace
+ $workspaceStageRecs = t3lib_BEfunc::getRecordsByField('sys_workspace_stage', 'parentid', $wsid, "AND parenttable='sys_workspace' ", '', $orderBy = 'sorting');
+ return $workspaceStageRecs;
+ } else {
+ return false;
+ }
+ }
+
+
+ /**
+ * Check if given workspace has custom staging activated
+ *
+ * @return bool true or false
+ */
+ function checkCustomStagingForWS($wsid) {
+ $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace',$wsid);
+ if($workspaceRec['use_custom_staging'] == '1') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ /**
+ * Get next stage in process for given stage id
+ *
+ * @param int workspace id
+ * @param int stageid
+ * @return int id
+ */
+ function getNextStage($wsid,$stageid) {
+ $workspaceStageRecs = $this->getStagesForWS($wsid);
+ if(is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
+ $nextStage = array();
+
+ // If current stage is the standart edit stage, next stage is the first custom stage
+ if($stageid === '0') {
+ $nextStage = $workspaceStageRecs[0];
+ $nextStage['uid'] = $nextStage['uid']+20;
+ return $nextStage;
+ }
+
+ while (list($array_key, $workspaceStageRec) = each($workspaceStageRecs)) {
+ if($workspaceStageRec['uid'] == ($stageid-20)) {
+ // Get the following value from the result array
+ list(,$nextStage) = each($workspaceStageRecs);
+ // check if there is a next stage or if the current stage is the last before publish
+ if($workspaceStageRecs[$array_key+1]) {
+ $nextStage = $workspaceStageRecs[$array_key+1];
+ $nextStage['uid'] = $nextStage['uid']+20;
+ } else {
+ $nextStage['uid'] = '10';
+ }
+ }
+ }
+ return $nextStage;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Get next stage in process for given stage id
+ *
+ * @param int workspace id
+ * @param int stageid
+ * @return int id
+ */
+ function getPrevStage($wsid,$stageid) {
+ $workspaceStageRecs = $this->getStagesForWS($wsid);
+ if(is_array($workspaceStageRecs) && !empty($workspaceStageRecs)) {
+ $prevStage = array();
+ // If the current stage is 10 then the prev stage is the last of the custom stages
+ if($stageid == '10') {
+ $prevStage = end($workspaceStageRecs);
+ $prevStage['uid'] = $prevStage['uid']+20;
+ } else {
+ while (list($array_key, $workspaceStageRec) = each($workspaceStageRecs)) {
+ if($workspaceStageRec['uid'] == ($stageid-20)) {
+ // check if there is a prev stage or if the current stage is the first custom stage
+ if($workspaceStageRecs[$array_key-1]) {
+ $prevStage = $workspaceStageRecs[$array_key-1];
+ $prevStage['uid'] = $prevStage['uid']+20;
+ } else {
+ // First stage is always the standart edit stage
+ $prevStage['uid'] = '0';
+ return $prevStage;
+ }
+ }
+ }
+ }
+ return $prevStage;
+ } else {
+ return false;
+ }
+ }
+}
+
+
+
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.wsstagelib.php']) {
+ include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.wslib.php']);
+}
+?>
\ No newline at end of file
Index: typo3/mod/user/ws/index.php
===================================================================
--- typo3/mod/user/ws/index.php (revision 270)
+++ typo3/mod/user/ws/index.php (working copy)
@@ -82,6 +82,7 @@
$LANG->includeLLFile('EXT:lang/locallang_misc.xml');
require_once(PATH_t3lib.'class.t3lib_scbase.php');
require_once(PATH_typo3.'mod/user/ws/class.wslib.php');
+require_once(PATH_typo3.'mod/user/ws/class.wsstagelib.php');
require_once(PATH_typo3.'mod/user/ws/class.wslib_gui.php');
require_once(PATH_t3lib.'class.t3lib_diff.php');
require_once(PATH_t3lib.'class.t3lib_pagetree.php');
@@ -177,6 +178,7 @@
*/
function execute() {
$post = t3lib_div::_POST();
+ $post = array_merge($post, t3lib_div::_GET());
# debug($post);
@@ -224,6 +226,15 @@
case "flush":
$cmdArray[$table][$uid]['version']['action'] = 'flush';
break;
+ default:
+ // Initialize workspace stage object
+ $wsstagelibObj = t3lib_div::makeInstance('wsstagelib');
+ if($wsstagelibObj->checkCustomStagingForWS($post['wsid'])) {
+ $cmdArray[$table][$uid]['version']['action'] = 'setStage';
+ $cmdArray[$table][$uid]['version']['stageId'] = str_replace('stage_','',$post['_with_selected_do']);
+ $cmdArray[$table][$uid]['version']['comment'] = $post['comments'];
+ }
+ break;
}
}
}
@@ -280,7 +291,7 @@
}
');
$this->doc->form = '<form action="index.php" method="post" name="pageform">';
-
+
// Setting up the context sensitive menu:
$this->doc->getContextMenuCode();
Index: typo3/mod/user/ws/class.wslib_gui.php
===================================================================
--- typo3/mod/user/ws/class.wslib_gui.php (revision 270)
+++ typo3/mod/user/ws/class.wslib_gui.php (working copy)
@@ -70,6 +70,7 @@
*/
require_once(PATH_typo3 . 'mod/user/ws/class.wslib.php');
+require_once(PATH_typo3 . 'mod/user/ws/class.wsstagelib.php');
$LANG->includeLLFile('EXT:lang/locallang_mod_user_ws.xml');
$LANG->includeLLFile('EXT:lang/locallang_misc.xml');
@@ -137,6 +138,9 @@
// Initialize workspace object and request all pending versions:
$wslibObj = t3lib_div::makeInstance('wslib');
+
+ // Initialize workspace stage object
+ $wsstagelibObj = t3lib_div::makeInstance('wsstagelib');
// Selecting ALL versions belonging to the workspace:
$versions = $wslibObj->selectVersionsInWorkspace($this->workspaceId, $filter, -99, $pageId);
@@ -187,28 +191,39 @@
if ($workspaceOverviewList || $this->alwaysDisplayHeader) {
// Make header of overview:
$tableRows = array();
- $tableRows[] = '
+ $tableHead = '';
+ $tableHead = '
<tr class="bgColor5 tableheader">
<td nowrap="nowrap" width="100">' . $LANG->getLL('label_pagetree') . '</td>
<td nowrap="nowrap" colspan="2">' . $LANG->getLL('label_live_version') . '</td>
<td nowrap="nowrap" colspan="2">' . $LANG->getLL('label_draft_versions') . '</td>
<td nowrap="nowrap">' . $LANG->getLL('label_stage') . '</td>
<td nowrap="nowrap">' . $LANG->getLL('label_publish') . '</td>
- <td><select name="_with_selected_do" onchange="if (confirm(\'Sure you want to perform this action with selected elements?\')) {document.forms[0].submit();}">
+ <td><select name="_with_selected_do" onchange="if (confirm(\'Sure you want to perform this action with selected elements?\')) {if(this.value == \'custom_stage\') { document.forms[0].action=\''.$this->doc->backPath.'mod.php?M=user_txversionM2\';document.forms[0].submit(); } else {document.forms[0].submit();}}">
<option value="_">Do:</option>
<option value="publish">Publish</option>
<option value="swap">Swap</option>
- <option value="release">Release</option>
- <option value="stage_-1">Stage: Reject</option>
+ <option value="release">Release</option>';
+
+ // Check if custom staging was choosed in workspace configuration
+ if($wsstagelibObj->checkCustomStagingForWS($this->workspaceId)) {
+ $tableHead .= '
+ <option value="custom_stage">Custom staging</option>';
+ } else {
+ $tableHead .= '<option value="stage_-1">Stage: Reject</option>
<option value="stage_0">Stage: Editing</option>
<option value="stage_1">Stage: Review</option>
- <option value="stage_10">Stage: Publish</option>
- <option value="flush">Flush (Delete)</option>
+ <option value="stage_10">Stage: Publish</option>';
+ }
+
+ $tableHead .= '<option value="flush">Flush (Delete)</option>
</select></td>
<td>' . $LANG->getLL('label_lifecycle') . '</td>
'.($this->showWorkspaceCol ? '<td>' . $LANG->getLL('label_workspace') . '</td>' : '').'
</tr>';
-
+
+ $tableRows[] = $tableHead;
+
// Add lines from overview:
$tableRows = array_merge($tableRows, $workspaceOverviewList);
@@ -341,6 +356,9 @@
// Initialize:
$fullColSpan = $this->showWorkspaceCol ? 10 : 9;
+
+ // Initialize workspace stage object
+ $wsstagelibObj = t3lib_div::makeInstance('wsstagelib');
// Traverse $pArray
if (is_array($pArray)) {
@@ -501,22 +519,41 @@
$verElement.
$subElements['off'].
'</td>';
-
- // Compile table row:
- $tableRows[] = '
- <tr class="bgColor4">
- '.$mainCell.$verCell.'
- <td nowrap="nowrap">'.$this->showStageChangeLog($table,$rec_off['uid'],$this->displayWorkspaceOverview_stageCmd($table,$rec_off)).'</td>
- <td nowrap="nowrap" class="'.$swapClass.'">'.
- $this->displayWorkspaceOverview_commandLinks($table,$rec_on,$rec_off,$vType).
- htmlspecialchars($swapLabel).
- '</td>
- <td nowrap="nowrap" align="center"><input type="checkbox" name="items['.$table.':'.$rec_off['uid'].']" id="items['.$table.':'.$rec_off['uid'].']" value="1"/></td>
- <td nowrap="nowrap">'.htmlspecialchars($this->formatCount($rec_off['t3ver_count'])).'</td>'. // Lifecycle
- ($this->showWorkspaceCol ? '
- <td nowrap="nowrap">'.htmlspecialchars($this->formatWorkspace($rec_off['t3ver_wsid'])).'</td>' : '').'
- </tr>';
-
+
+ // Check if custom staging is activated in workspace configuration
+ if($wsstagelibObj->checkCustomStagingForWS($this->workspaceId)) {
+ // Compile table row:
+ $tableRows[] = '
+ <tr class="bgColor4">
+ '.$mainCell.$verCell.'
+ <td nowrap="nowrap">'.$this->showStageChangeLog($table,$rec_off['uid'],$this->displayWorkspaceOverview_stageCmd($table,$rec_off)).'</td>
+ <td nowrap="nowrap" class="'.$swapClass.'">'.
+ $this->displayWorkspaceOverview_commandLinks($table,$rec_on,$rec_off,$vType).
+ htmlspecialchars($swapLabel).
+ '</td>
+ <td nowrap="nowrap" align="center"><input type="checkbox" name="items['.$table.':'.$rec_off['uid'].':'.$rec_off['t3ver_stage'].':'.$rec_off['t3ver_wsid'].']" id="items['.$table.':'.$rec_off['uid'].']" value="1"/>
+ </td>
+ <td nowrap="nowrap">'.htmlspecialchars($this->formatCount($rec_off['t3ver_count'])).'</td>'. // Lifecycle
+ ($this->showWorkspaceCol ? '
+ <td nowrap="nowrap">'.htmlspecialchars($this->formatWorkspace($rec_off['t3ver_wsid'])).'</td>' : '').'
+ </tr>';
+ } else {
+ // Compile table row:
+ $tableRows[] = '
+ <tr class="bgColor4">
+ '.$mainCell.$verCell.'
+ <td nowrap="nowrap">'.$this->showStageChangeLog($table,$rec_off['uid'],$this->displayWorkspaceOverview_stageCmd($table,$rec_off)).'</td>
+ <td nowrap="nowrap" class="'.$swapClass.'">'.
+ $this->displayWorkspaceOverview_commandLinks($table,$rec_on,$rec_off,$vType).
+ htmlspecialchars($swapLabel).
+ '</td>
+ <td nowrap="nowrap" align="center"><input type="checkbox" name="items['.$table.':'.$rec_off['uid'].']" id="items['.$table.':'.$rec_off['uid'].']" value="1"/></td>
+ <td nowrap="nowrap">'.htmlspecialchars($this->formatCount($rec_off['t3ver_count'])).'</td>'. // Lifecycle
+ ($this->showWorkspaceCol ? '
+ <td nowrap="nowrap">'.htmlspecialchars($this->formatWorkspace($rec_off['t3ver_wsid'])).'</td>' : '').'
+ </tr>';
+ }
+
// Reset the main cell:
$mainCell = '';
}
@@ -835,10 +872,21 @@
$text = $LANG->getLL('stage_reset_to_editing');
break;
default:
- $text = $LANG->getLL('stage_undefined');
- break;
+ // Initialize workspace stage object
+ $wsstagelibObj = t3lib_div::makeInstance('wsstagelib');
+ // Check if custom staging is activated in workspace configuration
+ if($wsstagelibObj->checkCustomStagingForWS($this->workspaceId)) {
+ $workspaceStageRec = t3lib_BEfunc::getRecord('sys_workspace_stage',$data['stage']-20);
+ if($workspaceStageRec) {
+ $text = $LANG->getLL('stage_custom');
+ $stagetitle = $workspaceStageRec['title'];
+ }
+ } else {
+ $text = $LANG->getLL('stage_undefined');
+ }
+ break;
}
- $text = t3lib_BEfunc::datetime($dat['tstamp']).': ' . sprintf($text, $username);
+ $text = t3lib_BEfunc::datetime($dat['tstamp']).': ' . sprintf($text, $username, $stagetitle);
$text.= ($data['comment']?'<br/>' . $LANG->getLL('stage_label_user_comment'). ' <em>'.htmlspecialchars($data['comment']).'</em>':'');
$entry[] = $text;
@@ -1215,6 +1263,11 @@
*/
function displayWorkspaceOverview_stageCmd($table,&$rec_off) {
global $LANG;
+
+ $this->workspaceId = (!is_null($wsid) ? $wsid : $GLOBALS['BE_USER']->workspace);
+
+ // Initialize workspace stage object
+ $wsstagelibObj = t3lib_div::makeInstance('wsstagelib');
switch((int)$rec_off['t3ver_stage']) {
case 0:
@@ -1246,6 +1299,20 @@
$sLabel = $LANG->getLL('label_undefined');
$sId = 0;
$color = '';
+
+ // Check if custom staging is activated in workspace configuration
+ if($wsstagelibObj->checkCustomStagingForWS($this->workspaceId)) {
+ $workspaceStageRec = t3lib_BEfunc::getRecord('sys_workspace_stage',$rec_off['t3ver_stage']-20);
+ if($workspaceStageRec) {
+ $sLabel = $workspaceStageRec['title'];
+ // Next custom stage
+ $nextStage = $wsstagelibObj->getNextStage($this->workspaceId,$rec_off['t3ver_stage']);
+ // ID of next stage
+ $sId = $nextStage['uid'];
+ $color = '#999999';
+ $titleAttrib = $LANG->getLL('label_sendToNextStage');
+ }
+ }
break;
}
#debug($sId);
@@ -1253,12 +1320,21 @@
$raiseOk = !$GLOBALS['BE_USER']->workspaceCannotEditOfflineVersion($table,$rec_off);
if ($raiseOk && $rec_off['t3ver_stage']!=-1) {
- $onClick = 'var commentTxt=window.prompt("'.$LANG->getLL('explain_reject').'","");
- if (commentTxt!=null) {window.location.href="'.$this->doc->issueCommand(
- '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
- '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]=-1'
- ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
- ' return false;';
+ // Check if custom staging is activated in workspace configuration
+ if($wsstagelibObj->checkCustomStagingForWS($rec_off['t3ver_wsid'])) {
+ // Reject id for custom stage reject is -21 instead of -1
+ $onClick = 'var commentTxt=null;window.location.href="'.
+ $this->doc->backPath.'mod.php?M=user_txversionM2'.
+ '&items['.$table.':'.$rec_off['uid'].':'.$rec_off['t3ver_stage'].':'.$rec_off['t3ver_wsid'].']=1";'.
+ ' return false;';
+ } else {
+ $onClick = 'var commentTxt=window.prompt("'.$LANG->getLL('explain_reject').'","");
+ if (commentTxt!=null) {window.location.href="'.$this->doc->issueCommand(
+ '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
+ '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]=-1'
+ ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
+ ' return false;';
+ }
// Reject:
$actionLinks.=
'<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
@@ -1272,15 +1348,23 @@
// TODO Use CSS?
$actionLinks.= '<span style="background-color: '.$color.'; color: white;">'.$sLabel.'</span>';
-
+
+
// Raise
if ($raiseOk) {
- $onClick = 'var commentTxt=window.prompt("'.$label.'","");
- if (commentTxt!=null) {window.location.href="'.$this->doc->issueCommand(
- '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
- '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]='.$sId
- ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
- ' return false;';
+ if($wsstagelibObj->checkCustomStagingForWS($rec_off['t3ver_wsid'])) {
+ $onClick = 'var commentTxt=null;window.location.href="'.
+ $this->doc->backPath.'mod.php?M=user_txversionM2'.
+ '&items['.$table.':'.$rec_off['uid'].':'.$rec_off['t3ver_stage'].':'.$rec_off['t3ver_wsid'].']=1";'.
+ ' return false;';
+ } else {
+ $onClick = 'var commentTxt=window.prompt("'.$label.'","");
+ if (commentTxt!=null) {window.location.href="'.$this->doc->issueCommand(
+ '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
+ '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]='.$sId
+ ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
+ ' return false;';
+ }
if ($rec_off['t3ver_stage']!=10) {
$actionLinks.=
'<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
(1-1/3)