Fix user in hook

This commit is contained in:
Michel Roux 2023-06-17 00:52:17 +02:00
parent efca0f86ac
commit 79788c98b9

View File

@ -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;
}