diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-07-15 18:11:54 +0300 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-07-31 20:37:59 +0300 |
commit | 7b723813cef60e744ab14ab418c82e5ec67a9f2e (patch) | |
tree | eda4a044c9defc883c35d98e1ba5a9e261a3ecdf /lib/private | |
parent | ab1a20522b1b2730398869a764f672175a1abcb8 (diff) |
Multiple fixesenh/noid/share-attributes
- 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')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 14 | ||||
-rw-r--r-- | lib/private/legacy/OC_Files.php | 30 |
2 files changed, 20 insertions, 24 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 627284da4e8..70f9b8665f9 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -1566,14 +1566,15 @@ class DefaultShareProvider implements IShareProvider { /** * Load from database format (JSON string) to IAttributes * - * @param IShare $share - * @param string|null $data - * @return IShare modified share + * @return IShare the modified share */ - private function updateShareAttributes(IShare $share, ?string $data) { + private function updateShareAttributes(IShare $share, ?string $data): IShare { if ($data !== null && $data !== '') { $attributes = new ShareAttributes(); $compressedAttributes = \json_decode($data, true); + if ($compressedAttributes === false || $compressedAttributes === null) { + return $share; + } foreach ($compressedAttributes as $compressedAttribute) { $attributes->setAttribute( $compressedAttribute[0], @@ -1589,11 +1590,8 @@ class DefaultShareProvider implements IShareProvider { /** * Format IAttributes to database format (JSON string) - * - * @param IAttributes|null $attributes - * @return string|null */ - private function formatShareAttributes($attributes) { + private function formatShareAttributes(?IAttributes $attributes): ?string { if ($attributes === null || empty($attributes->toArray())) { return null; } 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'; } |