From 0eb9da705d91dc2d0fe90fa5ec72b3464a41c853 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 24 Nov 2014 19:51:43 +0100 Subject: [PATCH 1/8] getDocumentCategories() returns categories sorted by name (Bug #181) --- SeedDMS_Core/Core/inc.ClassDMS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 77f2700fd..27b80a1a3 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -1446,7 +1446,7 @@ class SeedDMS_Core_DMS { } /* }}} */ function getDocumentCategories() { /* {{{ */ - $queryStr = "SELECT * FROM tblCategory"; + $queryStr = "SELECT * FROM tblCategory order by name"; $resArr = $this->db->getResultArray($queryStr); if (is_bool($resArr) && !$resArr) From 97d3a8bce309e1ddb4bd6fdb32abca3faab67868 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 24 Nov 2014 19:52:16 +0100 Subject: [PATCH 2/8] add note about changes to SeedDMS_Core_DMS::getDocumentCategories() --- SeedDMS_Core/package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index 4a98fb3b2..cecdaf691 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -26,6 +26,7 @@ - fix searching for attributes - add some more documentation +- SeedDMS_Core_DMS::getDocumentCategories() returns categories sorted by name (Bug #181) From 715410e437a953b0140cc28dd95e14e9454efd37 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 26 Nov 2014 07:49:19 +0100 Subject: [PATCH 3/8] allow users to access a document which has been locked by herself --- webdav/webdav.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webdav/webdav.php b/webdav/webdav.php index 3c3b8162e..dd0094c51 100644 --- a/webdav/webdav.php +++ b/webdav/webdav.php @@ -1003,7 +1003,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server return false; } - if($obj->isLocked()) { + if($obj->isLocked() && $this->user->getLogin() != $obj->getLockingUser()->getLogin()) { $lockuser = $obj->getLockingUser(); if($this->logger) $this->logger->log('checkLock: object is locked by '.$lockuser->getLogin(), PEAR_LOG_INFO); From 0aa07a2fe69716f49345c7654586c7610ab504e5 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 27 Nov 2014 09:13:02 +0100 Subject: [PATCH 4/8] add note about fixed locking in webdav --- CHANGELOG | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b7e6f850c..47b083682 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ -------------------------------------------------------------------------------- - Changes in version 4.3.12 + Changes in version 4.3.13 -------------------------------------------------------------------------------- - more error fixes when searching for attributes - fix saving multi value attributes without a maximum number of values @@ -9,6 +9,8 @@ when moving into a different folder (Bug #186) - Download of documents whose content is gone will not be possible anymore (Bug #185) +- allow user to access a locked document via webdav if he/she is the owner + of that document -------------------------------------------------------------------------------- Changes in version 4.3.12 From d6565041cd355e84a4ee7cfd78a1e2d0e3251882 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 27 Nov 2014 13:40:58 +0100 Subject: [PATCH 5/8] add new methode replaceContent() instead of adding a new version, this function replaces the content file of a version --- SeedDMS_Core/Core/inc.ClassDocument.php | 83 +++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index 509d362ea..ccd75b64f 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -1097,12 +1097,14 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * @param object $user user who shall be the owner of this content * @param string $tmpFile file containing the actuall content * @param string $orgFileName original file name + * @param string $fileType * @param string $mimeType MimeType of the content * @param array $reviewers list of reviewers * @param array $approvers list of approvers * @param integer $version version number of content or 0 if next higher version shall be used. * @param array $attributes list of version attributes. The element key * must be the id of the attribute definition. + * @param object $workflow * @return bool/array false in case of an error or a result set */ function addContent($comment, $user, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers=array(), $approvers=array(), $version=0, $attributes=array(), $workflow=null) { /* {{{ */ @@ -1247,6 +1249,87 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return $docResultSet; } /* }}} */ + /** + * Replace a version of a document + * + * Each document may have any number of content elements attached to it. + * This function replaces the file content of a given version. + * Using this function is highly discourage, because it undermines the + * idea of keeping all versions of a document as originally saved. + * Content will only be replaced if the mimetype, filetype, user and + * original filename are identical to the version being updated. + * + * This function was introduced for the webdav server because any saving + * of a document created a new version. + * + * @param object $user user who shall be the owner of this content + * @param string $tmpFile file containing the actuall content + * @param string $orgFileName original file name + * @param string $fileType + * @param string $mimeType MimeType of the content + * @param integer $version version number of content or 0 if next higher version shall be used. + * @return bool/array false in case of an error or a result set + */ + function replaceContent($version, $user, $tmpFile, $orgFileName, $fileType, $mimeType) { /* {{{ */ + $db = $this->_dms->getDB(); + + // the doc path is id/version.filetype + $dir = $this->getDir(); + + $date = time(); + + /* If $version < 1 than replace the content of the latest version. + */ + if ((int) $version<1) { + $queryStr = "SELECT MAX(version) as m from tblDocumentContent where document = ".$this->_id; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && !$res) + return false; + + $version = $resArr[0]['m']; + } + + $content = $this->getContentByVersion($version); + if(!$content) + return false; + + /* Check if $user, $orgFileName, $fileType and $mimetype are the same */ + if($user->getID() != $content->getUser()->getID()) { + return false; + } + if($orgFileName != $content->getOriginalFileName()) { + return false; + } + if($fileType != $content->getFileType()) { + return false; + } + if($mimeType != $content->getMimeType()) { + return false; + } + + $filesize = SeedDMS_Core_File::fileSize($tmpFile); + $checksum = SeedDMS_Core_File::checksum($tmpFile); + + $db->startTransaction(); + $queryStr = "UPDATE tblDocumentContent set date=".$date.", fileSize=".$filesize.", checksum=".$db->qstr($checksum)." WHERE id=".$content->getID(); + if (!$db->getResult($queryStr)) { + $db->rollbackTransaction(); + return false; + } + + // copy file + if (!SeedDMS_Core_File::copyFile($tmpFile, $this->_dms->contentDir . $dir . $version . $fileType)) { + $db->rollbackTransaction(); + return false; + } + + unset($this->_content); + unset($this->_latestContent); + $db->commitTransaction(); + + return true; + } /* }}} */ + /** * Return all content elements of a document * From 671fbd1f33ee9226e1474b756d3d7bd117352ef1 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 27 Nov 2014 13:42:00 +0100 Subject: [PATCH 6/8] do not create new version anymore, unless the user, mimetype has changed --- webdav/webdav.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/webdav/webdav.php b/webdav/webdav.php index dd0094c51..7d2439b1e 100644 --- a/webdav/webdav.php +++ b/webdav/webdav.php @@ -542,9 +542,21 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server $lc = $document->getLatestContent(); if($lc->getChecksum() == SeedDMS_Core_File::checksum($tmpFile)) { $lc->setDate(); - } elseif(!$document->addContent('', $this->user, $tmpFile, $name, $fileType, $mimetype, array(), array(), 0)) { - unlink($tmpFile); - return "409 Conflict"; + } else { + if($this->user->getID() == $lc->getUser()->getID() && + $name == $lc->getOriginalFileName() && + $fileType == $lc->getFileType() && + $mimetype == $lc->getMimeType()) { + if(!$document->replaceContent($lc->getVersion(), $this->user, $tmpFile, $name, $fileType, $mimetype)) { + unlink($tmpFile); + return "403 Forbidden"; + } + } else { + if(!$document->addContent('', $this->user, $tmpFile, $name, $fileType, $mimetype, array(), array(), 0)) { + unlink($tmpFile); + return "409 Conflict"; + } + } } } From fcfb965a29473cb4693974e69c9e659156abd2bf Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 27 Nov 2014 13:42:44 +0100 Subject: [PATCH 7/8] add note about new method SeedDMS_Core_Document::replaceContent() --- SeedDMS_Core/package.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index cecdaf691..4f1433d5c 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -12,7 +12,7 @@ uwe@steinmann.cx yes - 2014-11-21 + 2014-11-27 4.3.13 @@ -27,6 +27,7 @@ - fix searching for attributes - add some more documentation - SeedDMS_Core_DMS::getDocumentCategories() returns categories sorted by name (Bug #181) +- new methode SeedDMS_Core_Document::replaceContent() which replaces the content of a version. From 284327ce33ae99ddfd239686432326cf2cd910b6 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 27 Nov 2014 13:44:22 +0100 Subject: [PATCH 8/8] add note about new save behaviour in webdav server --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 47b083682..c9730861c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,9 @@ (Bug #185) - allow user to access a locked document via webdav if he/she is the owner of that document +- saving a document via webdav will not in any case create a new version + anymore. If the user and mimetype hasn't changed the content is just + replaced. -------------------------------------------------------------------------------- Changes in version 4.3.12