Skip to content

Commit 7385936

Browse files
committed
feat: Allow to register a class implementing IGlobalScaleService
Assisted-by: ClaudeCode:claude-sonnet-5 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent a08b5fc commit 7385936

6 files changed

Lines changed: 50 additions & 3 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@
10831083
'OCP\\User\\Backend\\IGetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
10841084
'OCP\\User\\Backend\\IGetHomeBackend' => $baseDir . '/lib/public/User/Backend/IGetHomeBackend.php',
10851085
'OCP\\User\\Backend\\IGetRealUIDBackend' => $baseDir . '/lib/public/User/Backend/IGetRealUIDBackend.php',
1086-
'OCP\\User\\Backend\\IGlobalScaleExtraDataBackend' => $baseDir . '/lib/public/User/Backend/IGlobalScaleExtraDataBackend.php',
10871086
'OCP\\User\\Backend\\ILimitAwareCountUsersBackend' => $baseDir . '/lib/public/User/Backend/ILimitAwareCountUsersBackend.php',
10881087
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => $baseDir . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
10891088
'OCP\\User\\Backend\\IPasswordHashBackend' => $baseDir . '/lib/public/User/Backend/IPasswordHashBackend.php',

lib/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
11241124
'OCP\\User\\Backend\\IGetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
11251125
'OCP\\User\\Backend\\IGetHomeBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetHomeBackend.php',
11261126
'OCP\\User\\Backend\\IGetRealUIDBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetRealUIDBackend.php',
1127-
'OCP\\User\\Backend\\IGlobalScaleExtraDataBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGlobalScaleExtraDataBackend.php',
11281127
'OCP\\User\\Backend\\ILimitAwareCountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ILimitAwareCountUsersBackend.php',
11291128
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
11301129
'OCP\\User\\Backend\\IPasswordHashBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IPasswordHashBackend.php',

lib/private/AppFramework/Bootstrap/RegistrationContext.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\EventDispatcher\IEventDispatcher;
3030
use OCP\Files\Conversion\IConversionProvider;
3131
use OCP\Files\Template\ICustomTemplateProvider;
32+
use OCP\GlobalScale\IGlobalScaleService;
3233
use OCP\Http\WellKnown\IHandler;
3334
use OCP\Mail\Provider\IProvider as IMailProvider;
3435
use OCP\Notification\INotifier;
@@ -167,6 +168,9 @@ class RegistrationContext {
167168
/** @var ServiceRegistration<IMailProvider>[] */
168169
private $mailProviders = [];
169170

171+
/** @var class-string<IGlobalScaleService>|null */
172+
private ?string $globalScaleService = null;
173+
170174
public function __construct(
171175
private LoggerInterface $logger,
172176
) {
@@ -491,6 +495,13 @@ public function registerConfigLexicon(string $configLexiconClass): void {
491495
$configLexiconClass
492496
);
493497
}
498+
499+
#[\Override]
500+
public function registerGlobalScaleService(string $globalScaleServiceClass): void {
501+
$this->context->registerGlobalScaleService(
502+
$globalScaleServiceClass
503+
);
504+
}
494505
};
495506
}
496507

@@ -709,6 +720,13 @@ public function registerConfigLexicon(string $appId, string $configLexiconClass)
709720
$this->configLexiconClasses[$appId] = $configLexiconClass;
710721
}
711722

723+
/**
724+
* @param class-string<IGlobalScaleService> $class
725+
*/
726+
public function registerGlobalScaleService(string $class): void {
727+
$this->globalScaleService = $class;
728+
}
729+
712730
/**
713731
* @param App[] $apps
714732
*/
@@ -1094,4 +1112,11 @@ public function getConfigLexicon(string $appId): ?ILexicon {
10941112

10951113
return Server::get($this->configLexiconClasses[$appId]);
10961114
}
1115+
1116+
/**
1117+
* @return ?class-string<IGlobalScaleService>
1118+
*/
1119+
public function getGlobalScaleService(): ?string {
1120+
return $this->globalScaleService;
1121+
}
10971122
}

lib/private/Server.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OC\Accounts\AccountManager;
1313
use OC\Activity\EventMerger;
1414
use OC\App\AppManager;
15+
use OC\AppFramework\Bootstrap\Coordinator;
1516
use OC\AppFramework\Http\Request;
1617
use OC\AppFramework\Http\RequestId;
1718
use OC\AppFramework\Services\AppConfig;
@@ -204,6 +205,7 @@
204205
use OCP\Files\Template\ITemplateManager;
205206
use OCP\FilesMetadata\IFilesMetadataManager;
206207
use OCP\FullTextSearch\IFullTextSearchManager;
208+
use OCP\GlobalScale\IGlobalScaleService;
207209
use OCP\Group\ISubAdmin;
208210
use OCP\Http\Client\IClientService;
209211
use OCP\IAppConfig;
@@ -1154,6 +1156,17 @@ function () use ($c) {
11541156
$this->registerAlias(\NCU\Sharing\ISharingRegistry::class, \OC\Sharing\SharingRegistry::class);
11551157
$this->registerAlias(\NCU\Sharing\ISharingManager::class, \OC\Sharing\SharingManager::class);
11561158

1159+
$this->registerService(IGlobalScaleService::class, function (ContainerInterface $c): IGlobalScaleService {
1160+
/** @var Coordinator $coordinator */
1161+
$coordinator = $c->get(Coordinator::class);
1162+
$registrationContext = $coordinator->getRegistrationContext();
1163+
$globalScaleServiceClass = $registrationContext->getGlobalScaleService();
1164+
if ($globalScaleServiceClass === null) {
1165+
throw new ServiceUnavailableException('The app providing the global scale service is not enabled');
1166+
}
1167+
return $c->get($globalScaleServiceClass);
1168+
});
1169+
11571170
$this->connectDispatcher();
11581171
}
11591172

lib/private/ServiceUnavailableException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
namespace OC;
1212

13-
class ServiceUnavailableException extends \Exception {
13+
use Psr\Container\ContainerExceptionInterface;
14+
15+
class ServiceUnavailableException extends \Exception implements ContainerExceptionInterface {
1416
}

lib/public/AppFramework/Bootstrap/IRegistrationContext.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\Collaboration\Reference\IReferenceProvider;
1717
use OCP\EventDispatcher\IEventDispatcher;
1818
use OCP\Files\Template\ICustomTemplateProvider;
19+
use OCP\GlobalScale\IGlobalScaleService;
1920
use OCP\IContainer;
2021
use OCP\Mail\Provider\IProvider as IMailProvider;
2122
use OCP\Notification\INotifier;
@@ -458,4 +459,12 @@ public function registerMailProvider(string $class): void;
458459
* @since 31.0.0
459460
*/
460461
public function registerConfigLexicon(string $configLexiconClass): void;
462+
463+
/**
464+
* Register an implementation of {@see IGlobalScaleService}.
465+
*
466+
* @param class-string<IGlobalScaleService> $globalScaleServiceClass
467+
* @since 34.0.3
468+
*/
469+
public function registerGlobalScaleService(string $globalScaleServiceClass): void;
461470
}

0 commit comments

Comments
 (0)