Skip to content

Commit 3b49198

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

7 files changed

Lines changed: 51 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
@@ -1046,7 +1046,6 @@
10461046
'OCP\\User\\Backend\\IGetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
10471047
'OCP\\User\\Backend\\IGetHomeBackend' => $baseDir . '/lib/public/User/Backend/IGetHomeBackend.php',
10481048
'OCP\\User\\Backend\\IGetRealUIDBackend' => $baseDir . '/lib/public/User/Backend/IGetRealUIDBackend.php',
1049-
'OCP\\User\\Backend\\IGlobalScaleExtraDataBackend' => $baseDir . '/lib/public/User/Backend/IGlobalScaleExtraDataBackend.php',
10501049
'OCP\\User\\Backend\\ILimitAwareCountUsersBackend' => $baseDir . '/lib/public/User/Backend/ILimitAwareCountUsersBackend.php',
10511050
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => $baseDir . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
10521051
'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
@@ -1087,7 +1087,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
10871087
'OCP\\User\\Backend\\IGetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
10881088
'OCP\\User\\Backend\\IGetHomeBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetHomeBackend.php',
10891089
'OCP\\User\\Backend\\IGetRealUIDBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetRealUIDBackend.php',
1090-
'OCP\\User\\Backend\\IGlobalScaleExtraDataBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGlobalScaleExtraDataBackend.php',
10911090
'OCP\\User\\Backend\\ILimitAwareCountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ILimitAwareCountUsersBackend.php',
10921091
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
10931092
'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
@@ -28,6 +28,7 @@
2828
use OCP\EventDispatcher\IEventDispatcher;
2929
use OCP\Files\Conversion\IConversionProvider;
3030
use OCP\Files\Template\ICustomTemplateProvider;
31+
use OCP\GlobalScale\IGlobalScaleService;
3132
use OCP\Http\WellKnown\IHandler;
3233
use OCP\Mail\Provider\IProvider as IMailProvider;
3334
use OCP\Notification\INotifier;
@@ -166,6 +167,9 @@ class RegistrationContext {
166167
/** @var ServiceRegistration<IMailProvider>[] */
167168
private $mailProviders = [];
168169

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

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

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

10901108
return Server::get($this->configLexiconClasses[$appId]);
10911109
}
1110+
1111+
/**
1112+
* @return ?class-string<IGlobalScaleService>
1113+
*/
1114+
public function getGlobalScaleService(): ?string {
1115+
return $this->globalScaleService;
1116+
}
10921117
}

lib/private/Server.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
use OCP\Files\Template\ITemplateManager;
210210
use OCP\FilesMetadata\IFilesMetadataManager;
211211
use OCP\FullTextSearch\IFullTextSearchManager;
212+
use OCP\GlobalScale\IGlobalScaleService;
212213
use OCP\Group\ISubAdmin;
213214
use OCP\Http\Client\IClientService;
214215
use OCP\IAppConfig;
@@ -1327,6 +1328,17 @@ public function __construct(
13271328
$this->registerAlias(ISnowflakeDecoder::class, SnowflakeDecoder::class);
13281329
$this->registerAlias(IJobRuns::class, JobRuns::class);
13291330

1331+
$this->registerService(IGlobalScaleService::class, function (ContainerInterface $c): IGlobalScaleService {
1332+
/** @var Coordinator $coordinator */
1333+
$coordinator = $c->get(Coordinator::class);
1334+
$registrationContext = $coordinator->getRegistrationContext();
1335+
$globalScaleServiceClass = $registrationContext->getGlobalScaleService();
1336+
if ($globalScaleServiceClass === null) {
1337+
throw new ServiceUnavailableException('The app providing the global scale service is not enabled');
1338+
}
1339+
return $c->get($globalScaleServiceClass);
1340+
});
1341+
13301342
$this->connectDispatcher();
13311343
}
13321344

lib/private/ServiceUnavailableException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
*/
1010
namespace OC;
1111

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

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;
@@ -459,4 +460,12 @@ public function registerMailProvider(string $class): void;
459460
* @since 31.0.0
460461
*/
461462
public function registerConfigLexicon(string $configLexiconClass): void;
463+
464+
/**
465+
* Register an implementation of {@see IGlobalScaleService}.
466+
*
467+
* @param class-string<IGlobalScaleService> $globalScaleServiceClass
468+
* @since 34.0.3
469+
*/
470+
public function registerGlobalScaleService(string $globalScaleServiceClass): void;
462471
}

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)