Passed
Push — master ( d2606a...e12737 )
by Christoph
14:29 queued 13s
created
apps/federation/lib/SyncFederationAddressBooks.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -32,67 +32,67 @@
 block discarded – undo
32 32
 use Psr\Log\LoggerInterface;
33 33
 
34 34
 class SyncFederationAddressBooks {
35
-	protected DbHandler $dbHandler;
36
-	private SyncService $syncService;
37
-	private DiscoveryService $ocsDiscoveryService;
38
-	private LoggerInterface $logger;
35
+    protected DbHandler $dbHandler;
36
+    private SyncService $syncService;
37
+    private DiscoveryService $ocsDiscoveryService;
38
+    private LoggerInterface $logger;
39 39
 
40
-	public function __construct(DbHandler $dbHandler,
41
-								SyncService $syncService,
42
-								IDiscoveryService $ocsDiscoveryService,
43
-								LoggerInterface $logger
44
-	) {
45
-		$this->syncService = $syncService;
46
-		$this->dbHandler = $dbHandler;
47
-		$this->ocsDiscoveryService = $ocsDiscoveryService;
48
-		$this->logger = $logger;
49
-	}
40
+    public function __construct(DbHandler $dbHandler,
41
+                                SyncService $syncService,
42
+                                IDiscoveryService $ocsDiscoveryService,
43
+                                LoggerInterface $logger
44
+    ) {
45
+        $this->syncService = $syncService;
46
+        $this->dbHandler = $dbHandler;
47
+        $this->ocsDiscoveryService = $ocsDiscoveryService;
48
+        $this->logger = $logger;
49
+    }
50 50
 
51
-	/**
52
-	 * @param \Closure $callback
53
-	 */
54
-	public function syncThemAll(\Closure $callback) {
55
-		$trustedServers = $this->dbHandler->getAllServer();
56
-		foreach ($trustedServers as $trustedServer) {
57
-			$url = $trustedServer['url'];
58
-			$callback($url, null);
59
-			$sharedSecret = $trustedServer['shared_secret'];
60
-			$syncToken = $trustedServer['sync_token'];
51
+    /**
52
+     * @param \Closure $callback
53
+     */
54
+    public function syncThemAll(\Closure $callback) {
55
+        $trustedServers = $this->dbHandler->getAllServer();
56
+        foreach ($trustedServers as $trustedServer) {
57
+            $url = $trustedServer['url'];
58
+            $callback($url, null);
59
+            $sharedSecret = $trustedServer['shared_secret'];
60
+            $syncToken = $trustedServer['sync_token'];
61 61
 
62
-			$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
63
-			$cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
64
-			$addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
62
+            $endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
63
+            $cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
64
+            $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
65 65
 
66
-			if (is_null($sharedSecret)) {
67
-				$this->logger->debug("Shared secret for $url is null");
68
-				continue;
69
-			}
70
-			$targetBookId = $trustedServer['url_hash'];
71
-			$targetPrincipal = "principals/system/system";
72
-			$targetBookProperties = [
73
-				'{DAV:}displayname' => $url
74
-			];
75
-			try {
76
-				$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
77
-				if ($newToken !== $syncToken) {
78
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
79
-				} else {
80
-					$this->logger->debug("Sync Token for $url unchanged from previous sync");
81
-				}
82
-			} catch (\Exception $ex) {
83
-				if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
84
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
85
-					$this->logger->error("Server sync for $url failed because of revoked access.", [
86
-						'exception' => $ex,
87
-					]);
88
-				} else {
89
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_FAILURE);
90
-					$this->logger->error("Server sync for $url failed.", [
91
-						'exception' => $ex,
92
-					]);
93
-				}
94
-				$callback($url, $ex);
95
-			}
96
-		}
97
-	}
66
+            if (is_null($sharedSecret)) {
67
+                $this->logger->debug("Shared secret for $url is null");
68
+                continue;
69
+            }
70
+            $targetBookId = $trustedServer['url_hash'];
71
+            $targetPrincipal = "principals/system/system";
72
+            $targetBookProperties = [
73
+                '{DAV:}displayname' => $url
74
+            ];
75
+            try {
76
+                $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
77
+                if ($newToken !== $syncToken) {
78
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
79
+                } else {
80
+                    $this->logger->debug("Sync Token for $url unchanged from previous sync");
81
+                }
82
+            } catch (\Exception $ex) {
83
+                if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
84
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
85
+                    $this->logger->error("Server sync for $url failed because of revoked access.", [
86
+                        'exception' => $ex,
87
+                    ]);
88
+                } else {
89
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_FAILURE);
90
+                    $this->logger->error("Server sync for $url failed.", [
91
+                        'exception' => $ex,
92
+                    ]);
93
+                }
94
+                $callback($url, $ex);
95
+            }
96
+        }
97
+    }
98 98
 }
Please login to merge, or discard this patch.