removeFromProcess() can transfer to new user for all processes

This commit is contained in:
Uwe Steinmann 2019-11-28 13:48:50 +01:00
parent e14e14ddb4
commit 1593ca5f34

View File

@ -897,27 +897,34 @@ class SeedDMS_Core_User { /* {{{ */
/**
* Remove user from all processes
*
* This method adds another log entry to the reviews and approvals
* This method adds another log entry to the reviews, approvals, receptions, revisions,
* 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 unless
* do so for each review/approval/reception/revision 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
* reviews/approvals/receptions/revisions 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.
* This behaviour can be changed by passing a list of states in the optional
* argument $states. Only reviews, etc. in the given state will be affected.
* This allows to remove the user only if the review, etc. has not been done
* (state = 0).
*
* The last optional parameter $newuser is for replacing the user currently in
* charge by another 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
* e.g. if passing array('review'=>array(0)), the method will operate on
* reviews which has not been touched yet.
* @param object user who is take over the processes
* @return boolean true on success or false in case of an error
*/
private function __removeFromProcesses($user, $states = array(), $newuser=null) { /* {{{ */
$db = $this->_dms->getDB();
/* Get a list of all reviews, even those of older document versions */
$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']))) {
@ -945,41 +952,92 @@ class SeedDMS_Core_User { /* {{{ */
}
$db->commitTransaction();
/* Get a list of all approvals, even those of older document versions */
$approvalStatus = $this->getApprovalStatus();
$db->startTransaction();
foreach ($approvalStatus["indstatus"] as $ai) {
if($ai['status'] != -2 && (!isset($states['approval']) || in_array($ai['status'], $states['approval']))) {
$queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $ai["approveID"] ."', '-2', 'Approver removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
$res=$db->getResult($queryStr);
if(!$res) {
$db->rollbackTransaction();
return false;
}
/* Only approvals not done already can be transferred to a new user */
if($newuser && $ai['status'] == 0) {
if($doc = $this->_dms->getDocument($ai['documentID'])) {
if($version = $doc->getContentByVersion($ai['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();
/* Get a list of all receptions, even those of older document versions */
$receiptStatus = $this->getReceiptStatus();
$db->startTransaction();
foreach ($receiptStatus["indstatus"] as $ri) {
if($ri['status'] != -2 && (!isset($states['receipt']) || in_array($ri['status'], $states['receipt']))) {
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $ri["receiptID"] ."', '-2', 'Recipient removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
$res=$db->getResult($queryStr);
if(!$res) {
$db->rollbackTransaction();
return false;
}
/* Only receptions 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->addIndRecipient($newuser, $user);
/* returns -3 if the user is already a recipient */
if($ret != 0 && $ret != -3) {
$db->rollbackTransaction();
return false;
}
}
}
}
}
}
$db->commitTransaction();
/* Get a list of all revisions, even those of older document versions */
$revisionStatus = $this->getRevisionStatus();
$db->startTransaction();
foreach ($revisionStatus["indstatus"] as $ri) {
if($ri['status'] != -2 && (!isset($states['revision']) || in_array($ri['status'], $states['revision']))) {
$queryStr = "INSERT INTO `tblDocumentRevisionLog` (`revisionID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $ri["revisionID"] ."', '-2', 'Revisor removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
$res=$db->getResult($queryStr);
if(!$res) {
$db->rollbackTransaction();
return false;
}
/* Only revisions 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->addIndRevisor($newuser, $user);
/* returns -3 if the user is already a revisor */
if($ret != 0 && $ret != -3) {
$db->rollbackTransaction();
return false;
}
}
}
}
}
}
$db->commitTransaction();
return true;
} /* }}} */