refactor: Cleanup files app bootstrap

- Register event listener in the register method
- Remove hook for injecting max_chunk_size in app config and move
  that code directly in JSConfigHelper
- Remove getUserFolder deprecated API usage

Signed-off-by: Carl Schwan <carlschwan@kde.org>
pull/59831/head
Carl Schwan 4 months ago
parent 351d3c6377
commit 0aafc14272
No known key found for this signature in database
GPG Key ID: 02325448204E452A
  1. 1
      apps/files/composer/composer/autoload_classmap.php
  2. 1
      apps/files/composer/composer/autoload_static.php
  3. 23
      apps/files/lib/App.php
  4. 17
      apps/files/lib/AppInfo/Application.php
  5. 30
      apps/files/lib/Collaboration/Resources/Listener.php
  6. 2
      apps/files_sharing/lib/Listener/LoadAdditionalListener.php
  7. 5
      build/psalm-baseline.xml
  8. 9
      lib/private/Template/JSConfigHelper.php

@ -17,7 +17,6 @@ return array(
'OCA\\Files\\Activity\\Settings\\FileChanged' => $baseDir . '/../lib/Activity/Settings/FileChanged.php',
'OCA\\Files\\Activity\\Settings\\FileFavoriteChanged' => $baseDir . '/../lib/Activity/Settings/FileFavoriteChanged.php',
'OCA\\Files\\AdvancedCapabilities' => $baseDir . '/../lib/AdvancedCapabilities.php',
'OCA\\Files\\App' => $baseDir . '/../lib/App.php',
'OCA\\Files\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => $baseDir . '/../lib/BackgroundJob/CleanupDirectEditingTokens.php',
'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => $baseDir . '/../lib/BackgroundJob/CleanupFileLocks.php',

@ -32,7 +32,6 @@ class ComposerStaticInitFiles
'OCA\\Files\\Activity\\Settings\\FileChanged' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileChanged.php',
'OCA\\Files\\Activity\\Settings\\FileFavoriteChanged' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileFavoriteChanged.php',
'OCA\\Files\\AdvancedCapabilities' => __DIR__ . '/..' . '/../lib/AdvancedCapabilities.php',
'OCA\\Files\\App' => __DIR__ . '/..' . '/../lib/App.php',
'OCA\\Files\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupDirectEditingTokens.php',
'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupFileLocks.php',

@ -1,23 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files;
use OCA\Files\Service\ChunkedUploadConfig;
class App {
public static function extendJsConfig($settings): void {
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
$appConfig['files'] = [
'max_chunk_size' => ChunkedUploadConfig::getMaxChunkSize(),
];
$settings['array']['oc_appconfig'] = json_encode($appConfig);
}
}

@ -9,7 +9,6 @@ declare(strict_types=1);
namespace OCA\Files\AppInfo;
use Closure;
use OCA\Files\AdvancedCapabilities;
use OCA\Files\Capabilities;
use OCA\Files\Collaboration\Resources\Listener;
@ -41,8 +40,10 @@ use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
use OCP\Files\Events\Node\NodeCopiedEvent;
use OCP\Files\Events\NodeAddedToFavorite;
use OCP\Files\Events\NodeRemovedFromFavorite;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\Share\Events\ShareDeletedFromSelfEvent;
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\Util;
class Application extends App implements IBootstrap {
public const APP_ID = 'files';
@ -72,6 +73,10 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(NodeRemovedFromFavorite::class, NodeRemovedFromFavoriteListener::class);
$context->registerEventListener(UserFirstTimeLoggedInEvent::class, UserFirstTimeLoggedInListener::class);
$context->registerEventListener(ShareCreatedEvent::class, Listener::class);
$context->registerEventListener(ShareDeletedEvent::class, Listener::class);
$context->registerEventListener(ShareDeletedFromSelfEvent::class, Listener::class);
$context->registerSearchProvider(FilesSearchProvider::class);
$context->registerNotifierService(Notifier::class);
@ -83,16 +88,10 @@ class Application extends App implements IBootstrap {
#[\Override]
public function boot(IBootContext $context): void {
$context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
$context->injectFn([Listener::class, 'register']);
$this->registerHooks();
$context->injectFn($this->registerCollaboration(...));
}
private function registerCollaboration(IProviderManager $providerManager): void {
$providerManager->registerResourceProvider(ResourceProvider::class);
}
private function registerHooks(): void {
Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
}
}

@ -10,25 +10,29 @@ declare(strict_types=1);
namespace OCA\Files\Collaboration\Resources;
use OCP\Collaboration\Resources\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Server;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\Share\Events\ShareDeletedFromSelfEvent;
class Listener {
public static function register(IEventDispatcher $dispatcher): void {
$dispatcher->addListener(ShareCreatedEvent::class, [self::class, 'shareModification']);
$dispatcher->addListener(ShareDeletedEvent::class, [self::class, 'shareModification']);
$dispatcher->addListener(ShareDeletedFromSelfEvent::class, [self::class, 'shareModification']);
/**
* @template-implements IEventListener<ShareCreatedEvent|ShareDeletedEvent|ShareDeletedFromSelfEvent>
*/
class Listener implements IEventListener {
public function __construct(
protected readonly IManager $resourceManager,
protected readonly ResourceProvider $resourceProvider,
) {
}
public static function shareModification(): void {
/** @var IManager $resourceManager */
$resourceManager = Server::get(IManager::class);
/** @var ResourceProvider $resourceProvider */
$resourceProvider = Server::get(ResourceProvider::class);
public function handle(Event $event): void {
if ($event instanceof ShareDeletedFromSelfEvent || $event instanceof ShareDeletedEvent || $event instanceof ShareCreatedEvent) {
$this->shareModification();
}
}
$resourceManager->invalidateAccessCacheForProvider($resourceProvider);
public function shareModification(): void {
$this->resourceManager->invalidateAccessCacheForProvider($this->resourceProvider);
}
}

@ -30,7 +30,7 @@ class LoadAdditionalListener implements IEventListener {
Util::addStyle(Application::APP_ID, 'icons');
$shareManager = Server::get(IManager::class);
if ($shareManager->shareApiEnabled() && class_exists('\OCA\Files\App')) {
if ($shareManager->shareApiEnabled()) {
Util::addInitScript(Application::APP_ID, 'init');
}
}

@ -1399,11 +1399,6 @@
<code><![CDATA[$this->fileIsEncrypted]]></code>
</TypeDoesNotContainType>
</file>
<file src="apps/files/lib/AppInfo/Application.php">
<DeprecatedMethod>
<code><![CDATA[Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig')]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files/lib/BackgroundJob/ScanFiles.php">
<DeprecatedClass>
<code><![CDATA[\OC_Util::tearDownFS()]]></code>

@ -13,6 +13,7 @@ use OC\Authentication\Token\IProvider;
use OC\CapabilitiesManager;
use OC\Core\AppInfo\ConfigLexicon;
use OC\Files\FilenameValidator;
use OCA\Files\Service\ChunkedUploadConfig;
use OCA\Provisioning_API\Controller\AUserDataOCSController;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
@ -257,7 +258,10 @@ class JSConfigHelper {
'defaultRemoteExpireDateEnabled' => $defaultRemoteExpireDateEnabled,
'defaultRemoteExpireDate' => $defaultRemoteExpireDate,
'defaultRemoteExpireDateEnforced' => $defaultRemoteExpireDateEnforced,
]
],
'files' => [
'max_chunk_size' => ChunkedUploadConfig::getMaxChunkSize(),
],
]),
'_theme' => json_encode([
'entity' => $this->defaults->getEntity(),
@ -288,9 +292,6 @@ class JSConfigHelper {
$this->initialStateService->provideInitialState('core', 'config', $config);
$this->initialStateService->provideInitialState('core', 'capabilities', $capabilities);
// Allow hooks to modify the output values
\OC_Hook::emit('\OCP\Config', 'js', ['array' => &$array]);
$result = '';
// Echo it

Loading…
Cancel
Save