Skip to content

Commit 20ebc6f

Browse files
CarlSchwanbackportbot[bot]
authored andcommitted
feat: Allow to register a class implementing IGlobalScaleService
feat: Allow to register a class implementing IGlobalScaleService Signed-off-by: Carl Schwan <carl@carlschwan.eu> [skip ci]
1 parent 30d6dc2 commit 20ebc6f

7 files changed

Lines changed: 48 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
@@ -1013,7 +1013,6 @@
10131013
'OCP\\User\\Backend\\IGetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
10141014
'OCP\\User\\Backend\\IGetHomeBackend' => $baseDir . '/lib/public/User/Backend/IGetHomeBackend.php',
10151015
'OCP\\User\\Backend\\IGetRealUIDBackend' => $baseDir . '/lib/public/User/Backend/IGetRealUIDBackend.php',
1016-
'OCP\\User\\Backend\\IGlobalScaleExtraDataBackend' => $baseDir . '/lib/public/User/Backend/IGlobalScaleExtraDataBackend.php',
10171016
'OCP\\User\\Backend\\ILimitAwareCountUsersBackend' => $baseDir . '/lib/public/User/Backend/ILimitAwareCountUsersBackend.php',
10181017
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => $baseDir . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
10191018
'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
@@ -1054,7 +1054,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
10541054
'OCP\\User\\Backend\\IGetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
10551055
'OCP\\User\\Backend\\IGetHomeBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetHomeBackend.php',
10561056
'OCP\\User\\Backend\\IGetRealUIDBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetRealUIDBackend.php',
1057-
'OCP\\User\\Backend\\IGlobalScaleExtraDataBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGlobalScaleExtraDataBackend.php',
10581057
'OCP\\User\\Backend\\ILimitAwareCountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ILimitAwareCountUsersBackend.php',
10591058
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
10601059
'OCP\\User\\Backend\\IPasswordHashBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IPasswordHashBackend.php',

lib/private/AppFramework/Bootstrap/RegistrationContext.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\Dashboard\IWidget;
2727
use OCP\EventDispatcher\IEventDispatcher;
2828
use OCP\Files\Template\ICustomTemplateProvider;
29+
use OCP\GlobalScale\IGlobalScaleService;
2930
use OCP\Http\WellKnown\IHandler;
3031
use OCP\Mail\Provider\IProvider as IMailProvider;
3132
use OCP\Notification\INotifier;
@@ -443,6 +444,13 @@ public function registerConfigLexicon(string $configLexiconClass): void {
443444
$configLexiconClass
444445
);
445446
}
447+
448+
#[\Override]
449+
public function registerGlobalScaleService(string $globalScaleServiceClass): void {
450+
$this->context->registerGlobalScaleService(
451+
$globalScaleServiceClass
452+
);
453+
}
446454
};
447455
}
448456

@@ -657,6 +665,13 @@ public function registerConfigLexicon(string $appId, string $configLexiconClass)
657665
$this->configLexiconClasses[$appId] = $configLexiconClass;
658666
}
659667

668+
/**
669+
* @param class-string<IGlobalScaleService> $class
670+
*/
671+
public function registerGlobalScaleService(string $class): void {
672+
$this->globalScaleService = $class;
673+
}
674+
660675
/**
661676
* @param App[] $apps
662677
*/
@@ -1031,4 +1046,11 @@ public function getConfigLexicon(string $appId): ?ILexicon {
10311046

10321047
return \OCP\Server::get($this->configLexiconClasses[$appId]);
10331048
}
1049+
1050+
/**
1051+
* @return ?class-string<IGlobalScaleService>
1052+
*/
1053+
public function getGlobalScaleService(): ?string {
1054+
return $this->globalScaleService;
1055+
}
10341056
}

lib/private/Server.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
use OCP\Files\Template\ITemplateManager;
171171
use OCP\FilesMetadata\IFilesMetadataManager;
172172
use OCP\FullTextSearch\IFullTextSearchManager;
173+
use OCP\GlobalScale\IGlobalScaleService;
173174
use OCP\Group\ISubAdmin;
174175
use OCP\Http\Client\IClientService;
175176
use OCP\IAppConfig;
@@ -1278,6 +1279,17 @@ public function __construct($webRoot, \OC\Config $config) {
12781279
}, false);
12791280
$this->registerAlias(ISnowflakeDecoder::class, SnowflakeDecoder::class);
12801281

1282+
$this->registerService(IGlobalScaleService::class, function (ContainerInterface $c): IGlobalScaleService {
1283+
/** @var Coordinator $coordinator */
1284+
$coordinator = $c->get(Coordinator::class);
1285+
$registrationContext = $coordinator->getRegistrationContext();
1286+
$globalScaleServiceClass = $registrationContext->getGlobalScaleService();
1287+
if ($globalScaleServiceClass === null) {
1288+
throw new ServiceUnavailableException('The app providing the global scale service is not enabled');
1289+
}
1290+
return $c->get($globalScaleServiceClass);
1291+
});
1292+
12811293
$this->connectDispatcher();
12821294
}
12831295

lib/private/ServiceUnavailableException.php

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

10-
class ServiceUnavailableException extends \Exception {
10+
use Psr\Container\ContainerExceptionInterface;
11+
12+
class ServiceUnavailableException extends \Exception implements ContainerExceptionInterface {
1113
}

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;
@@ -447,4 +448,12 @@ public function registerMailProvider(string $class): void;
447448
* @since 31.0.0
448449
*/
449450
public function registerConfigLexicon(string $configLexiconClass): void;
451+
452+
/**
453+
* Register an implementation of {@see IGlobalScaleService}.
454+
*
455+
* @param class-string<IGlobalScaleService> $globalScaleServiceClass
456+
* @since 34.0.3
457+
*/
458+
public function registerGlobalScaleService(string $globalScaleServiceClass): void;
450459
}

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)