bulk_delete.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. $file_guids = get_input("file_guids");
  3. $folder_guids = get_input("folder_guids");
  4. if (!empty($file_guids) || !empty($folder_guids)) {
  5. // remove all files
  6. if (!empty($file_guids)) {
  7. $file_count = 0;
  8. foreach ($file_guids as $guid) {
  9. if (($file = get_entity($guid)) && elgg_instanceof($file, "object", "file")) {
  10. if ($file->canEdit()) {
  11. if ($file->delete()) {
  12. $file_count++;
  13. }
  14. }
  15. }
  16. }
  17. if (!empty($file_count)) {
  18. system_message(elgg_echo("file_tools:action:bulk_delete:success:files", array($file_count)));
  19. } else {
  20. register_error(elgg_echo("file_tools:action:bulk_delete:error:files"));
  21. }
  22. }
  23. // remove folders
  24. if (!empty($folder_guids)) {
  25. $folder_count = 0;
  26. foreach ($folder_guids as $guid) {
  27. if (($folder = get_entity($guid)) && elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE)) {
  28. if ($folder->canEdit()) {
  29. if ($folder->delete()) {
  30. $folder_count++;
  31. }
  32. }
  33. }
  34. }
  35. if (!empty($folder_count)) {
  36. system_message(elgg_echo("file_tools:action:bulk_delete:success:folders", array($folder_count)));
  37. } else {
  38. register_error(elgg_echo("file_tools:action:bulk_delete:error:folders"));
  39. }
  40. }
  41. } else {
  42. register_error(elgg_echo("InvalidParameterException:MissingParameter"));
  43. }
  44. forward(REFERER);