mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
refactor(files): Migrate from event listener to class based declarative settings
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
9a7e1bb227
commit
bcfb02f5d7
6 changed files with 29 additions and 108 deletions
|
|
@ -58,9 +58,6 @@ return array(
|
|||
'OCA\\Files\\Event\\LoadSidebar' => $baseDir . '/../lib/Event/LoadSidebar.php',
|
||||
'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php',
|
||||
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
|
||||
'OCA\\Files\\Listener\\DeclarativeSettingsGetValueEventListener' => $baseDir . '/../lib/Listener/DeclarativeSettingsGetValueEventListener.php',
|
||||
'OCA\\Files\\Listener\\DeclarativeSettingsRegisterFormEventListener' => $baseDir . '/../lib/Listener/DeclarativeSettingsRegisterFormEventListener.php',
|
||||
'OCA\\Files\\Listener\\DeclarativeSettingsSetValueEventListener' => $baseDir . '/../lib/Listener/DeclarativeSettingsSetValueEventListener.php',
|
||||
'OCA\\Files\\Listener\\LoadSearchPluginsListener' => $baseDir . '/../lib/Listener/LoadSearchPluginsListener.php',
|
||||
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
|
||||
'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php',
|
||||
|
|
@ -77,5 +74,6 @@ return array(
|
|||
'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php',
|
||||
'OCA\\Files\\Service\\UserConfig' => $baseDir . '/../lib/Service/UserConfig.php',
|
||||
'OCA\\Files\\Service\\ViewConfig' => $baseDir . '/../lib/Service/ViewConfig.php',
|
||||
'OCA\\Files\\Settings\\DeclarativeAdminSettings' => $baseDir . '/../lib/Settings/DeclarativeAdminSettings.php',
|
||||
'OCA\\Files\\Settings\\PersonalSettings' => $baseDir . '/../lib/Settings/PersonalSettings.php',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -73,9 +73,6 @@ class ComposerStaticInitFiles
|
|||
'OCA\\Files\\Event\\LoadSidebar' => __DIR__ . '/..' . '/../lib/Event/LoadSidebar.php',
|
||||
'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php',
|
||||
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
|
||||
'OCA\\Files\\Listener\\DeclarativeSettingsGetValueEventListener' => __DIR__ . '/..' . '/../lib/Listener/DeclarativeSettingsGetValueEventListener.php',
|
||||
'OCA\\Files\\Listener\\DeclarativeSettingsRegisterFormEventListener' => __DIR__ . '/..' . '/../lib/Listener/DeclarativeSettingsRegisterFormEventListener.php',
|
||||
'OCA\\Files\\Listener\\DeclarativeSettingsSetValueEventListener' => __DIR__ . '/..' . '/../lib/Listener/DeclarativeSettingsSetValueEventListener.php',
|
||||
'OCA\\Files\\Listener\\LoadSearchPluginsListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSearchPluginsListener.php',
|
||||
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
|
||||
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
|
||||
|
|
@ -92,6 +89,7 @@ class ComposerStaticInitFiles
|
|||
'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php',
|
||||
'OCA\\Files\\Service\\UserConfig' => __DIR__ . '/..' . '/../lib/Service/UserConfig.php',
|
||||
'OCA\\Files\\Service\\ViewConfig' => __DIR__ . '/..' . '/../lib/Service/ViewConfig.php',
|
||||
'OCA\\Files\\Settings\\DeclarativeAdminSettings' => __DIR__ . '/..' . '/../lib/Settings/DeclarativeAdminSettings.php',
|
||||
'OCA\\Files\\Settings\\PersonalSettings' => __DIR__ . '/..' . '/../lib/Settings/PersonalSettings.php',
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ use OCA\Files\Controller\ApiController;
|
|||
use OCA\Files\DirectEditingCapabilities;
|
||||
use OCA\Files\Event\LoadSearchPlugins;
|
||||
use OCA\Files\Event\LoadSidebar;
|
||||
use OCA\Files\Listener\DeclarativeSettingsGetValueEventListener;
|
||||
use OCA\Files\Listener\DeclarativeSettingsRegisterFormEventListener;
|
||||
use OCA\Files\Listener\DeclarativeSettingsSetValueEventListener;
|
||||
use OCA\Files\Listener\LoadSearchPluginsListener;
|
||||
use OCA\Files\Listener\LoadSidebarListener;
|
||||
use OCA\Files\Listener\RenderReferenceEventListener;
|
||||
|
|
@ -28,6 +25,7 @@ use OCA\Files\Search\FilesSearchProvider;
|
|||
use OCA\Files\Service\TagService;
|
||||
use OCA\Files\Service\UserConfig;
|
||||
use OCA\Files\Service\ViewConfig;
|
||||
use OCA\Files\Settings\DeclarativeAdminSettings;
|
||||
use OCP\Activity\IManager as IActivityManager;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
|
|
@ -49,9 +47,6 @@ use OCP\IRequest;
|
|||
use OCP\IServerContainer;
|
||||
use OCP\ITagManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
|
||||
use OCP\Settings\Events\DeclarativeSettingsRegisterFormEvent;
|
||||
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
|
||||
use OCP\Share\IManager as IShareManager;
|
||||
use OCP\Util;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
|
@ -111,6 +106,8 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerCapability(Capabilities::class);
|
||||
$context->registerCapability(DirectEditingCapabilities::class);
|
||||
|
||||
$context->registerDeclarativeSettings(DeclarativeAdminSettings::class);
|
||||
|
||||
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
|
||||
$context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);
|
||||
$context->registerEventListener(BeforeNodeRenamedEvent::class, SyncLivePhotosListener::class);
|
||||
|
|
@ -119,9 +116,6 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerEventListener(BeforeNodeCopiedEvent::class, SyncLivePhotosListener::class);
|
||||
$context->registerEventListener(NodeCopiedEvent::class, SyncLivePhotosListener::class);
|
||||
$context->registerEventListener(LoadSearchPlugins::class, LoadSearchPluginsListener::class);
|
||||
$context->registerEventListener(DeclarativeSettingsRegisterFormEvent::class, DeclarativeSettingsRegisterFormEventListener::class);
|
||||
$context->registerEventListener(DeclarativeSettingsGetValueEvent::class, DeclarativeSettingsGetValueEventListener::class);
|
||||
$context->registerEventListener(DeclarativeSettingsSetValueEvent::class, DeclarativeSettingsSetValueEventListener::class);
|
||||
|
||||
$context->registerSearchProvider(FilesSearchProvider::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCA\Files\Listener;
|
||||
|
||||
use OCA\Files\AppInfo\Application;
|
||||
use OCA\Files\Service\SettingsService;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
|
||||
|
||||
/** @template-implements IEventListener<DeclarativeSettingsGetValueEvent> */
|
||||
class DeclarativeSettingsGetValueEventListener implements IEventListener {
|
||||
|
||||
public function __construct(
|
||||
private SettingsService $service,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof DeclarativeSettingsGetValueEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($event->getApp() !== Application::APP_ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->setValue(
|
||||
match($event->getFieldId()) {
|
||||
'windows_support' => $this->service->hasFilesWindowsSupport(),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCA\Files\Listener;
|
||||
|
||||
use OCA\Files\AppInfo\Application;
|
||||
use OCA\Files\Service\SettingsService;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
|
||||
|
||||
/** @template-implements IEventListener<DeclarativeSettingsSetValueEvent> */
|
||||
class DeclarativeSettingsSetValueEventListener implements IEventListener {
|
||||
|
||||
public function __construct(
|
||||
private SettingsService $service,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof DeclarativeSettingsSetValueEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($event->getApp() !== Application::APP_ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($event->getFieldId()) {
|
||||
case 'windows_support':
|
||||
$this->service->setFilesWindowsSupport((bool)$event->getValue());
|
||||
$event->stopPropagation();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,32 +2,42 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCA\Files\Listener;
|
||||
namespace OCA\Files\Settings;
|
||||
|
||||
use OCA\Files\AppInfo\Application;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCA\Files\Service\SettingsService;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUser;
|
||||
use OCP\Settings\DeclarativeSettingsTypes;
|
||||
use OCP\Settings\Events\DeclarativeSettingsRegisterFormEvent;
|
||||
use OCP\Settings\IDeclarativeSettingsFormWithHandlers;
|
||||
|
||||
/** @template-implements IEventListener<DeclarativeSettingsRegisterFormEvent> */
|
||||
class DeclarativeSettingsRegisterFormEventListener implements IEventListener {
|
||||
class DeclarativeAdminSettings implements IDeclarativeSettingsFormWithHandlers {
|
||||
|
||||
public function __construct(
|
||||
private IL10N $l,
|
||||
private SettingsService $service,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof DeclarativeSettingsRegisterFormEvent)) {
|
||||
return;
|
||||
}
|
||||
public function getValue(string $fieldId, IUser $user): mixed {
|
||||
return match($fieldId) {
|
||||
'windows_support' => $this->service->hasFilesWindowsSupport(),
|
||||
default => throw new \InvalidArgumentException('Unexpected field id ' . $fieldId),
|
||||
};
|
||||
}
|
||||
|
||||
$event->registerSchema(Application::APP_ID, [
|
||||
public function setValue(string $fieldId, mixed $value, IUser $user): void {
|
||||
switch ($fieldId) {
|
||||
case 'windows_support':
|
||||
$this->service->setFilesWindowsSupport((bool)$value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSchema(): array {
|
||||
return [
|
||||
'id' => 'files-filename-support',
|
||||
'priority' => 10,
|
||||
'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN,
|
||||
|
|
@ -45,6 +55,6 @@ class DeclarativeSettingsRegisterFormEventListener implements IEventListener {
|
|||
'default' => false,
|
||||
],
|
||||
],
|
||||
]);
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue