diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-07-15 17:11:54 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-07-31 19:37:59 +0200 |
commit | 7b723813cef60e744ab14ab418c82e5ec67a9f2e (patch) | |
tree | eda4a044c9defc883c35d98e1ba5a9e261a3ecdf /lib/private/legacy/OC_Files.php | |
parent | ab1a20522b1b2730398869a764f672175a1abcb8 (diff) | |
download | nextcloud-server-7b723813cef60e744ab14ab418c82e5ec67a9f2e.tar.gz nextcloud-server-7b723813cef60e744ab14ab418c82e5ec67a9f2e.zip |
Multiple fixes
- Fix tests
- Use non deprecated event stuff
- Add a bit of type hinting to the new stuff
- More safe handling of instanceOfStorage (share might not be the first
wrapper)
- Fix resharing
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/private/legacy/OC_Files.php')
-rw-r--r-- | lib/private/legacy/OC_Files.php | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index 220fa0e3429..6a3a44d6cc0 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -44,12 +44,12 @@ use bantu\IniGetWrapper\IniGetWrapper; use OC\Files\View; use OC\Streamer; use OCP\Lock\ILockingProvider; -use OCP\EventDispatcher\GenericEvent; +use OCP\Files\Events\BeforeZipCreatedEvent; +use OCP\Files\Events\BeforeDirectFileDownloadEvent; use OCP\EventDispatcher\IEventDispatcher; /** * Class for file server access - * */ class OC_Files { public const FILE = 1; @@ -170,11 +170,11 @@ class OC_Files { } //Dispatch an event to see if any apps have problem with download - $event = new GenericEvent(null, ['dir' => $dir, 'files' => $files, 'run' => true]); - $dispatcher = \OC::$server->query(IEventDispatcher::class); - $dispatcher->dispatch('file.beforeCreateZip', $event); - if (($event->getArgument('run') === false) or ($event->hasArgument('errorMessage'))) { - throw new \OC\ForbiddenException($event->getArgument('errorMessage')); + $event = new BeforeZipCreatedEvent($dir, is_array($files) ? $files : [$files]); + $dispatcher = \OCP\Server::get(IEventDispatcher::class); + $dispatcher->dispatchTyped($event); + if ((!$event->isSuccessful()) || $event->getErrorMessage() !== null) { + throw new \OC\ForbiddenException($event->getErrorMessage()); } $streamer = new Streamer(\OC::$server->getRequest(), $fileSize, $numberOfFiles); @@ -222,8 +222,6 @@ class OC_Files { $streamer->finalize(); set_time_limit($executionTime); self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); - $event = new GenericEvent(null, ['result' => 'success', 'dir' => $dir, 'files' => $files]); - $dispatcher->dispatch('file.afterCreateZip', $event); } catch (\OCP\Lock\LockedException $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); OC::$server->getLogger()->logException($ex); @@ -240,8 +238,8 @@ class OC_Files { OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('lib'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; - if ($event && $event->hasArgument('message')) { - $hint .= ' ' . $event->getArgument('message'); + if ($event && $event->getErrorMessage() !== null) { + $hint .= ' ' . $event->getErrorMessage(); } \OC_Template::printErrorPage($l->t('Cannot download file'), $hint, 200); } @@ -339,12 +337,12 @@ class OC_Files { } $dispatcher = \OC::$server->query(IEventDispatcher::class); - $event = new GenericEvent(null, ['path' => $filename]); - $dispatcher->dispatch('file.beforeGetDirect', $event); + $event = new BeforeDirectFileDownloadEvent($filename); + $dispatcher->dispatchTyped($event); - if (!\OC\Files\Filesystem::isReadable($filename) || $event->hasArgument('errorMessage')) { - if (!$event->hasArgument('errorMessage')) { - $msg = $event->getArgument('errorMessage'); + if (!\OC\Files\Filesystem::isReadable($filename) || $event->getErrorMessage()) { + if ($event->getErrorMessage()) { + $msg = $event->getErrorMessage(); } else { $msg = 'Access denied'; } |