From 79788c98b96cb4d4914e67fd330f3aebc3da9e94 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sat, 17 Jun 2023 00:52:17 +0200 Subject: [PATCH] Fix user in hook --- lib/Hooks.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Hooks.php b/lib/Hooks.php index 71d6f64..3864fb3 100644 --- a/lib/Hooks.php +++ b/lib/Hooks.php @@ -13,7 +13,7 @@ namespace OCA\Epubreader; use OCA\Epubreader\AppInfo\Application; use OCP\IConfig; use OCP\IDBConnection; -use OCP\IUser; +use OCP\IUserSession; use OCP\Server; class Hooks { @@ -21,7 +21,9 @@ class Hooks { public static function announce_settings(array $settings): void { // Nextcloud encodes this as JSON, Owncloud does not (yet) (#75) // TODO: remove this when Owncloud starts encoding oc_appconfig as JSON just like it already encodes most other properties - if (array_key_exists('array', $settings) && + $user = Server::get(IUserSession::class)->getUser(); + if ($user && + array_key_exists('array', $settings) && is_array($settings['array']) && array_key_exists('oc_appconfig', $settings['array']) ) { @@ -29,9 +31,9 @@ class Hooks { /** @var array $array */ $array = ($isJson) ? json_decode((string) $settings['array']['oc_appconfig'], true) : $settings['array']['oc_appconfig']; $array['filesReader'] = [ - 'enableEpub' => Server::get(IConfig::class)->getUserValue(Server::get(IUser::class)->getUID(), Application::APP_ID, 'epub_enable', 'true'), - 'enablePdf' => Server::get(IConfig::class)->getUserValue(Server::get(IUser::class)->getUID(), Application::APP_ID, 'pdf_enable', 'true'), - 'enableCbx' => Server::get(IConfig::class)->getUserValue(Server::get(IUser::class)->getUID(), Application::APP_ID, 'cbx_enable', 'true'), + 'enableEpub' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'epub_enable', 'true'), + 'enablePdf' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'pdf_enable', 'true'), + 'enableCbx' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'cbx_enable', 'true'), ]; $settings['array']['oc_appconfig'] = ($isJson) ? json_encode($array) : $array; }