11<?php
22
3+ declare (strict_types=1 );
4+
35/**
46 * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
57 * SPDX-License-Identifier: AGPL-3.0-or-later
68 */
9+
710namespace OC \GlobalScale ;
811
912use OCP \IConfig ;
13+ use Override ;
1014
1115class Config implements \OCP \GlobalScale \IConfig {
12- /** @var IConfig */
13- private $ config ;
14-
15- /**
16- * Config constructor.
17- *
18- * @param IConfig $config
19- */
20- public function __construct (IConfig $ config ) {
21- $ this ->config = $ config ;
16+ public function __construct (
17+ private readonly IConfig $ config ,
18+ ) {
2219 }
2320
24- /**
25- * check if global scale is enabled
26- *
27- * @since 12.0.1
28- * @return bool
29- */
30- public function isGlobalScaleEnabled () {
21+ #[Override]
22+ public function isGlobalScaleEnabled (): bool {
3123 return $ this ->config ->getSystemValueBool ('gs.enabled ' , false );
3224 }
3325
34- /**
35- * check if federation should only be used internally in a global scale setup
36- *
37- * @since 12.0.1
38- * @return bool
39- */
40- public function onlyInternalFederation () {
26+ #[Override]
27+ public function onlyInternalFederation (): bool {
4128 // if global scale is disabled federation works always globally
4229 $ gsEnabled = $ this ->isGlobalScaleEnabled ();
4330 if ($ gsEnabled === false ) {
@@ -48,4 +35,24 @@ public function onlyInternalFederation() {
4835
4936 return $ enabled === 'internal ' ;
5037 }
38+
39+ #[Override]
40+ public function isPrimary (): bool {
41+ return $ this ->isGlobalScaleEnabled ()
42+ && ($ this ->config ->getSystemValueString ('gss.mode ' , 'slave ' ) === 'master '
43+ || $ this ->config ->getSystemValueString ('gss.mode ' , 'slave ' ) === 'primary ' );
44+ }
45+
46+ #[Override]
47+ public function isSecondary (): bool {
48+ return $ this ->isGlobalScaleEnabled ()
49+ && ($ this ->config ->getSystemValueString ('gss.mode ' , 'slave ' ) === 'slave '
50+ || $ this ->config ->getSystemValueString ('gss.mode ' , 'slave ' ) === 'secondary ' );
51+ }
52+
53+ #[Override]
54+ public function isPrimaryAdmin (string $ userId ): bool {
55+ return in_array ($ userId , $ this ->config ->getSystemValue ('gss.master.admin ' , []))
56+ || in_array ($ userId , $ this ->config ->getSystemValue ('gss.primary.admin ' , []));
57+ }
5158}
0 commit comments