diff --git a/CHANGELOG b/CHANGELOG index b7e6f850c..c9730861c 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,11 @@ 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 +- 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 diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 3ce942b62..1398d3f53 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -1471,7 +1471,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) diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index 6e1dbf7cc..3134c1589 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) { /* {{{ */ @@ -1251,6 +1253,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 * diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index 4a98fb3b2..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 @@ -26,6 +26,8 @@ - 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. diff --git a/webdav/webdav.php b/webdav/webdav.php index 3c3b8162e..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"; + } + } } } @@ -1003,7 +1015,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);