new method SeedDMS_Document_Content::repair, restore old getPath() behaviour

getPath() didn't return a single '.' in the fileType
This commit is contained in:
Uwe Steinmann 2020-02-11 07:45:30 +01:00
parent d92c3afd56
commit 30ca5c71cd

View File

@ -1667,7 +1667,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
if($fileType == '.')
$fileType = '';
/* Check if $user, $orgFileName, $fileType and $mimetype are the same */
/* Check if $user, $orgFileName, $fileType and $mimeType are the same */
if($user->getID() != $content->getUser()->getID()) {
return false;
}
@ -2909,7 +2909,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
*
* @return string path of file on disc
*/
function getPath() { return $this->_document->getDir() . $this->_version . ($this->_fileType != '.' ? $this->_fileType : ''); }
function getPath() { return $this->_document->getDir() . $this->_version . $this->_fileType; }
function setDate($date = false) { /* {{{ */
$db = $this->_document->getDMS()->getDB();
@ -4824,6 +4824,50 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return $needwkflaction;
} /* }}} */
/**
* Checks the internal data of the document version and repairs it.
* Currently, this function only repairs a missing filetype
*
* @return boolean true on success, otherwise false
*/
function repair() { /* {{{ */
$dms = $this->_document->getDMS();
$db = $this->_dms->getDB();
if(file_exists($this->_dms->contentDir.$this->_document->getDir() . $this->_version . $this->_fileType)) {
if(strlen($this->_fileType) < 2) {
switch($this->_mimeType) {
case "application/pdf":
case "image/png":
case "image/gif":
case "image/jpg":
$expect = substr($this->_mimeType, -3, 3);
if($this->_fileType != '.'.$expect) {
$db->startTransaction();
$queryStr = "UPDATE `tblDocumentContent` SET `fileType`='.".$expect."' WHERE `id` = ". $this->_id;
echo $queryStr."<br />";
$res = $db->getResult($queryStr);
if ($res) {
if(!SeedDMS_Core_File::renameFile($this->_dms->contentDir.$this->_document->getDir() . $this->_version . $this->_fileType, $this->_dms->contentDir.$this->_document->getDir() . $this->_version . '.' . $expect)) {
$db->rollbackTransaction();
} else {
$db->commitTransaction();
}
} else {
$db->rollbackTransaction();
}
}
break;
}
}
} elseif(file_exists($this->_document->getDir() . $this->_version . '.')) {
echo "no file";
} else {
echo $this->_dms->contentDir.$this->_document->getDir() . $this->_version . $this->_fileType;
}
return true;
} /* }}} */
} /* }}} */