public function filedepot::deleteFile in filedepot 6
Same name and namespace in other branches
- 7 filedepot.class.php \filedepot::deleteFile()
1 call to filedepot::deleteFile()
File
- ./
filedepot.class.php, line 675 - filedepot.class.php Main class for the Filedepot module
Class
- filedepot
- @file filedepot.class.php Main class for the Filedepot module
Code
public function deleteFile($fid) {
global $user;
// Additional testing for the nexcloud instance because this method is also called from filedepot_uninstall()
if (function_exists('filedepot_nexcloud')) {
$nexcloud = filedepot_nexcloud();
}
else {
module_load_include('php', 'filedepot', 'nexcloud.class');
$nexcloud = new filedepotTagCloud();
}
if ($user->uid > 0 and db_result(db_query("SELECT fid FROM {filedepot_files} WHERE fid=%d", $fid)) == $fid) {
// Check if user is the owner or has category admin rights
$query = db_query("SELECT cid,cckfid,title,version,submitter,size FROM {filedepot_files} WHERE fid=%d", $fid);
list($cid, $cckfid, $title, $version, $submitter, $fsize) = array_values(db_fetch_array($query));
if ($submitter == $user->uid or $this
->checkPermission($cid, 'admin')) {
// Need to check there are no other repository entries in this category for the same filename
$fname = db_result(db_query("SELECT fname FROM {filedepot_fileversions} WHERE fid=%d AND version=%d", $fid, $version));
if (db_result(db_query("SELECT COUNT(fid) from {filedepot_files} WHERE cid=%d AND fname='%s'", $cid, $fname)) == 1) {
$ret = @unlink($this->root_storage_path . "{$cid}/{$fname}");
if (!$ret) {
watchdog('filedepot', 'Attempted to unlink file but failed - path: @path', array(
'@path' => "{$this->root_storage_path}{$cid}/{$fname}",
));
}
else {
watchdog('filedepot', 'Successfully deleted file: @file', array(
'@file' => "{$this->root_storage_path}{$cid}/{$fname}",
));
}
}
elseif (db_result(db_query("SELECT fid from {filedepot_files} WHERE cid=%d AND fname='%s'", $cid, $fname)) > 1) {
watchdog('filedepot', 'Delete physical file skipped - more then 1 record in folder @folder for file: @file', array(
'@folder' => $cid,
'@file' => $fname,
));
}
else {
watchdog('filedepot', 'Delete file failed - no matching record, cid: @cid, file: @file', array(
'@cid' => $cid,
'@file' => $fname,
));
}
$nexcloud
->clear_tags($fid);
// Clear all tags and update metrics for this item
db_query("DELETE FROM {filedepot_fileversions} WHERE fid=%d", $fid);
db_query("DELETE FROM {filedepot_files} WHERE fid=%d", $fid);
db_query("DELETE FROM {filedepot_notifications} WHERE fid=%d", $fid);
// Remove the CCK records for this attachment (file)
$this
->deleteNodeCCKField($cid, $cckfid);
return TRUE;
}
else {
watchdog('filedepot', 'Unable to delete file. User: @user, file: @fid and Folder: @folder', array(
'@user' => $user->uid,
'@fid' => $fid,
'@folder' => $cid,
));
$GLOBALS['alertMsg'] = 'No permission to remove selected file(s)';
return FALSE;
}
}
else {
return FALSE;
}
}