Skip to content

Commit 748804d

Browse files
committed
feat: Allow to register a class implementing IGlobalScaleService
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent d947818 commit 748804d

7 files changed

Lines changed: 52 additions & 4 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;
@@ -206,6 +207,7 @@
206207
use OCP\Files\Template\ITemplateManager;
207208
use OCP\FilesMetadata\IFilesMetadataManager;
208209
use OCP\FullTextSearch\IFullTextSearchManager;
210+
use OCP\GlobalScale\IGlobalScaleService;
209211
use OCP\Group\ISubAdmin;
210212
use OCP\Http\Client\IClientService;
211213
use OCP\IAppConfig;
@@ -1156,6 +1158,17 @@ function () use ($c) {
11561158
$this->registerAlias(\NCU\Sharing\ISharingRegistry::class, SharingRegistry::class);
11571159
$this->registerAlias(\NCU\Sharing\ISharingManager::class, SharingManager::class);
11581160

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

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
}

lib/public/GlobalScale/IGlobalScaleService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ interface IGlobalScaleService {
2626
* be decoded on the receiving end with {@see IGlobalScaleService::decodePayload()}.
2727
*
2828
* @param non-empty-string $path
29+
* @return string The url of the secondary
2930
* @throws \Exception When unable to send the payload.
3031
* @since 34.0.3
3132
*/
32-
public function sendToSecondary(IUser $user, string $path, array $payload): void;
33+
public function sendToSecondary(IUser $user, string $path, array $payload): string;
3334

3435
/**
3536
* Decode a receiving payload.

0 commit comments

Comments
 (0)