From 3011f96372e20792720d7fa0379b436735c876f6 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 28 Nov 2019 09:16:23 +0100 Subject: [PATCH] add optional parameter $newuser to removeFromProcesses() if set, the process will be transfered to a new user --- SeedDMS_Core/Core/inc.ClassUser.php | 31 +++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassUser.php b/SeedDMS_Core/Core/inc.ClassUser.php index 63714308a..9b3cab382 100644 --- a/SeedDMS_Core/Core/inc.ClassUser.php +++ b/SeedDMS_Core/Core/inc.ClassUser.php @@ -899,7 +899,8 @@ class SeedDMS_Core_User { /* {{{ */ * * This method adds another log entry to the reviews and approvals * which indicates the user has been deleted from the process. By default it will - * do so for each review/approval regardless of its current state. So even + * do so for each review/approval regardless of its current state unless + * the user has been removed already (status=-2). So even * reviews/approvals already processed by the user will be added the log * entry. Only if the last log entry was a removal already, it will not be * added a second time. @@ -907,24 +908,42 @@ class SeedDMS_Core_User { /* {{{ */ * @param object $user the user doing the removal (needed for entry in * review and approve log). * @param array $states remove user only from reviews/approvals in one of the states - * If passing array(0), the method will operate on reviews/approval which - * has not been touched. + * e.g. if passing array('review'=>array(0)), the method will operate on + * reviews which has not been touched yet. * @return boolean true on success or false in case of an error */ - private function __removeFromProcesses($user, $states = array()) { /* {{{ */ + private function __removeFromProcesses($user, $states = array(), $newuser=null) { /* {{{ */ $db = $this->_dms->getDB(); $reviewStatus = $this->getReviewStatus(); +// var_dump($newuser); +// print_r($reviewStatus);exit; + $db->startTransaction(); foreach ($reviewStatus["indstatus"] as $ri) { if($ri['status'] != -2 && (!isset($states['review']) || in_array($ri['status'], $states['review']))) { $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ". "VALUES ('". $ri["reviewID"] ."', '-2', 'Reviewer removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')"; $res=$db->getResult($queryStr); if(!$res) { + $db->rollbackTransaction(); return false; } + /* Only reviews not done already can be transferred to a new user */ + if($newuser && $ri['status'] == 0) { + if($doc = $this->_dms->getDocument($ri['documentID'])) { + if($version = $doc->getContentByVersion($ri['version'])) { + $ret = $version->addIndReviewer($newuser, $user); + /* returns -3 if the user is already a reviewer */ + if($ret != 0 && $ret != -3) { + $db->rollbackTransaction(); + return false; + } + } + } + } } } + $db->commitTransaction(); $approvalStatus = $this->getApprovalStatus(); foreach ($approvalStatus["indstatus"] as $ai) { @@ -975,11 +994,11 @@ class SeedDMS_Core_User { /* {{{ */ * @param array $states remove user only from reviews/approvals in one of the states * @return boolean true on success or false in case of an error */ - public function removeFromProcesses($user, $states=array()) { /* {{{ */ + public function removeFromProcesses($user, $states=array(), $newuser=null) { /* {{{ */ $db = $this->_dms->getDB(); $db->startTransaction(); - if(!$this->__removeFromProcesses($user, $states)) { + if(!$this->__removeFromProcesses($user, $states, $newuser)) { $db->rollbackTransaction(); return false; }