mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-08 20:46:05 +00:00
addDocumentFiles() clears internal list, make removeDocumentFile() more robust
This commit is contained in:
parent
08887fcbd9
commit
233e464692
|
@ -2358,29 +2358,37 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
|
|||
}
|
||||
|
||||
$db->commitTransaction();
|
||||
unset ($this->_documentFiles);
|
||||
return $file;
|
||||
} /* }}} */
|
||||
|
||||
function removeDocumentFile($ID) { /* {{{ */
|
||||
$db = $this->_dms->getDB();
|
||||
|
||||
if (!is_numeric($ID)) return false;
|
||||
if (!is_numeric($ID) || $ID < 1)
|
||||
return false;
|
||||
|
||||
$file = $this->getDocumentFile($ID);
|
||||
if (is_bool($file) && !$file) return false;
|
||||
|
||||
if (file_exists( $this->_dms->contentDir . $file->getPath() )){
|
||||
if (!SeedDMS_Core_File::removeFile( $this->_dms->contentDir . $file->getPath() ))
|
||||
return false;
|
||||
$db->startTransaction();
|
||||
/* First delete the database record, because that can be undone
|
||||
* if deletion of the file fails.
|
||||
*/
|
||||
$queryStr = "DELETE FROM `tblDocumentFiles` WHERE `document` = " . $this->getID() . " AND `id` = " . (int) $ID;
|
||||
if (!$db->getResult($queryStr)) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
|
||||
$name=$file->getName();
|
||||
$comment=$file->getcomment();
|
||||
|
||||
$queryStr = "DELETE FROM `tblDocumentFiles` WHERE `document` = " . $this->getID() . " AND `id` = " . (int) $ID;
|
||||
if (!$db->getResult($queryStr))
|
||||
return false;
|
||||
if (file_exists( $this->_dms->contentDir . $file->getPath() )){
|
||||
if (!SeedDMS_Core_File::removeFile( $this->_dms->contentDir . $file->getPath() )) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$db->commitTransaction();
|
||||
unset ($this->_documentFiles);
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user