public function filedepot::deleteFolder in filedepot 7
Same name and namespace in other branches
- 6 filedepot.class.php \filedepot::deleteFolder()
File
- ./
filedepot.class.php, line 1057 - filedepot.class.php Main class for the Filedepot module
Class
- filedepot
- @file filedepot.class.php Main class for the Filedepot module
Code
public function deleteFolder($filedepot_folder_id) {
/* Test for valid folder and admin permission one more time
* We are going to override the permission test in the function filedepot_getRecursiveCatIDs()
* and return all subfolders in case hidden folders exist for this user.
* If this user has admin permission for parent -- then they should be able to delete it
* and any subfolders.
*/
if ($filedepot_folder_id > 0 and $this
->checkPermission($filedepot_folder_id, 'admin')) {
// Need to delete all files in the folder
/* Build an array of all linked categories under this category the user has admin access to */
$list = array();
array_push($list, $filedepot_folder_id);
// Passing in permission check over-ride as noted above to filedepot_getRecursiveCatIDs()
$list = $this
->getRecursiveCatIDs($list, $filedepot_folder_id, 'admin', TRUE);
foreach ($list as $cid) {
// Drupal will remove the file attachments automatically when folder node is deleted even if file usage is > 1
$query = db_query("SELECT drupal_fid FROM {filedepot_files} WHERE cid=:cid", array(
':cid' => $cid,
));
while ($A = $query
->fetchAssoc()) {
$file = file_load($A['drupal_fid']);
file_usage_delete($file, 'filedepot');
if (file_exists($file->uri)) {
file_delete($file);
}
}
$subfolder_nid = db_query("SELECT nid FROM {filedepot_categories} WHERE cid=:cid", array(
':cid' => $cid,
))
->fetchField();
db_delete('filedepot_categories')
->condition('cid', $cid)
->execute();
db_delete('filedepot_categories')
->condition('cid', $cid)
->execute();
db_delete('filedepot_access')
->condition('catid', $cid)
->execute();
db_delete('filedepot_recentfolders')
->condition('cid', $cid)
->execute();
db_delete('filedepot_notifications')
->condition('cid', $cid)
->execute();
db_delete('filedepot_filesubmissions')
->condition('cid', $cid)
->execute();
// Call the drupal node delete now for the subfolder node
//watchdog('filedepot',"Calling node_delete for node id: {$subfolder_nid}");
node_delete($subfolder_nid);
// Remove the physical directory
$uri = $this->root_storage_path . $cid;
if (file_exists($uri)) {
$ret = @unlink("{$uri}/.htaccess");
$ret = @unlink("{$uri}/submissions/.htaccess");
$ret = @drupal_rmdir("{$uri}/submissions");
$ret = @drupal_rmdir($uri);
}
}
return TRUE;
}
else {
return FALSE;
}
}