From b624cd0a6158e2ed2a84acde332b25462386db02 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 1 Jun 2021 10:48:52 +0200 Subject: [PATCH] fix getWorkflowState(), can now handle empty state --- SeedDMS_Core/Core/inc.ClassDocument.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index c0850dabe..ccb05979a 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -4331,11 +4331,11 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ if (!$this->_workflowState) { $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.`state` IS NOT NULL AND `workflow`=". intval($this->_workflow->getID()) ." AND a.`version`='".$this->_version ."' AND a.`document` = '". $this->_document->getID() ."' "; $recs = $db->getResultArray($queryStr); - if (is_bool($recs) && !$recs) + if (!$recs) return false; $this->_workflowState = new SeedDMS_Core_Workflow_State($recs[0]['id'], $recs[0]['name'], $recs[0]['maxtime'], $recs[0]['precondfunc'], $recs[0]['documentstatus']); $this->_workflowState->setDMS($this->_document->getDMS()); @@ -4497,7 +4497,11 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ return true; } - if(SeedDMS_Core_DMS::checkIfEqual($this->_workflow->getInitState(), $this->getWorkflowState()) || $unlink == true) { + /* A workflow should always be in a state, but in case it isn't, the + * at least allow to remove the workflow. + */ + $currentstate = $this->getWorkflowState(); + if(!$currentstate || SeedDMS_Core_DMS::checkIfEqual($this->_workflow->getInitState(), $currentstate) || $unlink == true) { $db->startTransaction(); $queryStr= "DELETE FROM `tblWorkflowDocumentContent` WHERE "