major change of workflow/document management

This commit is contained in:
Uwe Steinmann 2018-03-28 17:04:39 +02:00
parent 3379a2510c
commit 5882fc10a9
4 changed files with 130 additions and 78 deletions

View File

@ -2270,11 +2270,14 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
return false; return false;
} }
/* Will be deleted automatically when record will be deleted
* from tblWorkflowDocumentContent
$queryStr = "DELETE FROM `tblWorkflowLog` WHERE `document` = '". $this->getID() ."' AND `version` = '" . $version->_version."'"; $queryStr = "DELETE FROM `tblWorkflowLog` WHERE `document` = '". $this->getID() ."' AND `version` = '" . $version->_version."'";
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
} }
*/
// remove document files attached to version // remove document files attached to version
$res = $this->getDocumentFiles($version->_version); $res = $this->getDocumentFiles($version->_version);
@ -5407,7 +5410,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db = $this->_document->_dms->getDB(); $db = $this->_document->_dms->getDB();
if($this->_workflow) { if($this->_workflow) {
$queryStr = "UPDATE `tblWorkflowDocumentContent` set `state`=". $state->getID() ." WHERE `workflow`=". intval($this->_workflow->getID()). " AND `document`=". intval($this->_document->getID()) ." AND version=". intval($this->_version) .""; $queryStr = "UPDATE `tblWorkflowDocumentContent` set `state`=". $state->getID() ." WHERE `id`=". $this->_workflow['id'];
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
return false; return false;
} }
@ -5434,9 +5437,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (!$this->_workflowState) { if (!$this->_workflowState) {
$queryStr= $queryStr=
"SELECT b.* FROM `tblWorkflowDocumentContent` a LEFT JOIN `tblWorkflowStates` b ON a.`state` = b.id WHERE `workflow`=". intval($this->_workflow->getID()) "SELECT b.* FROM `tblWorkflowDocumentContent` a LEFT JOIN `tblWorkflowStates` b ON a.`state` = b.id WHERE `a`.`id`=". $this->_workflow['id'];
." AND a.`version`='".$this->_version
."' AND a.`document` = '". $this->_document->getID() ."' ";
$recs = $db->getResultArray($queryStr); $recs = $db->getResultArray($queryStr);
if (is_bool($recs) && !$recs) if (is_bool($recs) && !$recs)
return false; return false;
@ -5455,6 +5456,9 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db = $this->_document->_dms->getDB(); $db = $this->_document->_dms->getDB();
$this->getWorkflow(); $this->getWorkflow();
if($this->_workflow)
return false;
if($workflow && is_object($workflow)) { if($workflow && is_object($workflow)) {
$db->startTransaction(); $db->startTransaction();
$initstate = $workflow->getInitState(); $initstate = $workflow->getInitState();
@ -5463,7 +5467,11 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
} }
$this->_workflow = $workflow; $this->getWorkflow();
if($workflow->getID() != $this->_workflow['workflow']->getID()) {
$db->rollbackTransaction();
return false;
}
if(!$this->setStatus(S_IN_WORKFLOW, "Added workflow '".$workflow->getName()."'", $user)) { if(!$this->setStatus(S_IN_WORKFLOW, "Added workflow '".$workflow->getName()."'", $user)) {
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
@ -5471,15 +5479,19 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->commitTransaction(); $db->commitTransaction();
return true; return true;
} }
return true; return false;
} /* }}} */ } /* }}} */
/** /**
* Get workflow assigned to the document content * Get workflow assigned to the document content
* *
* The method returns the last workflow if one was assigned. * The method returns the last workflow if one was assigned.
* If a the document version is in a sub workflow, it will have * If the document version is in a sub workflow, it will have
* a never date and therefore will be found first. * a never date and therefore will be found first.
* The methods also sets $this->_workflow['id'] and
* $this->_workflow['parent']. $this->_workflow['id'] is the
* id from table tblWorkflowDocumentContent which is used to
* get log entries for this workflow.
* *
* @return object/boolean an object of class SeedDMS_Core_Workflow * @return object/boolean an object of class SeedDMS_Core_Workflow
* or false in case of error, e.g. the version has not a workflow * or false in case of error, e.g. the version has not a workflow
@ -5489,18 +5501,19 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (!isset($this->_workflow)) { if (!isset($this->_workflow)) {
$queryStr= $queryStr=
"SELECT b.* FROM `tblWorkflowDocumentContent` a LEFT JOIN `tblWorkflows` b ON a.`workflow` = b.id WHERE a.`version`='".$this->_version "SELECT a.id as wdcid, a.parent, b.* FROM `tblWorkflowDocumentContent` a LEFT JOIN `tblWorkflows` b ON a.`workflow` = b.id WHERE a.`version`='".$this->_version
."' AND a.`document` = '". $this->_document->getID() ."' " ."' AND a.`document` = '". $this->_document->getID() ."' "
." AND a.`state` IS NOT NULL"
." ORDER BY `date` DESC LIMIT 1"; ." ORDER BY `date` DESC LIMIT 1";
$recs = $db->getResultArray($queryStr); $recs = $db->getResultArray($queryStr);
if (is_bool($recs) && !$recs) if (is_bool($recs) && !$recs)
return false; return false;
if(!$recs) if(!$recs)
return false; return false;
$this->_workflow = new SeedDMS_Core_Workflow($recs[0]['id'], $recs[0]['name'], $this->_document->_dms->getWorkflowState($recs[0]['initstate']), $recs[0]["layoutdata"]); $this->_workflow = array('id'=>(int)$recs[0]['wdcid'], 'parent'=>(int)$recs[0]['parent'], 'workflow'=>new SeedDMS_Core_Workflow($recs[0]['id'], $recs[0]['name'], $this->_document->_dms->getWorkflowState($recs[0]['initstate']), $recs[0]["layoutdata"]));
$this->_workflow->setDMS($this->_document->_dms); $this->_workflow['workflow']->setDMS($this->_document->_dms);
} }
return $this->_workflow; return $this->_workflow['workflow'];
} /* }}} */ } /* }}} */
/** /**
@ -5516,10 +5529,18 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
function rewriteWorkflowLog($workflowlog) { /* {{{ */ function rewriteWorkflowLog($workflowlog) { /* {{{ */
$db = $this->_document->_dms->getDB(); $db = $this->_document->_dms->getDB();
/* Get the workflowdocumentcontent */
$queryStr = "SELECT `id` FROM `tblWorkflowDocumentContent` WHERE `tblWorkflowDocumentContent`.`document` = '". $this->_document->getID() ."' AND `tblWorkflowDocumentContent`.`version` = '". $this->_version ."'";
$recs = $db->getResultArray($queryStr);
if (is_bool($recs) && !$recs)
return false;
if (!$recs)
return false;
$db->startTransaction(); $db->startTransaction();
/* First, remove the old entries */ /* First, remove the old entries */
$queryStr = "DELETE FROM `tblWorkflowLog` WHERE `tblWorkflowLog`.`document` = '". $this->_document->getID() ."' AND `tblWorkflowLog`.`version` = '". $this->_version ."'"; $queryStr = "DELETE FROM `tblWorkflowLog` WHERE `tblWorkflowLog`.`workflowdocumentcontent` IN (SELECT `id` FROM `tblWorkflowDocumentContent` WHERE `tblWorkflowDocumentContent`.`document` = '". $this->_document->getID() ."' AND `tblWorkflowDocumentContent`.`version` = '". $this->_version ."')";
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
@ -5532,8 +5553,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
} }
$queryStr = "INSERT INTO `tblWorkflowLog` (`document`, `version`, `workflow`, `transition`, `comment`, `date`, `userid`) ". $queryStr = "INSERT INTO `tblWorkflowLog` (`workflowdocumentcontent`, `transition`, `comment`, `date`, `userid`) ".
"VALUES ('".$this->_document->getID() ."', '".(int) $this->_version."', '".(int) $log['workflow']->getID()."', '".(int) $log['transition']->getID()."', ".$db->qstr($log['comment']) .", ".$db->qstr($log['date']).", ".$log['user']->getID().")"; "VALUES ('".$recs[0]['id'] ."', '".(int) $log['transition']->getID()."', ".$db->qstr($log['comment']) .", ".$db->qstr($log['date']).", ".$log['user']->getID().")";
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
@ -5558,15 +5579,16 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (!isset($this->_workflow)) { if (!isset($this->_workflow)) {
return true; return true;
} }
$workflow = $this->_workflow['workflow'];
$db->startTransaction(); $db->startTransaction();
$queryStr = "DELETE from `tblWorkflowLog` WHERE `document` = ". $this->_document->getID() ." AND `version` = ".$this->_version." AND `workflow` = ".$this->_workflow->getID(); $queryStr = "DELETE from `tblWorkflowLog` WHERE `workflowdocumentcontent` = ".$this->_workflow['id'];
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
} }
$this->setWorkflowState($this->_workflow->getInitState()); $this->setWorkflowState($workflow->getInitState());
$db->commitTransaction(); $db->commitTransaction();
return true; return true;
@ -5578,7 +5600,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* Fully removing a workflow including entries in the workflow log is * Fully removing a workflow including entries in the workflow log is
* only allowed if the workflow is still its initial state. * only allowed if the workflow is still its initial state.
* At a later point of time only unlinking the document from the * At a later point of time only unlinking the document from the
* workflow is allowed. It will keep any log entries. * workflow is allowed. It will keep any log entries and set the state
* to NULL.
* A workflow is unlinked from a document when enterNextState() * A workflow is unlinked from a document when enterNextState()
* succeeds. * succeeds.
* *
@ -5600,27 +5623,35 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return true; return true;
} }
if(SeedDMS_Core_DMS::checkIfEqual($this->_workflow->getInitState(), $this->getWorkflowState()) || $unlink == true) { $workflow = $this->_workflow['workflow'];
if(SeedDMS_Core_DMS::checkIfEqual($workflow->getInitState(), $this->getWorkflowState()) || $unlink == true) {
$db->startTransaction(); $db->startTransaction();
$queryStr= if($unlink) {
"DELETE FROM `tblWorkflowDocumentContent` WHERE "
."`version`='".$this->_version."' "
." AND `document` = '". $this->_document->getID() ."' "
." AND `workflow` = '". $this->_workflow->getID() ."' ";
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
if(!$unlink) {
$queryStr= $queryStr=
"DELETE FROM `tblWorkflowLog` WHERE " "UPDATE `tblWorkflowDocumentContent` SET `state` = NULL WHERE `id`=".$this->_workflow['id'];
."`version`='".$this->_version."' "
." AND `document` = '". $this->_document->getID() ."' "
." AND `workflow` = '". $this->_workflow->getID() ."' ";
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
} }
} else {
$queryStr=
"DELETE FROM `tblWorkflowDocumentContent` WHERE `id`=".$this->_workflow['id'];
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
/* will be deleted automatically when tblWorkflowDocumentContent is deleted
$queryStr=
"DELETE FROM `tblWorkflowLog` WHERE "
."`version`='".$this->_version."' "
." AND `document` = '". $this->_document->getID() ."' "
." AND `workflow` = '". $workflow->getID() ."' ";
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
*/
} }
$this->_workflow = null; $this->_workflow = null;
$this->_workflowState = null; $this->_workflowState = null;
@ -5644,19 +5675,19 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if(!$this->_workflow) if(!$this->_workflow)
return false; return false;
if(!$this->_workflow['parent'])
return false;
$queryStr= $queryStr=
"SELECT * FROM `tblWorkflowDocumentContent` WHERE " "SELECT * FROM `tblWorkflowDocumentContent` WHERE `parent`=".$this->_workflow['parent'];
."`version`='".$this->_version."' "
." AND `document` = '". $this->_document->getID() ."' "
." AND `workflow` = '". $this->_workflow->getID() ."' ";
$recs = $db->getResultArray($queryStr); $recs = $db->getResultArray($queryStr);
if (is_bool($recs) && !$recs) if (is_bool($recs) && !$recs)
return false; return false;
if(!$recs) if(!$recs)
return false; return false;
if($recs[0]['parentworkflow']) if($recs[0]['workflow'])
return $this->_document->_dms->getWorkflow($recs[0]['parentworkflow']); return $this->_document->_dms->getWorkflow((int)$recs[0]['workflow']);
return false; return false;
} /* }}} */ } /* }}} */
@ -5680,11 +5711,11 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if($subworkflow) { if($subworkflow) {
$initstate = $subworkflow->getInitState(); $initstate = $subworkflow->getInitState();
$queryStr = "INSERT INTO `tblWorkflowDocumentContent` (`parentworkflow`, `workflow`, `document`, `version`, `state`, `date`) VALUES (". $this->_workflow->getID(). ", ". $subworkflow->getID(). ", ". $this->_document->getID() .", ". $this->_version .", ".$initstate->getID().", ".$db->getCurrentDatetime().")"; $queryStr = "INSERT INTO `tblWorkflowDocumentContent` (`parent`, `workflow`, `document`, `version`, `state`, `date`) VALUES (". $this->_workflow['id']. ", ". $subworkflow->getID(). ", ". $this->_document->getID() .", ". $this->_version .", ".$initstate->getID().", ".$db->getCurrentDatetime().")";
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
return false; return false;
} }
$this->_workflow = $subworkflow; $this->_workflow = array('id'=>$db->getInsertID('tblWorkflowDocumentContent'), 'parent'=>$this->_workflow['id'], 'workflow'=>$subworkflow);
return true; return true;
} }
return true; return true;
@ -5709,30 +5740,23 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return false; return false;
if (isset($this->_workflow)) { if (isset($this->_workflow)) {
$workflow = $this->_workflow['workflow'];
$db->startTransaction(); $db->startTransaction();
$queryStr= $queryStr = "UPDATE `tblWorkflowDocumentContent` SET `state` = NULL WHERE `id` = '" . $this->_workflow['id']."'";
"SELECT * FROM `tblWorkflowDocumentContent` WHERE `workflow`=". intval($this->_workflow->getID())
. " AND `version`='".$this->_version
."' AND `document` = '". $this->_document->getID() ."' ";
$recs = $db->getResultArray($queryStr);
if (is_bool($recs) && !$recs) {
$db->rollbackTransaction();
return false;
}
if(!$recs) {
$db->rollbackTransaction();
return false;
}
$queryStr = "DELETE FROM `tblWorkflowDocumentContent` WHERE `workflow` =". intval($this->_workflow->getID())." AND `document` = '". $this->_document->getID() ."' AND `version` = '" . $this->_version."'";
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
$db->rollbackTransaction(); $db->rollbackTransaction();
return false; return false;
} }
$this->_workflow = $this->_document->_dms->getWorkflow($recs[0]['parentworkflow']); /* Calling getWorkflow() should find the parent workflow, better check */
$this->_workflow->setDMS($this->_document->_dms); $parent = $this->_workflow['parent'];
unset($this->_workflow);
$this->getWorkflow();
if($this->_workflow['id'] != $parent) {
$db->rollbackTransaction();
return false;
}
if($transition) { if($transition) {
if(false === $this->triggerWorkflowTransition($user, $transition, $comment)) { if(false === $this->triggerWorkflowTransition($user, $transition, $comment)) {
@ -5743,7 +5767,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->commitTransaction(); $db->commitTransaction();
} }
return $this->_workflow; return $this->_workflow['workflow'];
} /* }}} */ } /* }}} */
/** /**
@ -5770,7 +5794,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
/* Check if the user has already triggered the transition */ /* Check if the user has already triggered the transition */
$queryStr= $queryStr=
"SELECT * FROM `tblWorkflowLog` WHERE `version`='".$this->_version ."' AND `document` = '". $this->_document->getID() ."' AND `workflow` = ". $this->_workflow->getID(). " AND userid = ".$user->getID(); "SELECT * FROM `tblWorkflowLog` WHERE `workflowdocumentcontent` = ".$this->_workflow['id']." AND userid = ".$user->getID();
$queryStr .= " AND `transition` = ".$transition->getID(); $queryStr .= " AND `transition` = ".$transition->getID();
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && !$resArr) if (is_bool($resArr) && !$resArr)
@ -5918,8 +5942,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if(!$this->triggerWorkflowTransitionIsAllowed($user, $transition)) if(!$this->triggerWorkflowTransitionIsAllowed($user, $transition))
return false; return false;
$state = $this->_workflowState; $queryStr = "INSERT INTO `tblWorkflowLog` (`workflowdocumentcontent`, `userid`, `transition`, `date`, `comment`) VALUES (".$this->_workflow['id'].", ".(int) $user->getID(). ", ".(int) $transition->getID().", ".$db->getCurrentDatetime().", ".$db->qstr($comment).")";
$queryStr = "INSERT INTO `tblWorkflowLog` (`document`, `version`, `workflow`, `userid`, `transition`, `date`, `comment`) VALUES (".$this->_document->getID().", ".$this->_version.", " . (int) $this->_workflow->getID() . ", " .(int) $user->getID(). ", ".(int) $transition->getID().", ".$db->getCurrentDatetime().", ".$db->qstr($comment).")";
if (!$db->getResult($queryStr)) if (!$db->getResult($queryStr))
return false; return false;
@ -5970,8 +5993,9 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* the next state will be reached if one of the transitions * the next state will be reached if one of the transitions
* leading to the given state can be processed. * leading to the given state can be processed.
*/ */
if($nextstate->getPreCondFunc() == '') { if($nextstate->getPreCondFunc() == '') {
$transitions = $this->_workflow->getPreviousTransitions($nextstate); $workflow = $this->_workflow['workflow'];
$transitions = $workflow->getPreviousTransitions($nextstate);
foreach($transitions as $transition) { foreach($transitions as $transition) {
// echo "transition ".$transition->getID()." led to state ".$nextstate->getName()."<br />"; // echo "transition ".$transition->getID()." led to state ".$nextstate->getName()."<br />";
if($this->executeWorkflowTransitionIsAllowed($transition)) { if($this->executeWorkflowTransitionIsAllowed($transition)) {
@ -5996,7 +6020,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
/* make sure the users and groups allowed to trigger the next /* make sure the users and groups allowed to trigger the next
* transitions are also allowed to read the document * transitions are also allowed to read the document
*/ */
$transitions = $this->_workflow->getNextTransitions($nextstate); $transitions = $workflow->getNextTransitions($nextstate);
foreach($transitions as $tran) { foreach($transitions as $tran) {
// echo "checking access for users/groups allowed to trigger transition ".$tran->getID()."<br />"; // echo "checking access for users/groups allowed to trigger transition ".$tran->getID()."<br />";
$transusers = $tran->getUsers(); $transusers = $tran->getUsers();
@ -6035,24 +6059,27 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
/** /**
* Get the so far logged operations on the document content within the * Get the so far logged operations on the document content within the
* workflow * workflow. If the document content is currently in a workflow and
* a transition is passed, then the
* log entries will be restricted on the workflow and returned as one
* dimensional list. Without a running workflow the log entries of
* all workflows in the past are returned grouped by workflow.
* *
* @return array list of operations * @return array list of operations
*/ */
function getWorkflowLog($transition = null) { /* {{{ */ function getWorkflowLog($transition = null) { /* {{{ */
$db = $this->_document->_dms->getDB(); $db = $this->_document->_dms->getDB();
/*
if(!$this->_workflow) if(!$this->_workflow)
$this->getWorkflow(); $this->getWorkflow();
if(!$this->_workflow)
return false;
*/
$queryStr= $queryStr=
"SELECT * FROM `tblWorkflowLog` WHERE `version`='".$this->_version ."' AND `document` = '". $this->_document->getID() ."'"; // AND `workflow` = ". $this->_workflow->getID(); "SELECT `a`.`id`, `a`.`userid`, `a`.`transition`, `a`.`date`, `a`.`comment`, `a`.`workflowdocumentcontent`, `b`.`version`, `b`.`document`, `b`.`workflow` FROM `tblWorkflowLog` `a` LEFT JOIN `tblWorkflowDocumentContent` `b` ON `a`.`workflowdocumentcontent` = `b`.`id` WHERE `b`.`version`='".$this->_version ."' AND `b`.`document` = '". $this->_document->getID() ."'"; // AND `workflow` = ". $this->_workflow->getID();
if($transition) if($transition) {
$queryStr .= " AND `transition` = ".$transition->getID(); $queryStr .= " AND `a`.`transition` = ".$transition->getID();
}
if($this->_workflow)
$queryStr .= " AND `a`.`workflowdocumentcontent` = ".$this->_workflow['id'];
$queryStr .= " ORDER BY `date`"; $queryStr .= " ORDER BY `date`";
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && !$resArr) if (is_bool($resArr) && !$resArr)
@ -6063,7 +6090,10 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$workflow = $this->_document->_dms->getWorkflow($resArr[$i]["workflow"]); $workflow = $this->_document->_dms->getWorkflow($resArr[$i]["workflow"]);
$workflowlog = new SeedDMS_Core_Workflow_Log($resArr[$i]["id"], $this->_document->_dms->getDocument($resArr[$i]["document"]), $resArr[$i]["version"], $workflow, $this->_document->_dms->getUser($resArr[$i]["userid"]), $workflow->getTransition($resArr[$i]["transition"]), $resArr[$i]["date"], $resArr[$i]["comment"]); $workflowlog = new SeedDMS_Core_Workflow_Log($resArr[$i]["id"], $this->_document->_dms->getDocument($resArr[$i]["document"]), $resArr[$i]["version"], $workflow, $this->_document->_dms->getUser($resArr[$i]["userid"]), $workflow->getTransition($resArr[$i]["transition"]), $resArr[$i]["date"], $resArr[$i]["comment"]);
$workflowlog->setDMS($this); $workflowlog->setDMS($this);
$workflowlogs[$i] = $workflowlog; if($this->_workflow && $transition)
$workflowlogs[] = $workflowlog;
else
$workflowlogs[$resArr[$i]["workflowdocumentcontent"]][] = $workflowlog;
} }
return $workflowlogs; return $workflowlogs;
@ -6085,7 +6115,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return false; return false;
$queryStr= $queryStr=
"SELECT * FROM `tblWorkflowLog` WHERE `version`='".$this->_version ."' AND `document` = '". $this->_document->getID() ."' AND `workflow` = ". $this->_workflow->getID(); "SELECT * FROM `tblWorkflowLog` WHERE `workflowdocumentcontent` = ". $this->_workflow['id'];
$queryStr .= " ORDER BY `id` DESC LIMIT 1"; $queryStr .= " ORDER BY `id` DESC LIMIT 1";
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && !$resArr) if (is_bool($resArr) && !$resArr)
@ -6111,10 +6141,11 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
function needsWorkflowAction($user) { /* {{{ */ function needsWorkflowAction($user) { /* {{{ */
$needwkflaction = false; $needwkflaction = false;
if($this->_workflow) { if($this->_workflow) {
$workflow = $this->_workflow['workflow'];
if (!$this->_workflowState) if (!$this->_workflowState)
$this->getWorkflowState(); $this->getWorkflowState();
$workflowstate = $this->_workflowState; $workflowstate = $this->_workflowState;
$transitions = $this->_workflow->getNextTransitions($workflowstate); $transitions = $workflow->getNextTransitions($workflowstate);
foreach($transitions as $transition) { foreach($transitions as $transition) {
if($this->triggerWorkflowTransitionIsAllowed($user, $transition)) { if($this->triggerWorkflowTransitionIsAllowed($user, $transition)) {
$needwkflaction = true; $needwkflaction = true;

View File

@ -6,6 +6,24 @@ ALTER TABLE `tblUsers` ADD COLUMN `secret` varchar(50) DEFAULT NULL AFTER `pwd`;
ALTER TABLE `tblWorkflows` ADD COLUMN `layoutdata` text DEFAULT NULL AFTER `initstate`; ALTER TABLE `tblWorkflows` ADD COLUMN `layoutdata` text DEFAULT NULL AFTER `initstate`;
ALTER TABLE `tblWorkflowDocumentContent` ADD COLUMN `id` int(11) NOT NULL AUTO_INCREMENT UNIQUE FIRST;
ALTER TABLE `tblWorkflowLog` ADD COLUMN `workflowdocumentcontent` int(11) NOT NULL DEFAULT '0' AFTER `id`;
UPDATE `tblWorkflowLog` a, `tblWorkflowDocumentContent` b SET a.`workflowdocumentcontent` = b.`id` WHERE a.`document` = b.`document` AND a.`version` = b.`version` AND a.`workflow` = b.`workflow`;
INSERT INTO `tblWorkflowDocumentContent` (`parentworkflow`, `workflow`, `document`, `version`, `state`, `date`) SELECT 0 as `parentworkflow`, `workflow`, `document`, `version`, NULL as `state`, max(`date`) as `date` FROM `tblWorkflowLog` WHERE `workflowdocumentcontent` = 0 GROUP BY `workflow`, `document`, `version`;
UPDATE `tblWorkflowLog` a, `tblWorkflowDocumentContent` b SET a.`workflowdocumentcontent` = b.`id` WHERE a.`document` = b.`document` AND a.`version` = b.`version` AND a.`workflow` = b.`workflow`;
ALTER TABLE `tblWorkflowLog` ADD CONSTRAINT `tblWorkflowLog_workflowdocumentcontent` FOREIGN KEY (`workflowdocumentcontent`) REFERENCES `tblWorkflowDocumentContent` (`id`) ON DELETE CASCADE;
ALTER TABLE `tblWorkflowDocumentContent` ADD COLUMN `parent` int(11) DEFAULT NULL AFTER `id`;
ALTER TABLE `tblWorkflowDocumentContent` ADD CONSTRAINT `tblWorkflowDocumentContent_parent` FOREIGN KEY (`parent`) REFERENCES `tblWorkflowDocumentContent` (`id`) ON DELETE CASCADE;
ALTER TABLE `tblWorkflowDocumentContent` DROP COLUMN `parentworkflow`;
CREATE TABLE `tblUserSubstitutes` ( CREATE TABLE `tblUserSubstitutes` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`user` int(11) DEFAULT null, `user` int(11) DEFAULT null,

View File

@ -46,7 +46,7 @@ class SeedDMS_View_RewindWorkflow extends SeedDMS_Bootstrap_Style {
$this->contentHeading(getMLText("rewind_workflow")); $this->contentHeading(getMLText("rewind_workflow"));
$currentstate = $latestContent->getWorkflowState(); $currentstate = $latestContent->getWorkflowState();
$wkflog = $latestContent->getWorkflowLog(); $wkflog = array_pop($latestContent->getWorkflowLog());
$workflow = $latestContent->getWorkflow(); $workflow = $latestContent->getWorkflow();
$msg = "The document is currently in state: ".$currentstate->getName()."<br />"; $msg = "The document is currently in state: ".$currentstate->getName()."<br />";

View File

@ -750,11 +750,13 @@ class SeedDMS_View_ViewDocument extends SeedDMS_Bootstrap_Style {
if($wkflogs) { if($wkflogs) {
$this->contentHeading(getMLText("workflow_summary")); $this->contentHeading(getMLText("workflow_summary"));
$this->contentContainerStart(); $this->contentContainerStart();
foreach($wkflogs as $wkflogt) {
echo "<table class=\"table table-condensed\"><thead>"; echo "<table class=\"table table-condensed\"><thead>";
echo "<th>".getMLText('date')."</th><th>".getMLText('action')."</th><th>".getMLText('user')."</th><th>".getMLText('comment')."</th></tr>\n"; echo "<th>".getMLText('workflow')."</th><th>".getMLText('date')."</th><th>".getMLText('action')."</th><th>".getMLText('user')."</th><th>".getMLText('comment')."</th></tr>\n";
echo "</thead><tbody>"; echo "</thead><tbody>";
foreach($wkflogs as $wkflog) { foreach($wkflogt as $wkflog) {
echo "<tr>"; echo "<tr>";
echo "<td>".$wkflog->getWorkflow()->getName()."</td>";
echo "<td>".$wkflog->getDate()."</td>"; echo "<td>".$wkflog->getDate()."</td>";
echo "<td>".$wkflog->getTransition()->getAction()->getName()."</td>"; echo "<td>".$wkflog->getTransition()->getAction()->getName()."</td>";
$loguser = $wkflog->getUser(); $loguser = $wkflog->getUser();
@ -763,6 +765,7 @@ class SeedDMS_View_ViewDocument extends SeedDMS_Bootstrap_Style {
echo "</tr>"; echo "</tr>";
} }
print "</tbody>\n</table>\n"; print "</tbody>\n</table>\n";
}
$this->contentContainerEnd(); $this->contentContainerEnd();
} }
} }