Merge branch 'seeddms-4.3.13' into develop

This commit is contained in:
Uwe Steinmann 2014-11-27 13:52:38 +01:00
commit 631066b697
5 changed files with 109 additions and 7 deletions

View File

@ -1,5 +1,5 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Changes in version 4.3.12 Changes in version 4.3.13
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
- more error fixes when searching for attributes - more error fixes when searching for attributes
- fix saving multi value attributes without a maximum number of values - fix saving multi value attributes without a maximum number of values
@ -9,6 +9,11 @@
when moving into a different folder (Bug #186) when moving into a different folder (Bug #186)
- Download of documents whose content is gone will not be possible anymore - Download of documents whose content is gone will not be possible anymore
(Bug #185) (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 Changes in version 4.3.12

View File

@ -1471,7 +1471,7 @@ class SeedDMS_Core_DMS {
} /* }}} */ } /* }}} */
function getDocumentCategories() { /* {{{ */ function getDocumentCategories() { /* {{{ */
$queryStr = "SELECT * FROM tblCategory"; $queryStr = "SELECT * FROM tblCategory order by name";
$resArr = $this->db->getResultArray($queryStr); $resArr = $this->db->getResultArray($queryStr);
if (is_bool($resArr) && !$resArr) if (is_bool($resArr) && !$resArr)

View File

@ -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 object $user user who shall be the owner of this content
* @param string $tmpFile file containing the actuall content * @param string $tmpFile file containing the actuall content
* @param string $orgFileName original file name * @param string $orgFileName original file name
* @param string $fileType
* @param string $mimeType MimeType of the content * @param string $mimeType MimeType of the content
* @param array $reviewers list of reviewers * @param array $reviewers list of reviewers
* @param array $approvers list of approvers * @param array $approvers list of approvers
* @param integer $version version number of content or 0 if next higher version shall be used. * @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 * @param array $attributes list of version attributes. The element key
* must be the id of the attribute definition. * must be the id of the attribute definition.
* @param object $workflow
* @return bool/array false in case of an error or a result set * @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) { /* {{{ */ 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; 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 * Return all content elements of a document
* *

View File

@ -12,7 +12,7 @@
<email>uwe@steinmann.cx</email> <email>uwe@steinmann.cx</email>
<active>yes</active> <active>yes</active>
</lead> </lead>
<date>2014-11-21</date> <date>2014-11-27</date>
<time>11:56:35</time> <time>11:56:35</time>
<version> <version>
<release>4.3.13</release> <release>4.3.13</release>
@ -26,6 +26,8 @@
<notes> <notes>
- fix searching for attributes - fix searching for attributes
- add some more documentation - 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.
</notes> </notes>
<contents> <contents>
<dir baseinstalldir="SeedDMS" name="/"> <dir baseinstalldir="SeedDMS" name="/">

View File

@ -542,11 +542,23 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$lc = $document->getLatestContent(); $lc = $document->getLatestContent();
if($lc->getChecksum() == SeedDMS_Core_File::checksum($tmpFile)) { if($lc->getChecksum() == SeedDMS_Core_File::checksum($tmpFile)) {
$lc->setDate(); $lc->setDate();
} elseif(!$document->addContent('', $this->user, $tmpFile, $name, $fileType, $mimetype, array(), array(), 0)) { } 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); unlink($tmpFile);
return "409 Conflict"; return "409 Conflict";
} }
} }
}
}
} else { } else {
if ($folder->getAccessMode($this->user) < M_READWRITE) { if ($folder->getAccessMode($this->user) < M_READWRITE) {
@ -1003,7 +1015,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
return false; return false;
} }
if($obj->isLocked()) { if($obj->isLocked() && $this->user->getLogin() != $obj->getLockingUser()->getLogin()) {
$lockuser = $obj->getLockingUser(); $lockuser = $obj->getLockingUser();
if($this->logger) if($this->logger)
$this->logger->log('checkLock: object is locked by '.$lockuser->getLogin(), PEAR_LOG_INFO); $this->logger->log('checkLock: object is locked by '.$lockuser->getLogin(), PEAR_LOG_INFO);