diff options
author | Steven Bühner <buehner@me.com> | 2016-08-25 13:47:51 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-09-20 12:06:43 +0200 |
commit | 0408d9a2e4dfa4d640b1a862dfcb230dce8f73d3 (patch) | |
tree | 7bd68c1b48c8ce5f7dbec9408a81312bb1d2fb0b /apps/files_trashbin/lib | |
parent | 09e1218df939ffb28160d054bed28af8fc29113e (diff) | |
download | nextcloud-server-0408d9a2e4dfa4d640b1a862dfcb230dce8f73d3.tar.gz nextcloud-server-0408d9a2e4dfa4d640b1a862dfcb230dce8f73d3.zip |
Emit Hooks for each file bevore and after all files in trashbin have been deleted.
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r-- | apps/files_trashbin/lib/Trashbin.php | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index db6eb29228b..f88aec45e22 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -58,7 +58,7 @@ class Trashbin { private static $scannedVersions = false; /** - * Ensure we don't need to scan the file during the move to trash + * Ensure we dont need to scan the file during the move to trash * by triggering the scan in the pre-hook * * @param array $params @@ -470,15 +470,44 @@ class Trashbin { public static function deleteAll() { $user = User::getUser(); $view = new View('/' . $user); + $fileInfos = $view->getDirectoryContent('files_trashbin/files'); + + foreach($fileInfos as $fileInfo){ + $path = $view->getRelativePath($fileInfo->getPath()); + self::emitTrashbinPreDelete($path); + } + $view->deleteAll('files_trashbin'); $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?'); $query->execute(array($user)); + + foreach($fileInfos as $fileInfo){ + $path = $fileInfo->getPath(); + self::emitTrashbinPostDelete($path); + } + $view->mkdir('files_trashbin'); $view->mkdir('files_trashbin/files'); return true; } + /** + * 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 * @@ -507,9 +536,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; } |