add new method setFileType()

This commit is contained in:
Uwe Steinmann 2020-02-13 12:19:43 +01:00
parent efec0c36bf
commit 9b24827598

View File

@ -3491,6 +3491,40 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return true;
} /* }}} */
/**
* Set file type by evaluating the mime type
*/
function setFileType() { /* {{{ */
$mimetype = $this->getMimeType();
switch($this->_mimeType) {
case "application/pdf":
case "image/png":
case "image/gif":
case "image/jpg":
$expect = substr($this->_mimeType, -3, 3);
break;
}
if($expect && '.'.$expect != $this->_fileType) {
$db = $this->_document->getDMS()->getDB();
$db->startTransaction();
$queryStr = "UPDATE `tblDocumentContent` SET `fileType`='.".$expect."' WHERE `id` = ". $this->_id;
$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();
return true;
}
} else {
$db->rollbackTransaction();
}
}
return false;
} /* }}} */
function setComment($newComment) { /* {{{ */
$db = $this->_document->getDMS()->getDB();