diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index e932e0ada..492061637 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -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."
"; + $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; + } /* }}} */ + } /* }}} */