Refacto all project #1

Merged
Xefir merged 18 commits from test into master 2023-06-17 23:48:37 +00:00
Showing only changes of commit 79788c98b9 - Show all commits

View File

@ -13,7 +13,7 @@ namespace OCA\Epubreader;
use OCA\Epubreader\AppInfo\Application; use OCA\Epubreader\AppInfo\Application;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IUser; use OCP\IUserSession;
use OCP\Server; use OCP\Server;
class Hooks { class Hooks {
@ -21,7 +21,9 @@ class Hooks {
public static function announce_settings(array $settings): void { public static function announce_settings(array $settings): void {
// Nextcloud encodes this as JSON, Owncloud does not (yet) (#75) // 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 // 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']) && is_array($settings['array']) &&
array_key_exists('oc_appconfig', $settings['array']) array_key_exists('oc_appconfig', $settings['array'])
) { ) {
@ -29,9 +31,9 @@ class Hooks {
/** @var array $array */ /** @var array $array */
$array = ($isJson) ? json_decode((string) $settings['array']['oc_appconfig'], true) : $settings['array']['oc_appconfig']; $array = ($isJson) ? json_decode((string) $settings['array']['oc_appconfig'], true) : $settings['array']['oc_appconfig'];
$array['filesReader'] = [ $array['filesReader'] = [
'enableEpub' => Server::get(IConfig::class)->getUserValue(Server::get(IUser::class)->getUID(), Application::APP_ID, 'epub_enable', 'true'), 'enableEpub' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'epub_enable', 'true'),
'enablePdf' => Server::get(IConfig::class)->getUserValue(Server::get(IUser::class)->getUID(), Application::APP_ID, 'pdf_enable', 'true'), 'enablePdf' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'pdf_enable', 'true'),
'enableCbx' => Server::get(IConfig::class)->getUserValue(Server::get(IUser::class)->getUID(), Application::APP_ID, 'cbx_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; $settings['array']['oc_appconfig'] = ($isJson) ? json_encode($array) : $array;
} }