various minor changes ported back from SeedDMS 6

This commit is contained in:
Uwe Steinmann 2021-09-28 16:20:33 +02:00
parent b8763822d0
commit 007e3faa0a
4 changed files with 50 additions and 26 deletions

View File

@ -347,9 +347,11 @@ class SeedDMS_Core_DMS {
*/ */
static function filterDocumentFiles($user, $files) { /* {{{ */ static function filterDocumentFiles($user, $files) { /* {{{ */
$tmp = array(); $tmp = array();
foreach ($files as $file) if($files) {
if ($file->isPublic() || ($file->getUser()->getID() == $user->getID()) || $user->isAdmin() || ($file->getDocument()->getOwner()->getID() == $user->getID())) foreach ($files as $file)
array_push($tmp, $file); if ($file->isPublic() || ($file->getUser()->getID() == $user->getID()) || $user->isAdmin() || ($file->getDocument()->getOwner()->getID() == $user->getID()))
array_push($tmp, $file);
}
return $tmp; return $tmp;
} /* }}} */ } /* }}} */
@ -374,6 +376,7 @@ class SeedDMS_Core_DMS {
$this->forceRename = false; $this->forceRename = false;
$this->checkWithinRootDir = false; $this->checkWithinRootDir = false;
$this->noReadForStatus = array(); $this->noReadForStatus = array();
$this->user = null;
$this->classnames = array(); $this->classnames = array();
$this->classnames['folder'] = 'SeedDMS_Core_Folder'; $this->classnames['folder'] = 'SeedDMS_Core_Folder';
$this->classnames['document'] = 'SeedDMS_Core_Document'; $this->classnames['document'] = 'SeedDMS_Core_Document';
@ -589,8 +592,9 @@ class SeedDMS_Core_DMS {
/** /**
* Set the logged in user * Set the logged in user
* *
* If user authentication was done externally, this function can * This method tells SeeDMS_Core_DMS the currently logged in user. It must be
* be used to tell the dms who is currently logged in. * called right after instanciating the class, because some methods in
* SeedDMS_Core_Document() require the currently logged in user.
* *
* @param object $user this muss not be empty and an instance of SeedDMS_Core_User * @param object $user this muss not be empty and an instance of SeedDMS_Core_User
* @return bool|object returns the old user object or null on success, otherwise false * @return bool|object returns the old user object or null on success, otherwise false
@ -613,8 +617,7 @@ class SeedDMS_Core_DMS {
/** /**
* Get the logged in user * Get the logged in user
* *
* If user authentication was done externally, this function can * Returns the currently logged in user, as set by setUser()
* be used to tell the dms who is currently logged in.
* *
* @return SeedDMS_Core_User $user * @return SeedDMS_Core_User $user
* *
@ -685,7 +688,7 @@ class SeedDMS_Core_DMS {
if (!$db->createTemporaryTable("ttstatid") || !$db->createTemporaryTable("ttcontentid")) { if (!$db->createTemporaryTable("ttstatid") || !$db->createTemporaryTable("ttcontentid")) {
return false; return false;
} }
$tsnow = mktime(0, 0, 0); /* Start of today */ $tsnow = mktime(0, 0, 0); /* Start of today */
if(is_int($date)) { if(is_int($date)) {
$ts = $tsnow + $date * 86400; $ts = $tsnow + $date * 86400;
@ -1041,7 +1044,7 @@ class SeedDMS_Core_DMS {
$queryStr .= " AND `tblDocumentReviewLog`.`status` = 0 "; $queryStr .= " AND `tblDocumentReviewLog`.`status` = 0 ";
if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; if ($orderby=='e') $queryStr .= "ORDER BY `expires`";
else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`";
else if ($orderby=='s') $queryStr .= "ORDER BY `status`"; else if ($orderby=='s') $queryStr .= "ORDER BY `tblDocumentStatusLog`.`status`";
else $queryStr .= "ORDER BY `name`"; else $queryStr .= "ORDER BY `name`";
$queryStr .= " ".$orderdir; $queryStr .= " ".$orderdir;
} else { } else {
@ -1123,7 +1126,7 @@ class SeedDMS_Core_DMS {
$queryStr .= " AND `tblDocumentApproveLog`.`status` = 0 "; $queryStr .= " AND `tblDocumentApproveLog`.`status` = 0 ";
if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; if ($orderby=='e') $queryStr .= "ORDER BY `expires`";
else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`";
else if ($orderby=='s') $queryStr .= "ORDER BY `status`"; else if ($orderby=='s') $queryStr .= "ORDER BY `tblDocumentStatusLog`.`status`";
else $queryStr .= "ORDER BY `name`"; else $queryStr .= "ORDER BY `name`";
$queryStr .= " ".$orderdir; $queryStr .= " ".$orderdir;
} else { } else {
@ -1197,6 +1200,7 @@ class SeedDMS_Core_DMS {
$queryStr .= "OR `tblWorkflowTransitionGroups`.`groupid` IN (".implode(',', $groups).")"; $queryStr .= "OR `tblWorkflowTransitionGroups`.`groupid` IN (".implode(',', $groups).")";
$queryStr .= ") "; $queryStr .= ") ";
} }
$queryStr .= "AND `tblDocumentStatusLog`.`status` = ".S_IN_WORKFLOW." ";
// echo 'SELECT '.$selectStr." ".$queryStr; // echo 'SELECT '.$selectStr." ".$queryStr;
if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; if ($orderby=='e') $queryStr .= "ORDER BY `expires`";
else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`";
@ -1264,8 +1268,8 @@ class SeedDMS_Core_DMS {
$orderdir = 'DESC'; $orderdir = 'DESC';
else else
$orderdir = 'ASC'; $orderdir = 'ASC';
$queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' ". $queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' ";
"AND `tblDocumentStatusLog`.`status` IN (".S_REJECTED.") "; $queryStr .= "AND `tblDocumentStatusLog`.`status` IN (".S_REJECTED.") ";
//$queryStr .= "ORDER BY `statusDate` DESC"; //$queryStr .= "ORDER BY `statusDate` DESC";
if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; if ($orderby=='e') $queryStr .= "ORDER BY `expires`";
else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`";

View File

@ -58,6 +58,12 @@ define("S_OBSOLETE", -2);
*/ */
define("S_EXPIRED", -3); define("S_EXPIRED", -3);
/*
* Lowest and highest status that may be set
*/
define("S_LOWEST_STATUS", -3);
define("S_HIGHEST_STATUS", 3);
/** /**
* The different states a workflow log can be in. This is used in * The different states a workflow log can be in. This is used in
* all tables tblDocumentXXXLog * all tables tblDocumentXXXLog
@ -2939,7 +2945,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* *
* This method may not be called after a negative approval or review to * This method may not be called after a negative approval or review to
* recalculated the status, because * recalculated the status, because
* it doesn't take a defeating approval or review into account. It will * it doesn't take a defeating approval or review into account. This method
* does not set the status to S_REJECTED! It will
* just check for a pending workflow, approval or review and set the status * just check for a pending workflow, approval or review and set the status
* accordingly, e.g. after the list of reviewers or appovers has been * accordingly, e.g. after the list of reviewers or appovers has been
* modified. If there is not pending workflow, approval or review the * modified. If there is not pending workflow, approval or review the
@ -2966,6 +2973,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
/* $pendingReview will be set when there are still open reviews */ /* $pendingReview will be set when there are still open reviews */
$pendingReview=false; $pendingReview=false;
/* $hasReview will be set if there is at least one positiv review */
$hasReview=false;
unset($this->_reviewStatus); // force to be reloaded from DB unset($this->_reviewStatus); // force to be reloaded from DB
$reviewStatus=$this->getReviewStatus(); $reviewStatus=$this->getReviewStatus();
if (is_array($reviewStatus) && count($reviewStatus)>0) { if (is_array($reviewStatus) && count($reviewStatus)>0) {
@ -2973,12 +2982,16 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if ($r["status"]==0){ if ($r["status"]==0){
$pendingReview=true; $pendingReview=true;
break; break;
} elseif($r["status"]==1){
$hasReview=true;
} }
} }
} }
/* $pendingApproval will be set when there are still open approvals */ /* $pendingApproval will be set when there are still open approvals */
$pendingApproval=false; $pendingApproval=false;
/* $hasApproval will be set if there is at least one positiv review */
$hasApproval=false;
unset($this->_approvalStatus); // force to be reloaded from DB unset($this->_approvalStatus); // force to be reloaded from DB
$approvalStatus=$this->getApprovalStatus(); $approvalStatus=$this->getApprovalStatus();
if (is_array($approvalStatus) && count($approvalStatus)>0) { if (is_array($approvalStatus) && count($approvalStatus)>0) {
@ -2986,6 +2999,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if ($a["status"]==0){ if ($a["status"]==0){
$pendingApproval=true; $pendingApproval=true;
break; break;
} elseif($a["status"]==1){
$hasApproval=true;
} }
} }
} }
@ -3233,7 +3248,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
// If the supplied value lies outside of the accepted range, return an // If the supplied value lies outside of the accepted range, return an
// error. // error.
if ($status < -3 || $status > 3) { if ($status < S_LOWEST_STATUS || $status > S_HIGHEST_STATUS) {
return false; return false;
} }
@ -4524,6 +4539,9 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->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();
@ -4540,14 +4558,14 @@ 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.
* *
* @return object/boolean an object of class SeedDMS_Core_Workflow * @return object/boolean an object of class SeedDMS_Core_Workflow
@ -4601,7 +4619,7 @@ 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` (`document`, `version`, `workflow`, `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 ('".$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().")";
if (!$db->getResult($queryStr)) { if (!$db->getResult($queryStr)) {
$db->rollbackTransaction(); $db->rollbackTransaction();

View File

@ -1051,9 +1051,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
$document = $this->_dms->getDocument($db->getInsertID('tblDocuments')); $document = $this->_dms->getDocument($db->getInsertID('tblDocuments'));
// if ($version_comment!="") $res = $document->addContent($version_comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers, $reqversion, $version_attributes, $workflow);
$res = $document->addContent($version_comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers, $reqversion, $version_attributes, $workflow);
// else $res = $document->addContent($comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers,$reqversion, $version_attributes, $workflow);
if (is_bool($res) && !$res) { if (is_bool($res) && !$res) {
$db->rollbackTransaction(); $db->rollbackTransaction();
@ -1296,9 +1294,9 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
* has no access list the returned array contains the two elements * has no access list the returned array contains the two elements
* 'users' and 'groups' which are than empty. The methode returns false * 'users' and 'groups' which are than empty. The methode returns false
* if the function fails. * if the function fails.
* *
* @param int $mode access mode (defaults to M_ANY) * @param integer $mode access mode (defaults to M_ANY)
* @param int|string $op operation (defaults to O_EQ) * @param integer $op operation (defaults to O_EQ)
* @return bool|SeedDMS_Core_GroupAccess|SeedDMS_Core_UserAccess * @return bool|SeedDMS_Core_GroupAccess|SeedDMS_Core_UserAccess
*/ */
function getAccessList($mode = M_ANY, $op = O_EQ) { /* {{{ */ function getAccessList($mode = M_ANY, $op = O_EQ) { /* {{{ */

View File

@ -232,7 +232,7 @@ class SeedDMS_Core_DatabaseAccess {
$this->_ttapproveid = false; $this->_ttapproveid = false;
$this->_ttstatid = false; $this->_ttstatid = false;
$this->_ttcontentid = false; $this->_ttcontentid = false;
$this->_useviews = false; $this->_useviews = false; // turn off views, because they are much slower then temp. tables
$this->_debug = false; $this->_debug = false;
} /* }}} */ } /* }}} */
@ -401,8 +401,10 @@ class SeedDMS_Core_DatabaseAccess {
} }
$res = $this->_conn->query($queryStr); $res = $this->_conn->query($queryStr);
if ($res === false) { if ($res === false) {
if($this->_debug) if($this->_debug) {
echo "error: ".$queryStr."<br />"; echo "error: ".$queryStr."<br />";
print_r($this->_conn->errorInfo());
}
return false; return false;
} }
$resArr = $res->fetchAll(PDO::FETCH_ASSOC); $resArr = $res->fetchAll(PDO::FETCH_ASSOC);
@ -429,8 +431,10 @@ class SeedDMS_Core_DatabaseAccess {
} }
$res = $this->_conn->exec($queryStr); $res = $this->_conn->exec($queryStr);
if($res === false) { if($res === false) {
if($this->_debug) if($this->_debug) {
echo "error: ".$queryStr."<br />"; echo "error: ".$queryStr."<br />";
print_r($this->_conn->errorInfo());
}
return false; return false;
} else } else
return true; return true;