summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-09-27 18:52:14 +0200
committerGitHub <noreply@github.com>2016-09-27 18:52:14 +0200
commit2f488ce3730d3dc8aa0df7b6e57c46478fcf1288 (patch)
tree53852eafd0cd36d437deced3a01619942d4a23a9 /apps
parent06e969cb74aacc3d6490d3207a625cc712941968 (diff)
parent1bd4eebb267c193beef8d96f5145b61ae0388e12 (diff)
downloadnextcloud-server-2f488ce3730d3dc8aa0df7b6e57c46478fcf1288.tar.gz
nextcloud-server-2f488ce3730d3dc8aa0df7b6e57c46478fcf1288.zip
Merge pull request #1459 from nextcloud/upstream-fix_trashbin_deleteallhooks_solution2
[Upstream] fix trashbin deleteallhooks solution2
Diffstat (limited to 'apps')
-rw-r--r--apps/files_trashbin/lib/Trashbin.php47
1 files changed, 45 insertions, 2 deletions
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php
index db6eb29228b..bf2fa57453f 100644
--- a/apps/files_trashbin/lib/Trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php
@@ -470,9 +470,36 @@ class Trashbin {
public static function deleteAll() {
$user = User::getUser();
$view = new View('/' . $user);
+ $fileInfos = $view->getDirectoryContent('files_trashbin/files');
+
+ // Array to store the relative path in (after the file is deleted, the view won't be able to relativise the path anymore)
+ $filePaths = array();
+ foreach($fileInfos as $fileInfo){
+ $filePaths[] = $view->getRelativePath($fileInfo->getPath());
+ }
+ unset($fileInfos); // save memory
+
+ // Bulk PreDelete-Hook
+ \OC_Hook::emit('\OCP\Trashbin', 'preDeleteAll', array('paths' => $filePaths));
+
+ // Single-File Hooks
+ foreach($filePaths as $path){
+ self::emitTrashbinPreDelete($path);
+ }
+
+ // actual file deletion
$view->deleteAll('files_trashbin');
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?');
$query->execute(array($user));
+
+ // Bulk PostDelete-Hook
+ \OC_Hook::emit('\OCP\Trashbin', 'deleteAll', array('paths' => $filePaths));
+
+ // Single-File Hooks
+ foreach($filePaths as $path){
+ self::emitTrashbinPostDelete($path);
+ }
+
$view->mkdir('files_trashbin');
$view->mkdir('files_trashbin/files');
@@ -480,6 +507,22 @@ class Trashbin {
}
/**
+ * wrapper function to emit the 'preDelete' hook of \OCP\Trashbin before a file is deleted
+ * @param string $path
+ */
+ protected static function emitTrashbinPreDelete($path){
+ \OC_Hook::emit('\OCP\Trashbin', 'preDelete', array('path' => $path));
+ }
+
+ /**
+ * wrapper function to emit the 'delete' hook of \OCP\Trashbin after a file has been deleted
+ * @param string $path
+ */
+ protected static function emitTrashbinPostDelete($path){
+ \OC_Hook::emit('\OCP\Trashbin', 'delete', array('path' => $path));
+ }
+
+ /**
* delete file from trash bin permanently
*
* @param string $filename path to the file
@@ -507,9 +550,9 @@ class Trashbin {
} else {
$size += $view->filesize('/files_trashbin/files/' . $file);
}
- \OC_Hook::emit('\OCP\Trashbin', 'preDelete', array('path' => '/files_trashbin/files/' . $file));
+ self::emitTrashbinPreDelete('/files_trashbin/files/' . $file);
$view->unlink('/files_trashbin/files/' . $file);
- \OC_Hook::emit('\OCP\Trashbin', 'delete', array('path' => '/files_trashbin/files/' . $file));
+ self::emitTrashbinPostDelete('/files_trashbin/files/' . $file);
return $size;
}