Passed
Push — master ( a2046d...d2f9de )
by Blizzz
13:01 queued 12s
created
apps/files_trashbin/appinfo/app.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
 // register hooks
29 29
 \OCA\Files_Trashbin\Trashbin::registerHooks();
30 30
 
31
-\OCA\Files\App::getNavigationManager()->add(function () {
31
+\OCA\Files\App::getNavigationManager()->add(function() {
32 32
 	$l = \OC::$server->getL10N('files_trashbin');
33 33
 	return [
34 34
 		'id' => 'trashbin',
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
 \OCA\Files_Trashbin\Trashbin::registerHooks();
30 30
 
31 31
 \OCA\Files\App::getNavigationManager()->add(function () {
32
-	$l = \OC::$server->getL10N('files_trashbin');
33
-	return [
34
-		'id' => 'trashbin',
35
-		'appname' => 'files_trashbin',
36
-		'script' => 'list.php',
37
-		'order' => 50,
38
-		'name' => $l->t('Deleted files'),
39
-		'classes' => 'pinned',
40
-	];
32
+    $l = \OC::$server->getL10N('files_trashbin');
33
+    return [
34
+        'id' => 'trashbin',
35
+        'appname' => 'files_trashbin',
36
+        'script' => 'list.php',
37
+        'order' => 50,
38
+        'name' => $l->t('Deleted files'),
39
+        'classes' => 'pinned',
40
+    ];
41 41
 });
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/Converter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -119,9 +119,9 @@
 block discarded – undo
119 119
 		$elements = explode(' ', $fullName);
120 120
 		$result = ['', '', '', '', ''];
121 121
 		if (count($elements) > 2) {
122
-			$result[0] = implode(' ', array_slice($elements, count($elements)-1));
122
+			$result[0] = implode(' ', array_slice($elements, count($elements) - 1));
123 123
 			$result[1] = $elements[0];
124
-			$result[2] = implode(' ', array_slice($elements, 1, count($elements)-2));
124
+			$result[2] = implode(' ', array_slice($elements, 1, count($elements) - 2));
125 125
 		} elseif (count($elements) === 2) {
126 126
 			$result[0] = $elements[1];
127 127
 			$result[1] = $elements[0];
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -31,122 +31,122 @@
 block discarded – undo
31 31
 
32 32
 class Converter {
33 33
 
34
-	/** @var AccountManager */
35
-	private $accountManager;
36
-
37
-	/**
38
-	 * Converter constructor.
39
-	 *
40
-	 * @param AccountManager $accountManager
41
-	 */
42
-	public function __construct(AccountManager $accountManager) {
43
-		$this->accountManager = $accountManager;
44
-	}
45
-
46
-	/**
47
-	 * @param IUser $user
48
-	 * @return VCard|null
49
-	 */
50
-	public function createCardFromUser(IUser $user) {
51
-
52
-		$userData = $this->accountManager->getUser($user);
53
-
54
-		$uid = $user->getUID();
55
-		$cloudId = $user->getCloudId();
56
-		$image = $this->getAvatarImage($user);
57
-
58
-		$vCard = new VCard();
59
-		$vCard->VERSION = '3.0';
60
-		$vCard->UID = $uid;
61
-
62
-		$publish = false;
63
-
64
-		if ($image !== null && isset($userData[AccountManager::PROPERTY_AVATAR])) {
65
-			$userData[AccountManager::PROPERTY_AVATAR]['value'] = true;
66
-		}
67
-
68
-		foreach ($userData as $property => $value) {
69
-
70
-			$shareWithTrustedServers =
71
-				$value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
72
-				$value['scope'] === AccountManager::VISIBILITY_PUBLIC;
73
-
74
-			$emptyValue = !isset($value['value']) || $value['value'] === '';
75
-
76
-			if ($shareWithTrustedServers && !$emptyValue) {
77
-				$publish = true;
78
-				switch ($property) {
79
-					case AccountManager::PROPERTY_DISPLAYNAME:
80
-						$vCard->add(new Text($vCard, 'FN', $value['value']));
81
-						$vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value'])));
82
-						break;
83
-					case AccountManager::PROPERTY_AVATAR:
84
-						if ($image !== null) {
85
-							$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
86
-						}
87
-						break;
88
-					case AccountManager::PROPERTY_EMAIL:
89
-						$vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER']));
90
-						break;
91
-					case AccountManager::PROPERTY_WEBSITE:
92
-						$vCard->add(new Text($vCard, 'URL', $value['value']));
93
-						break;
94
-					case AccountManager::PROPERTY_PHONE:
95
-						$vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER']));
96
-						break;
97
-					case AccountManager::PROPERTY_ADDRESS:
98
-						$vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER']));
99
-						break;
100
-					case AccountManager::PROPERTY_TWITTER:
101
-						$vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER']));
102
-						break;
103
-				}
104
-			}
105
-		}
106
-
107
-		if ($publish && !empty($cloudId)) {
108
-			$vCard->add(new Text($vCard, 'CLOUD', $cloudId));
109
-			$vCard->validate();
110
-			return $vCard;
111
-		}
112
-
113
-		return null;
114
-	}
115
-
116
-	/**
117
-	 * @param string $fullName
118
-	 * @return string[]
119
-	 */
120
-	public function splitFullName($fullName) {
121
-		// Very basic western style parsing. I'm not gonna implement
122
-		// https://github.com/android/platform_packages_providers_contactsprovider/blob/master/src/com/android/providers/contacts/NameSplitter.java ;)
123
-
124
-		$elements = explode(' ', $fullName);
125
-		$result = ['', '', '', '', ''];
126
-		if (count($elements) > 2) {
127
-			$result[0] = implode(' ', array_slice($elements, count($elements)-1));
128
-			$result[1] = $elements[0];
129
-			$result[2] = implode(' ', array_slice($elements, 1, count($elements)-2));
130
-		} elseif (count($elements) === 2) {
131
-			$result[0] = $elements[1];
132
-			$result[1] = $elements[0];
133
-		} else {
134
-			$result[0] = $elements[0];
135
-		}
136
-
137
-		return $result;
138
-	}
139
-
140
-	/**
141
-	 * @param IUser $user
142
-	 * @return null|IImage
143
-	 */
144
-	private function getAvatarImage(IUser $user) {
145
-		try {
146
-			return $user->getAvatarImage(-1);
147
-		} catch (\Exception $ex) {
148
-			return null;
149
-		}
150
-	}
34
+    /** @var AccountManager */
35
+    private $accountManager;
36
+
37
+    /**
38
+     * Converter constructor.
39
+     *
40
+     * @param AccountManager $accountManager
41
+     */
42
+    public function __construct(AccountManager $accountManager) {
43
+        $this->accountManager = $accountManager;
44
+    }
45
+
46
+    /**
47
+     * @param IUser $user
48
+     * @return VCard|null
49
+     */
50
+    public function createCardFromUser(IUser $user) {
51
+
52
+        $userData = $this->accountManager->getUser($user);
53
+
54
+        $uid = $user->getUID();
55
+        $cloudId = $user->getCloudId();
56
+        $image = $this->getAvatarImage($user);
57
+
58
+        $vCard = new VCard();
59
+        $vCard->VERSION = '3.0';
60
+        $vCard->UID = $uid;
61
+
62
+        $publish = false;
63
+
64
+        if ($image !== null && isset($userData[AccountManager::PROPERTY_AVATAR])) {
65
+            $userData[AccountManager::PROPERTY_AVATAR]['value'] = true;
66
+        }
67
+
68
+        foreach ($userData as $property => $value) {
69
+
70
+            $shareWithTrustedServers =
71
+                $value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
72
+                $value['scope'] === AccountManager::VISIBILITY_PUBLIC;
73
+
74
+            $emptyValue = !isset($value['value']) || $value['value'] === '';
75
+
76
+            if ($shareWithTrustedServers && !$emptyValue) {
77
+                $publish = true;
78
+                switch ($property) {
79
+                    case AccountManager::PROPERTY_DISPLAYNAME:
80
+                        $vCard->add(new Text($vCard, 'FN', $value['value']));
81
+                        $vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value'])));
82
+                        break;
83
+                    case AccountManager::PROPERTY_AVATAR:
84
+                        if ($image !== null) {
85
+                            $vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
86
+                        }
87
+                        break;
88
+                    case AccountManager::PROPERTY_EMAIL:
89
+                        $vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER']));
90
+                        break;
91
+                    case AccountManager::PROPERTY_WEBSITE:
92
+                        $vCard->add(new Text($vCard, 'URL', $value['value']));
93
+                        break;
94
+                    case AccountManager::PROPERTY_PHONE:
95
+                        $vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER']));
96
+                        break;
97
+                    case AccountManager::PROPERTY_ADDRESS:
98
+                        $vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER']));
99
+                        break;
100
+                    case AccountManager::PROPERTY_TWITTER:
101
+                        $vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER']));
102
+                        break;
103
+                }
104
+            }
105
+        }
106
+
107
+        if ($publish && !empty($cloudId)) {
108
+            $vCard->add(new Text($vCard, 'CLOUD', $cloudId));
109
+            $vCard->validate();
110
+            return $vCard;
111
+        }
112
+
113
+        return null;
114
+    }
115
+
116
+    /**
117
+     * @param string $fullName
118
+     * @return string[]
119
+     */
120
+    public function splitFullName($fullName) {
121
+        // Very basic western style parsing. I'm not gonna implement
122
+        // https://github.com/android/platform_packages_providers_contactsprovider/blob/master/src/com/android/providers/contacts/NameSplitter.java ;)
123
+
124
+        $elements = explode(' ', $fullName);
125
+        $result = ['', '', '', '', ''];
126
+        if (count($elements) > 2) {
127
+            $result[0] = implode(' ', array_slice($elements, count($elements)-1));
128
+            $result[1] = $elements[0];
129
+            $result[2] = implode(' ', array_slice($elements, 1, count($elements)-2));
130
+        } elseif (count($elements) === 2) {
131
+            $result[0] = $elements[1];
132
+            $result[1] = $elements[0];
133
+        } else {
134
+            $result[0] = $elements[0];
135
+        }
136
+
137
+        return $result;
138
+    }
139
+
140
+    /**
141
+     * @param IUser $user
142
+     * @return null|IImage
143
+     */
144
+    private function getAvatarImage(IUser $user) {
145
+        try {
146
+            return $user->getAvatarImage(-1);
147
+        } catch (\Exception $ex) {
148
+            return null;
149
+        }
150
+    }
151 151
 
152 152
 }
Please login to merge, or discard this patch.
apps/federation/lib/SyncFederationAddressBooks.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -30,64 +30,64 @@
 block discarded – undo
30 30
 
31 31
 class SyncFederationAddressBooks {
32 32
 
33
-	/** @var DbHandler */
34
-	protected $dbHandler;
33
+    /** @var DbHandler */
34
+    protected $dbHandler;
35 35
 
36
-	/** @var SyncService */
37
-	private $syncService;
36
+    /** @var SyncService */
37
+    private $syncService;
38 38
 
39
-	/** @var  DiscoveryService */
40
-	private $ocsDiscoveryService;
39
+    /** @var  DiscoveryService */
40
+    private $ocsDiscoveryService;
41 41
 
42
-	/**
43
-	 * @param DbHandler $dbHandler
44
-	 * @param SyncService $syncService
45
-	 * @param IDiscoveryService $ocsDiscoveryService
46
-	 */
47
-	public function __construct(DbHandler $dbHandler,
48
-								SyncService $syncService,
49
-								IDiscoveryService $ocsDiscoveryService
50
-	) {
51
-		$this->syncService = $syncService;
52
-		$this->dbHandler = $dbHandler;
53
-		$this->ocsDiscoveryService = $ocsDiscoveryService;
54
-	}
42
+    /**
43
+     * @param DbHandler $dbHandler
44
+     * @param SyncService $syncService
45
+     * @param IDiscoveryService $ocsDiscoveryService
46
+     */
47
+    public function __construct(DbHandler $dbHandler,
48
+                                SyncService $syncService,
49
+                                IDiscoveryService $ocsDiscoveryService
50
+    ) {
51
+        $this->syncService = $syncService;
52
+        $this->dbHandler = $dbHandler;
53
+        $this->ocsDiscoveryService = $ocsDiscoveryService;
54
+    }
55 55
 
56
-	/**
57
-	 * @param \Closure $callback
58
-	 */
59
-	public function syncThemAll(\Closure $callback) {
56
+    /**
57
+     * @param \Closure $callback
58
+     */
59
+    public function syncThemAll(\Closure $callback) {
60 60
 
61
-		$trustedServers = $this->dbHandler->getAllServer();
62
-		foreach ($trustedServers as $trustedServer) {
63
-			$url = $trustedServer['url'];
64
-			$callback($url, null);
65
-			$sharedSecret = $trustedServer['shared_secret'];
66
-			$syncToken = $trustedServer['sync_token'];
61
+        $trustedServers = $this->dbHandler->getAllServer();
62
+        foreach ($trustedServers as $trustedServer) {
63
+            $url = $trustedServer['url'];
64
+            $callback($url, null);
65
+            $sharedSecret = $trustedServer['shared_secret'];
66
+            $syncToken = $trustedServer['sync_token'];
67 67
 
68
-			$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
69
-			$cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
70
-			$addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
68
+            $endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
69
+            $cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
70
+            $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
71 71
 
72
-			if (is_null($sharedSecret)) {
73
-				continue;
74
-			}
75
-			$targetBookId = $trustedServer['url_hash'];
76
-			$targetPrincipal = "principals/system/system";
77
-			$targetBookProperties = [
78
-					'{DAV:}displayname' => $url
79
-			];
80
-			try {
81
-				$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
82
-				if ($newToken !== $syncToken) {
83
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
84
-				}
85
-			} catch (\Exception $ex) {
86
-				if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
87
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
88
-				}
89
-				$callback($url, $ex);
90
-			}
91
-		}
92
-	}
72
+            if (is_null($sharedSecret)) {
73
+                continue;
74
+            }
75
+            $targetBookId = $trustedServer['url_hash'];
76
+            $targetPrincipal = "principals/system/system";
77
+            $targetBookProperties = [
78
+                    '{DAV:}displayname' => $url
79
+            ];
80
+            try {
81
+                $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
82
+                if ($newToken !== $syncToken) {
83
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
84
+                }
85
+            } catch (\Exception $ex) {
86
+                if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
87
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
88
+                }
89
+                $callback($url, $ex);
90
+            }
91
+        }
92
+    }
93 93
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -39,33 +39,33 @@
 block discarded – undo
39 39
  * @package OCA\DAV\Connector\Sabre
40 40
  */
41 41
 class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin {
42
-	/** @var \Sabre\DAV\Server */
43
-	protected $server;
42
+    /** @var \Sabre\DAV\Server */
43
+    protected $server;
44 44
 
45
-	/**
46
-	 * @param \Sabre\DAV\Server $server
47
-	 * @return void
48
-	 */
49
-	function initialize(\Sabre\DAV\Server $server) {
50
-		$this->server = $server;
51
-		$this->server->on('method:GET', [$this, 'httpGet'], 200);
52
-	}
45
+    /**
46
+     * @param \Sabre\DAV\Server $server
47
+     * @return void
48
+     */
49
+    function initialize(\Sabre\DAV\Server $server) {
50
+        $this->server = $server;
51
+        $this->server->on('method:GET', [$this, 'httpGet'], 200);
52
+    }
53 53
 
54
-	/**
55
-	 * @param RequestInterface $request
56
-	 * @param ResponseInterface $response
57
-	 * @return false
58
-	 */
59
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
60
-		$string = 'This is the WebDAV interface. It can only be accessed by ' .
61
-			'WebDAV clients such as the Nextcloud desktop sync client.';
62
-		$stream = fopen('php://memory','r+');
63
-		fwrite($stream, $string);
64
-		rewind($stream);
54
+    /**
55
+     * @param RequestInterface $request
56
+     * @param ResponseInterface $response
57
+     * @return false
58
+     */
59
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
60
+        $string = 'This is the WebDAV interface. It can only be accessed by ' .
61
+            'WebDAV clients such as the Nextcloud desktop sync client.';
62
+        $stream = fopen('php://memory','r+');
63
+        fwrite($stream, $string);
64
+        rewind($stream);
65 65
 
66
-		$response->setStatus(200);
67
-		$response->setBody($stream);
66
+        $response->setStatus(200);
67
+        $response->setBody($stream);
68 68
 
69
-		return false;
70
-	}
69
+        return false;
70
+    }
71 71
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@
 block discarded – undo
57 57
 	 * @return false
58 58
 	 */
59 59
 	function httpGet(RequestInterface $request, ResponseInterface $response) {
60
-		$string = 'This is the WebDAV interface. It can only be accessed by ' .
60
+		$string = 'This is the WebDAV interface. It can only be accessed by '.
61 61
 			'WebDAV clients such as the Nextcloud desktop sync client.';
62
-		$stream = fopen('php://memory','r+');
62
+		$stream = fopen('php://memory', 'r+');
63 63
 		fwrite($stream, $string);
64 64
 		rewind($stream);
65 65
 
Please login to merge, or discard this patch.
lib/private/Migration/ConsoleOutput.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -37,57 +37,57 @@
 block discarded – undo
37 37
  */
38 38
 class ConsoleOutput implements IOutput {
39 39
 
40
-	/** @var OutputInterface */
41
-	private $output;
40
+    /** @var OutputInterface */
41
+    private $output;
42 42
 
43
-	/** @var ProgressBar */
44
-	private $progressBar;
43
+    /** @var ProgressBar */
44
+    private $progressBar;
45 45
 
46
-	public function __construct(OutputInterface $output) {
47
-		$this->output = $output;
48
-	}
46
+    public function __construct(OutputInterface $output) {
47
+        $this->output = $output;
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $message
52
-	 */
53
-	public function info($message) {
54
-		$this->output->writeln("<info>$message</info>");
55
-	}
50
+    /**
51
+     * @param string $message
52
+     */
53
+    public function info($message) {
54
+        $this->output->writeln("<info>$message</info>");
55
+    }
56 56
 
57
-	/**
58
-	 * @param string $message
59
-	 */
60
-	public function warning($message) {
61
-		$this->output->writeln("<comment>$message</comment>");
62
-	}
57
+    /**
58
+     * @param string $message
59
+     */
60
+    public function warning($message) {
61
+        $this->output->writeln("<comment>$message</comment>");
62
+    }
63 63
 
64
-	/**
65
-	 * @param int $max
66
-	 */
67
-	public function startProgress($max = 0) {
68
-		if (!is_null($this->progressBar)) {
69
-			$this->progressBar->finish();
70
-		}
71
-		$this->progressBar = new ProgressBar($this->output);
72
-		$this->progressBar->start($max);
73
-	}
64
+    /**
65
+     * @param int $max
66
+     */
67
+    public function startProgress($max = 0) {
68
+        if (!is_null($this->progressBar)) {
69
+            $this->progressBar->finish();
70
+        }
71
+        $this->progressBar = new ProgressBar($this->output);
72
+        $this->progressBar->start($max);
73
+    }
74 74
 
75
-	/**
76
-	 * @param int $step
77
-	 * @param string $description
78
-	 */
79
-	public function advance($step = 1, $description = '') {
80
-		if (!is_null($this->progressBar)) {
81
-			$this->progressBar = new ProgressBar($this->output);
82
-			$this->progressBar->start();
83
-		}
84
-		$this->progressBar->advance($step);
85
-	}
75
+    /**
76
+     * @param int $step
77
+     * @param string $description
78
+     */
79
+    public function advance($step = 1, $description = '') {
80
+        if (!is_null($this->progressBar)) {
81
+            $this->progressBar = new ProgressBar($this->output);
82
+            $this->progressBar->start();
83
+        }
84
+        $this->progressBar->advance($step);
85
+    }
86 86
 
87
-	public function finishProgress() {
88
-		if (is_null($this->progressBar)) {
89
-			return;
90
-		}
91
-		$this->progressBar->finish();
92
-	}
87
+    public function finishProgress() {
88
+        if (is_null($this->progressBar)) {
89
+            return;
90
+        }
91
+        $this->progressBar->finish();
92
+    }
93 93
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/Entry.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -29,141 +29,141 @@
 block discarded – undo
29 29
 
30 30
 class Entry implements IEntry {
31 31
 
32
-	/** @var string|int|null */
33
-	private $id = null;
34
-
35
-	/** @var string */
36
-	private $fullName = '';
37
-
38
-	/** @var string[] */
39
-	private $emailAddresses = [];
40
-
41
-	/** @var string|null */
42
-	private $avatar;
43
-
44
-	/** @var IAction[] */
45
-	private $actions = [];
46
-
47
-	/** @var array */
48
-	private $properties = [];
49
-
50
-	/**
51
-	 * @param string $id
52
-	 */
53
-	public function setId($id) {
54
-		$this->id = $id;
55
-	}
56
-
57
-	/**
58
-	 * @param string $displayName
59
-	 */
60
-	public function setFullName($displayName) {
61
-		$this->fullName = $displayName;
62
-	}
63
-
64
-	/**
65
-	 * @return string
66
-	 */
67
-	public function getFullName() {
68
-		return $this->fullName;
69
-	}
70
-
71
-	/**
72
-	 * @param string $address
73
-	 */
74
-	public function addEMailAddress($address) {
75
-		$this->emailAddresses[] = $address;
76
-	}
77
-
78
-	/**
79
-	 * @return string
80
-	 */
81
-	public function getEMailAddresses() {
82
-		return $this->emailAddresses;
83
-	}
84
-
85
-	/**
86
-	 * @param string $avatar
87
-	 */
88
-	public function setAvatar($avatar) {
89
-		$this->avatar = $avatar;
90
-	}
91
-
92
-	/**
93
-	 * @return string
94
-	 */
95
-	public function getAvatar() {
96
-		return $this->avatar;
97
-	}
98
-
99
-	/**
100
-	 * @param IAction $action
101
-	 */
102
-	public function addAction(IAction $action) {
103
-		$this->actions[] = $action;
104
-		$this->sortActions();
105
-	}
106
-
107
-	/**
108
-	 * @return IAction[]
109
-	 */
110
-	public function getActions() {
111
-		return $this->actions;
112
-	}
113
-
114
-	/**
115
-	 * sort the actions by priority and name
116
-	 */
117
-	private function sortActions() {
118
-		usort($this->actions, function(IAction $action1, IAction $action2) {
119
-			$prio1 = $action1->getPriority();
120
-			$prio2 = $action2->getPriority();
121
-
122
-			if ($prio1 === $prio2) {
123
-				// Ascending order for same priority
124
-				return strcasecmp($action1->getName(), $action2->getName());
125
-			}
126
-
127
-			// Descending order when priority differs
128
-			return $prio2 - $prio1;
129
-		});
130
-	}
131
-
132
-	/**
133
-	 * @param array $contact key-value array containing additional properties
134
-	 */
135
-	public function setProperties(array $contact) {
136
-		$this->properties = $contact;
137
-	}
138
-
139
-	/**
140
-	 * @param string $key
141
-	 * @return mixed
142
-	 */
143
-	public function getProperty($key) {
144
-		if (!isset($this->properties[$key])) {
145
-			return null;
146
-		}
147
-		return $this->properties[$key];
148
-	}
149
-
150
-	/**
151
-	 * @return array
152
-	 */
153
-	public function jsonSerialize() {
154
-		$topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
155
-		$otherActions = array_map(function(IAction $action) {
156
-			return $action->jsonSerialize();
157
-		}, array_slice($this->actions, 1));
158
-
159
-		return [
160
-			'id' => $this->id,
161
-			'fullName' => $this->fullName,
162
-			'avatar' => $this->getAvatar(),
163
-			'topAction' => $topAction,
164
-			'actions' => $otherActions,
165
-			'lastMessage' => '',
166
-		];
167
-	}
32
+    /** @var string|int|null */
33
+    private $id = null;
34
+
35
+    /** @var string */
36
+    private $fullName = '';
37
+
38
+    /** @var string[] */
39
+    private $emailAddresses = [];
40
+
41
+    /** @var string|null */
42
+    private $avatar;
43
+
44
+    /** @var IAction[] */
45
+    private $actions = [];
46
+
47
+    /** @var array */
48
+    private $properties = [];
49
+
50
+    /**
51
+     * @param string $id
52
+     */
53
+    public function setId($id) {
54
+        $this->id = $id;
55
+    }
56
+
57
+    /**
58
+     * @param string $displayName
59
+     */
60
+    public function setFullName($displayName) {
61
+        $this->fullName = $displayName;
62
+    }
63
+
64
+    /**
65
+     * @return string
66
+     */
67
+    public function getFullName() {
68
+        return $this->fullName;
69
+    }
70
+
71
+    /**
72
+     * @param string $address
73
+     */
74
+    public function addEMailAddress($address) {
75
+        $this->emailAddresses[] = $address;
76
+    }
77
+
78
+    /**
79
+     * @return string
80
+     */
81
+    public function getEMailAddresses() {
82
+        return $this->emailAddresses;
83
+    }
84
+
85
+    /**
86
+     * @param string $avatar
87
+     */
88
+    public function setAvatar($avatar) {
89
+        $this->avatar = $avatar;
90
+    }
91
+
92
+    /**
93
+     * @return string
94
+     */
95
+    public function getAvatar() {
96
+        return $this->avatar;
97
+    }
98
+
99
+    /**
100
+     * @param IAction $action
101
+     */
102
+    public function addAction(IAction $action) {
103
+        $this->actions[] = $action;
104
+        $this->sortActions();
105
+    }
106
+
107
+    /**
108
+     * @return IAction[]
109
+     */
110
+    public function getActions() {
111
+        return $this->actions;
112
+    }
113
+
114
+    /**
115
+     * sort the actions by priority and name
116
+     */
117
+    private function sortActions() {
118
+        usort($this->actions, function(IAction $action1, IAction $action2) {
119
+            $prio1 = $action1->getPriority();
120
+            $prio2 = $action2->getPriority();
121
+
122
+            if ($prio1 === $prio2) {
123
+                // Ascending order for same priority
124
+                return strcasecmp($action1->getName(), $action2->getName());
125
+            }
126
+
127
+            // Descending order when priority differs
128
+            return $prio2 - $prio1;
129
+        });
130
+    }
131
+
132
+    /**
133
+     * @param array $contact key-value array containing additional properties
134
+     */
135
+    public function setProperties(array $contact) {
136
+        $this->properties = $contact;
137
+    }
138
+
139
+    /**
140
+     * @param string $key
141
+     * @return mixed
142
+     */
143
+    public function getProperty($key) {
144
+        if (!isset($this->properties[$key])) {
145
+            return null;
146
+        }
147
+        return $this->properties[$key];
148
+    }
149
+
150
+    /**
151
+     * @return array
152
+     */
153
+    public function jsonSerialize() {
154
+        $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
155
+        $otherActions = array_map(function(IAction $action) {
156
+            return $action->jsonSerialize();
157
+        }, array_slice($this->actions, 1));
158
+
159
+        return [
160
+            'id' => $this->id,
161
+            'fullName' => $this->fullName,
162
+            'avatar' => $this->getAvatar(),
163
+            'topAction' => $topAction,
164
+            'actions' => $otherActions,
165
+            'lastMessage' => '',
166
+        ];
167
+    }
168 168
 
169 169
 }
Please login to merge, or discard this patch.
lib/public/Contacts/ContactsMenu/IEntry.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -31,36 +31,36 @@
 block discarded – undo
31 31
  */
32 32
 interface IEntry extends JsonSerializable {
33 33
 
34
-	/**
35
-	 * @since 12.0
36
-	 * @return string
37
-	 */
38
-	public function getFullName();
34
+    /**
35
+     * @since 12.0
36
+     * @return string
37
+     */
38
+    public function getFullName();
39 39
 
40
-	/**
41
-	 * @since 12.0
42
-	 * @return string[]
43
-	 */
44
-	public function getEMailAddresses();
40
+    /**
41
+     * @since 12.0
42
+     * @return string[]
43
+     */
44
+    public function getEMailAddresses();
45 45
 
46
-	/**
47
-	 * @since 12.0
48
-	 * @return string|null image URI
49
-	 */
50
-	public function getAvatar();
46
+    /**
47
+     * @since 12.0
48
+     * @return string|null image URI
49
+     */
50
+    public function getAvatar();
51 51
 
52
-	/**
53
-	 * @since 12.0
54
-	 * @param IAction $action an action to show in the contacts menu
55
-	 */
56
-	public function addAction(IAction $action);
52
+    /**
53
+     * @since 12.0
54
+     * @param IAction $action an action to show in the contacts menu
55
+     */
56
+    public function addAction(IAction $action);
57 57
 
58
-	/**
59
-	 * Get an arbitrary property from the contact
60
-	 *
61
-	 * @since 12.0
62
-	 * @param string $key
63
-	 * @return mixed the value of the property or null
64
-	 */
65
-	public function getProperty($key);
58
+    /**
59
+     * Get an arbitrary property from the contact
60
+     *
61
+     * @since 12.0
62
+     * @param string $key
63
+     * @return mixed the value of the property or null
64
+     */
65
+    public function getProperty($key);
66 66
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Helper.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		$result = array();
45 45
 		$timestamp = null;
46 46
 
47
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
47
+		$view = new \OC\Files\View('/'.$user.'/files_trashbin/files');
48 48
 
49 49
 		if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
50 50
 			throw new \Exception('Directory does not exists');
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 				$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
73 73
 			}
74 74
 			$originalPath = '';
75
-			$originalName = substr($entryName, 0, -strlen($timestamp)-2);
75
+			$originalName = substr($entryName, 0, -strlen($timestamp) - 2);
76 76
 			if (isset($originalLocations[$originalName][$timestamp])) {
77 77
 				$originalPath = $originalLocations[$originalName][$timestamp];
78 78
 				if (substr($originalPath, -1) === '/') {
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 			);
93 93
 			if ($originalPath) {
94 94
 				if ($originalPath !== '.') {
95
-					$i['extraData'] = $originalPath . '/' . $originalName;
95
+					$i['extraData'] = $originalPath.'/'.$originalName;
96 96
 				} else {
97 97
 					$i['extraData'] = $originalName;
98 98
 				}
99 99
 			}
100
-			$result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
100
+			$result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount);
101 101
 		}
102 102
 
103 103
 		if ($sortAttribute !== '') {
Please login to merge, or discard this patch.
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -33,96 +33,96 @@
 block discarded – undo
33 33
 use OCP\Files\Cache\ICacheEntry;
34 34
 
35 35
 class Helper {
36
-	/**
37
-	 * Retrieves the contents of a trash bin directory.
38
-	 *
39
-	 * @param string $dir path to the directory inside the trashbin
40
-	 * or empty to retrieve the root of the trashbin
41
-	 * @param string $user
42
-	 * @param string $sortAttribute attribute to sort on or empty to disable sorting
43
-	 * @param bool $sortDescending true for descending sort, false otherwise
44
-	 * @return \OCP\Files\FileInfo[]
45
-	 */
46
-	public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
47
-		$result = array();
48
-		$timestamp = null;
36
+    /**
37
+     * Retrieves the contents of a trash bin directory.
38
+     *
39
+     * @param string $dir path to the directory inside the trashbin
40
+     * or empty to retrieve the root of the trashbin
41
+     * @param string $user
42
+     * @param string $sortAttribute attribute to sort on or empty to disable sorting
43
+     * @param bool $sortDescending true for descending sort, false otherwise
44
+     * @return \OCP\Files\FileInfo[]
45
+     */
46
+    public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
47
+        $result = array();
48
+        $timestamp = null;
49 49
 
50
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
50
+        $view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
51 51
 
52
-		if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
53
-			throw new \Exception('Directory does not exists');
54
-		}
52
+        if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
53
+            throw new \Exception('Directory does not exists');
54
+        }
55 55
 
56
-		$mount = $view->getMount($dir);
57
-		$storage = $mount->getStorage();
58
-		$absoluteDir = $view->getAbsolutePath($dir);
59
-		$internalPath = $mount->getInternalPath($absoluteDir);
56
+        $mount = $view->getMount($dir);
57
+        $storage = $mount->getStorage();
58
+        $absoluteDir = $view->getAbsolutePath($dir);
59
+        $internalPath = $mount->getInternalPath($absoluteDir);
60 60
 
61
-		$originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
62
-		$dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
63
-		foreach ($dirContent as $entry) {
64
-			$entryName = $entry->getName();
65
-			$name = $entryName;
66
-			if ($dir === '' || $dir === '/') {
67
-				$pathparts = pathinfo($entryName);
68
-				$timestamp = substr($pathparts['extension'], 1);
69
-				$name = $pathparts['filename'];
61
+        $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
62
+        $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
63
+        foreach ($dirContent as $entry) {
64
+            $entryName = $entry->getName();
65
+            $name = $entryName;
66
+            if ($dir === '' || $dir === '/') {
67
+                $pathparts = pathinfo($entryName);
68
+                $timestamp = substr($pathparts['extension'], 1);
69
+                $name = $pathparts['filename'];
70 70
 
71
-			} else if ($timestamp === null) {
72
-				// for subfolders we need to calculate the timestamp only once
73
-				$parts = explode('/', ltrim($dir, '/'));
74
-				$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
75
-			}
76
-			$originalPath = '';
77
-			$originalName = substr($entryName, 0, -strlen($timestamp)-2);
78
-			if (isset($originalLocations[$originalName][$timestamp])) {
79
-				$originalPath = $originalLocations[$originalName][$timestamp];
80
-				if (substr($originalPath, -1) === '/') {
81
-					$originalPath = substr($originalPath, 0, -1);
82
-				}
83
-			}
84
-			$type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
85
-			$i = array(
86
-				'name' => $name,
87
-				'mtime' => $timestamp,
88
-				'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
89
-				'type' => $type,
90
-				'directory' => ($dir === '/') ? '' : $dir,
91
-				'size' => $entry->getSize(),
92
-				'etag' => '',
93
-				'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
94
-				'fileid' => $entry->getId(),
95
-			);
96
-			if ($originalPath) {
97
-				if ($originalPath !== '.') {
98
-					$i['extraData'] = $originalPath . '/' . $originalName;
99
-				} else {
100
-					$i['extraData'] = $originalName;
101
-				}
102
-			}
103
-			$result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
104
-		}
71
+            } else if ($timestamp === null) {
72
+                // for subfolders we need to calculate the timestamp only once
73
+                $parts = explode('/', ltrim($dir, '/'));
74
+                $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
75
+            }
76
+            $originalPath = '';
77
+            $originalName = substr($entryName, 0, -strlen($timestamp)-2);
78
+            if (isset($originalLocations[$originalName][$timestamp])) {
79
+                $originalPath = $originalLocations[$originalName][$timestamp];
80
+                if (substr($originalPath, -1) === '/') {
81
+                    $originalPath = substr($originalPath, 0, -1);
82
+                }
83
+            }
84
+            $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
85
+            $i = array(
86
+                'name' => $name,
87
+                'mtime' => $timestamp,
88
+                'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
89
+                'type' => $type,
90
+                'directory' => ($dir === '/') ? '' : $dir,
91
+                'size' => $entry->getSize(),
92
+                'etag' => '',
93
+                'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
94
+                'fileid' => $entry->getId(),
95
+            );
96
+            if ($originalPath) {
97
+                if ($originalPath !== '.') {
98
+                    $i['extraData'] = $originalPath . '/' . $originalName;
99
+                } else {
100
+                    $i['extraData'] = $originalName;
101
+                }
102
+            }
103
+            $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
104
+        }
105 105
 
106
-		if ($sortAttribute !== '') {
107
-			return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
108
-		}
109
-		return $result;
110
-	}
106
+        if ($sortAttribute !== '') {
107
+            return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
108
+        }
109
+        return $result;
110
+    }
111 111
 
112
-	/**
113
-	 * Format file infos for JSON
114
-	 *
115
-	 * @param \OCP\Files\FileInfo[] $fileInfos file infos
116
-	 */
117
-	public static function formatFileInfos($fileInfos) {
118
-		$files = array();
119
-		foreach ($fileInfos as $i) {
120
-			$entry = \OCA\Files\Helper::formatFileInfo($i);
121
-			$entry['id'] = $i->getId();
122
-			$entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
123
-			$entry['permissions'] = \OCP\Constants::PERMISSION_READ;
124
-			$files[] = $entry;
125
-		}
126
-		return $files;
127
-	}
112
+    /**
113
+     * Format file infos for JSON
114
+     *
115
+     * @param \OCP\Files\FileInfo[] $fileInfos file infos
116
+     */
117
+    public static function formatFileInfos($fileInfos) {
118
+        $files = array();
119
+        foreach ($fileInfos as $i) {
120
+            $entry = \OCA\Files\Helper::formatFileInfo($i);
121
+            $entry['id'] = $i->getId();
122
+            $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
123
+            $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
124
+            $files[] = $entry;
125
+        }
126
+        return $files;
127
+    }
128 128
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/SyncService.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 			if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
100 100
 				// remote server revoked access to the address book, remove it
101 101
 				$this->backend->deleteAddressBook($addressBookId);
102
-				$this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
102
+				$this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']);
103 103
 				throw $ex;
104 104
 			}
105 105
 		}
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	protected function getClient($url, $userName, $sharedSecret) {
151 151
 		$settings = [
152
-			'baseUri' => $url . '/',
152
+			'baseUri' => $url.'/',
153 153
 			'userName' => $userName,
154 154
 			'password' => $sharedSecret,
155 155
 		];
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	 */
270 270
 	public function deleteUser($userOrCardId) {
271 271
 		$systemAddressBook = $this->getLocalSystemAddressBook();
272
-		if ($userOrCardId instanceof IUser){
272
+		if ($userOrCardId instanceof IUser) {
273 273
 			$name = $userOrCardId->getBackendClassName();
274 274
 			$userId = $userOrCardId->getUID();
275 275
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		if (is_null($this->localSystemAddressBook)) {
286 286
 			$systemPrincipal = "principals/system/system";
287 287
 			$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
288
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
288
+				'{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance'
289 289
 			]);
290 290
 		}
291 291
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 
304 304
 		// remove no longer existing
305 305
 		$allCards = $this->backend->getCards($systemAddressBook['id']);
306
-		foreach($allCards as $card) {
306
+		foreach ($allCards as $card) {
307 307
 			$vCard = Reader::read($card['carddata']);
308 308
 			$uid = $vCard->UID->getValue();
309 309
 			// load backend and see if user exists
Please login to merge, or discard this patch.
Indentation   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -39,304 +39,304 @@
 block discarded – undo
39 39
 
40 40
 class SyncService {
41 41
 
42
-	/** @var CardDavBackend */
43
-	private $backend;
44
-
45
-	/** @var IUserManager */
46
-	private $userManager;
47
-
48
-	/** @var ILogger */
49
-	private $logger;
50
-
51
-	/** @var array */
52
-	private $localSystemAddressBook;
53
-
54
-	/** @var AccountManager */
55
-	private $accountManager;
56
-
57
-	/** @var string */
58
-	protected $certPath;
59
-
60
-	/**
61
-	 * SyncService constructor.
62
-	 *
63
-	 * @param CardDavBackend $backend
64
-	 * @param IUserManager $userManager
65
-	 * @param ILogger $logger
66
-	 * @param AccountManager $accountManager
67
-	 */
68
-	public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) {
69
-		$this->backend = $backend;
70
-		$this->userManager = $userManager;
71
-		$this->logger = $logger;
72
-		$this->accountManager = $accountManager;
73
-		$this->certPath = '';
74
-	}
75
-
76
-	/**
77
-	 * @param string $url
78
-	 * @param string $userName
79
-	 * @param string $addressBookUrl
80
-	 * @param string $sharedSecret
81
-	 * @param string $syncToken
82
-	 * @param int $targetBookId
83
-	 * @param string $targetPrincipal
84
-	 * @param array $targetProperties
85
-	 * @return string
86
-	 * @throws \Exception
87
-	 */
88
-	public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) {
89
-		// 1. create addressbook
90
-		$book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties);
91
-		$addressBookId = $book['id'];
92
-
93
-		// 2. query changes
94
-		try {
95
-			$response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken);
96
-		} catch (ClientHttpException $ex) {
97
-			if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
98
-				// remote server revoked access to the address book, remove it
99
-				$this->backend->deleteAddressBook($addressBookId);
100
-				$this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
101
-				throw $ex;
102
-			}
103
-		}
104
-
105
-		// 3. apply changes
106
-		// TODO: use multi-get for download
107
-		foreach ($response['response'] as $resource => $status) {
108
-			$cardUri = basename($resource);
109
-			if (isset($status[200])) {
110
-				$vCard = $this->download($url, $userName, $sharedSecret, $resource);
111
-				$existingCard = $this->backend->getCard($addressBookId, $cardUri);
112
-				if ($existingCard === false) {
113
-					$this->backend->createCard($addressBookId, $cardUri, $vCard['body']);
114
-				} else {
115
-					$this->backend->updateCard($addressBookId, $cardUri, $vCard['body']);
116
-				}
117
-			} else {
118
-				$this->backend->deleteCard($addressBookId, $cardUri);
119
-			}
120
-		}
121
-
122
-		return $response['token'];
123
-	}
124
-
125
-	/**
126
-	 * @param string $principal
127
-	 * @param string $id
128
-	 * @param array $properties
129
-	 * @return array|null
130
-	 * @throws \Sabre\DAV\Exception\BadRequest
131
-	 */
132
-	public function ensureSystemAddressBookExists($principal, $id, $properties) {
133
-		$book = $this->backend->getAddressBooksByUri($principal, $id);
134
-		if (!is_null($book)) {
135
-			return $book;
136
-		}
137
-		$this->backend->createAddressBook($principal, $id, $properties);
138
-
139
-		return $this->backend->getAddressBooksByUri($principal, $id);
140
-	}
141
-
142
-	/**
143
-	 * Check if there is a valid certPath we should use
144
-	 *
145
-	 * @return string
146
-	 */
147
-	protected function getCertPath() {
148
-
149
-		// we already have a valid certPath
150
-		if ($this->certPath !== '') {
151
-			return $this->certPath;
152
-		}
153
-
154
-		/** @var ICertificateManager $certManager */
155
-		$certManager = \OC::$server->getCertificateManager(null);
156
-		$certPath = $certManager->getAbsoluteBundlePath();
157
-		if (file_exists($certPath)) {
158
-			$this->certPath = $certPath;
159
-		}
160
-
161
-		return $this->certPath;
162
-	}
163
-
164
-	/**
165
-	 * @param string $url
166
-	 * @param string $userName
167
-	 * @param string $addressBookUrl
168
-	 * @param string $sharedSecret
169
-	 * @return Client
170
-	 */
171
-	protected function getClient($url, $userName, $sharedSecret) {
172
-		$settings = [
173
-			'baseUri' => $url . '/',
174
-			'userName' => $userName,
175
-			'password' => $sharedSecret,
176
-		];
177
-		$client = new Client($settings);
178
-		$certPath = $this->getCertPath();
179
-		$client->setThrowExceptions(true);
180
-
181
-		if ($certPath !== '' && strpos($url, 'http://') !== 0) {
182
-			$client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
183
-		}
184
-
185
-		return $client;
186
-	}
187
-
188
-	/**
189
-	 * @param string $url
190
-	 * @param string $userName
191
-	 * @param string $addressBookUrl
192
-	 * @param string $sharedSecret
193
-	 * @param string $syncToken
194
-	 * @return array
195
-	 */
196
-	 protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) {
197
-		 $client = $this->getClient($url, $userName, $sharedSecret);
198
-
199
-		 $body = $this->buildSyncCollectionRequestBody($syncToken);
200
-
201
-		 $response = $client->request('REPORT', $addressBookUrl, $body, [
202
-			 'Content-Type' => 'application/xml'
203
-		 ]);
204
-
205
-		 return $this->parseMultiStatus($response['body']);
206
-	 }
207
-
208
-	/**
209
-	 * @param string $url
210
-	 * @param string $userName
211
-	 * @param string $sharedSecret
212
-	 * @param string $resourcePath
213
-	 * @return array
214
-	 */
215
-	protected function download($url, $userName, $sharedSecret, $resourcePath) {
216
-		$client = $this->getClient($url, $userName, $sharedSecret);
217
-		return $client->request('GET', $resourcePath);
218
-	}
219
-
220
-	/**
221
-	 * @param string|null $syncToken
222
-	 * @return string
223
-	 */
224
-	private function buildSyncCollectionRequestBody($syncToken) {
225
-
226
-		$dom = new \DOMDocument('1.0', 'UTF-8');
227
-		$dom->formatOutput = true;
228
-		$root = $dom->createElementNS('DAV:', 'd:sync-collection');
229
-		$sync = $dom->createElement('d:sync-token', $syncToken);
230
-		$prop = $dom->createElement('d:prop');
231
-		$cont = $dom->createElement('d:getcontenttype');
232
-		$etag = $dom->createElement('d:getetag');
233
-
234
-		$prop->appendChild($cont);
235
-		$prop->appendChild($etag);
236
-		$root->appendChild($sync);
237
-		$root->appendChild($prop);
238
-		$dom->appendChild($root);
239
-		return $dom->saveXML();
240
-	}
241
-
242
-	/**
243
-	 * @param string $body
244
-	 * @return array
245
-	 * @throws \Sabre\Xml\ParseException
246
-	 */
247
-	private function parseMultiStatus($body) {
248
-		$xml = new Service();
249
-
250
-		/** @var MultiStatus $multiStatus */
251
-		$multiStatus = $xml->expect('{DAV:}multistatus', $body);
252
-
253
-		$result = [];
254
-		foreach ($multiStatus->getResponses() as $response) {
255
-			$result[$response->getHref()] = $response->getResponseProperties();
256
-		}
257
-
258
-		return ['response' => $result, 'token' => $multiStatus->getSyncToken()];
259
-	}
260
-
261
-	/**
262
-	 * @param IUser $user
263
-	 */
264
-	public function updateUser(IUser $user) {
265
-		$systemAddressBook = $this->getLocalSystemAddressBook();
266
-		$addressBookId = $systemAddressBook['id'];
267
-		$converter = new Converter($this->accountManager);
268
-		$name = $user->getBackendClassName();
269
-		$userId = $user->getUID();
270
-
271
-		$cardId = "$name:$userId.vcf";
272
-		$card = $this->backend->getCard($addressBookId, $cardId);
273
-		if ($user->isEnabled()) {
274
-			if ($card === false) {
275
-				$vCard = $converter->createCardFromUser($user);
276
-				if ($vCard !== null) {
277
-					$this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
278
-				}
279
-			} else {
280
-				$vCard = $converter->createCardFromUser($user);
281
-				if (is_null($vCard)) {
282
-					$this->backend->deleteCard($addressBookId, $cardId);
283
-				} else {
284
-					$this->backend->updateCard($addressBookId, $cardId, $vCard->serialize());
285
-				}
286
-			}
287
-		} else {
288
-			$this->backend->deleteCard($addressBookId, $cardId);
289
-		}
290
-	}
291
-
292
-	/**
293
-	 * @param IUser|string $userOrCardId
294
-	 */
295
-	public function deleteUser($userOrCardId) {
296
-		$systemAddressBook = $this->getLocalSystemAddressBook();
297
-		if ($userOrCardId instanceof IUser){
298
-			$name = $userOrCardId->getBackendClassName();
299
-			$userId = $userOrCardId->getUID();
300
-
301
-			$userOrCardId = "$name:$userId.vcf";
302
-		}
303
-		$this->backend->deleteCard($systemAddressBook['id'], $userOrCardId);
304
-	}
305
-
306
-	/**
307
-	 * @return array|null
308
-	 */
309
-	public function getLocalSystemAddressBook() {
310
-		if (is_null($this->localSystemAddressBook)) {
311
-			$systemPrincipal = "principals/system/system";
312
-			$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
313
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
314
-			]);
315
-		}
316
-
317
-		return $this->localSystemAddressBook;
318
-	}
319
-
320
-	public function syncInstance(\Closure $progressCallback = null) {
321
-		$systemAddressBook = $this->getLocalSystemAddressBook();
322
-		$this->userManager->callForSeenUsers(function($user) use ($systemAddressBook, $progressCallback) {
323
-			$this->updateUser($user);
324
-			if (!is_null($progressCallback)) {
325
-				$progressCallback();
326
-			}
327
-		});
328
-
329
-		// remove no longer existing
330
-		$allCards = $this->backend->getCards($systemAddressBook['id']);
331
-		foreach($allCards as $card) {
332
-			$vCard = Reader::read($card['carddata']);
333
-			$uid = $vCard->UID->getValue();
334
-			// load backend and see if user exists
335
-			if (!$this->userManager->userExists($uid)) {
336
-				$this->deleteUser($card['uri']);
337
-			}
338
-		}
339
-	}
42
+    /** @var CardDavBackend */
43
+    private $backend;
44
+
45
+    /** @var IUserManager */
46
+    private $userManager;
47
+
48
+    /** @var ILogger */
49
+    private $logger;
50
+
51
+    /** @var array */
52
+    private $localSystemAddressBook;
53
+
54
+    /** @var AccountManager */
55
+    private $accountManager;
56
+
57
+    /** @var string */
58
+    protected $certPath;
59
+
60
+    /**
61
+     * SyncService constructor.
62
+     *
63
+     * @param CardDavBackend $backend
64
+     * @param IUserManager $userManager
65
+     * @param ILogger $logger
66
+     * @param AccountManager $accountManager
67
+     */
68
+    public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) {
69
+        $this->backend = $backend;
70
+        $this->userManager = $userManager;
71
+        $this->logger = $logger;
72
+        $this->accountManager = $accountManager;
73
+        $this->certPath = '';
74
+    }
75
+
76
+    /**
77
+     * @param string $url
78
+     * @param string $userName
79
+     * @param string $addressBookUrl
80
+     * @param string $sharedSecret
81
+     * @param string $syncToken
82
+     * @param int $targetBookId
83
+     * @param string $targetPrincipal
84
+     * @param array $targetProperties
85
+     * @return string
86
+     * @throws \Exception
87
+     */
88
+    public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) {
89
+        // 1. create addressbook
90
+        $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties);
91
+        $addressBookId = $book['id'];
92
+
93
+        // 2. query changes
94
+        try {
95
+            $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken);
96
+        } catch (ClientHttpException $ex) {
97
+            if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
98
+                // remote server revoked access to the address book, remove it
99
+                $this->backend->deleteAddressBook($addressBookId);
100
+                $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
101
+                throw $ex;
102
+            }
103
+        }
104
+
105
+        // 3. apply changes
106
+        // TODO: use multi-get for download
107
+        foreach ($response['response'] as $resource => $status) {
108
+            $cardUri = basename($resource);
109
+            if (isset($status[200])) {
110
+                $vCard = $this->download($url, $userName, $sharedSecret, $resource);
111
+                $existingCard = $this->backend->getCard($addressBookId, $cardUri);
112
+                if ($existingCard === false) {
113
+                    $this->backend->createCard($addressBookId, $cardUri, $vCard['body']);
114
+                } else {
115
+                    $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']);
116
+                }
117
+            } else {
118
+                $this->backend->deleteCard($addressBookId, $cardUri);
119
+            }
120
+        }
121
+
122
+        return $response['token'];
123
+    }
124
+
125
+    /**
126
+     * @param string $principal
127
+     * @param string $id
128
+     * @param array $properties
129
+     * @return array|null
130
+     * @throws \Sabre\DAV\Exception\BadRequest
131
+     */
132
+    public function ensureSystemAddressBookExists($principal, $id, $properties) {
133
+        $book = $this->backend->getAddressBooksByUri($principal, $id);
134
+        if (!is_null($book)) {
135
+            return $book;
136
+        }
137
+        $this->backend->createAddressBook($principal, $id, $properties);
138
+
139
+        return $this->backend->getAddressBooksByUri($principal, $id);
140
+    }
141
+
142
+    /**
143
+     * Check if there is a valid certPath we should use
144
+     *
145
+     * @return string
146
+     */
147
+    protected function getCertPath() {
148
+
149
+        // we already have a valid certPath
150
+        if ($this->certPath !== '') {
151
+            return $this->certPath;
152
+        }
153
+
154
+        /** @var ICertificateManager $certManager */
155
+        $certManager = \OC::$server->getCertificateManager(null);
156
+        $certPath = $certManager->getAbsoluteBundlePath();
157
+        if (file_exists($certPath)) {
158
+            $this->certPath = $certPath;
159
+        }
160
+
161
+        return $this->certPath;
162
+    }
163
+
164
+    /**
165
+     * @param string $url
166
+     * @param string $userName
167
+     * @param string $addressBookUrl
168
+     * @param string $sharedSecret
169
+     * @return Client
170
+     */
171
+    protected function getClient($url, $userName, $sharedSecret) {
172
+        $settings = [
173
+            'baseUri' => $url . '/',
174
+            'userName' => $userName,
175
+            'password' => $sharedSecret,
176
+        ];
177
+        $client = new Client($settings);
178
+        $certPath = $this->getCertPath();
179
+        $client->setThrowExceptions(true);
180
+
181
+        if ($certPath !== '' && strpos($url, 'http://') !== 0) {
182
+            $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
183
+        }
184
+
185
+        return $client;
186
+    }
187
+
188
+    /**
189
+     * @param string $url
190
+     * @param string $userName
191
+     * @param string $addressBookUrl
192
+     * @param string $sharedSecret
193
+     * @param string $syncToken
194
+     * @return array
195
+     */
196
+        protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) {
197
+            $client = $this->getClient($url, $userName, $sharedSecret);
198
+
199
+            $body = $this->buildSyncCollectionRequestBody($syncToken);
200
+
201
+            $response = $client->request('REPORT', $addressBookUrl, $body, [
202
+                'Content-Type' => 'application/xml'
203
+            ]);
204
+
205
+            return $this->parseMultiStatus($response['body']);
206
+        }
207
+
208
+    /**
209
+     * @param string $url
210
+     * @param string $userName
211
+     * @param string $sharedSecret
212
+     * @param string $resourcePath
213
+     * @return array
214
+     */
215
+    protected function download($url, $userName, $sharedSecret, $resourcePath) {
216
+        $client = $this->getClient($url, $userName, $sharedSecret);
217
+        return $client->request('GET', $resourcePath);
218
+    }
219
+
220
+    /**
221
+     * @param string|null $syncToken
222
+     * @return string
223
+     */
224
+    private function buildSyncCollectionRequestBody($syncToken) {
225
+
226
+        $dom = new \DOMDocument('1.0', 'UTF-8');
227
+        $dom->formatOutput = true;
228
+        $root = $dom->createElementNS('DAV:', 'd:sync-collection');
229
+        $sync = $dom->createElement('d:sync-token', $syncToken);
230
+        $prop = $dom->createElement('d:prop');
231
+        $cont = $dom->createElement('d:getcontenttype');
232
+        $etag = $dom->createElement('d:getetag');
233
+
234
+        $prop->appendChild($cont);
235
+        $prop->appendChild($etag);
236
+        $root->appendChild($sync);
237
+        $root->appendChild($prop);
238
+        $dom->appendChild($root);
239
+        return $dom->saveXML();
240
+    }
241
+
242
+    /**
243
+     * @param string $body
244
+     * @return array
245
+     * @throws \Sabre\Xml\ParseException
246
+     */
247
+    private function parseMultiStatus($body) {
248
+        $xml = new Service();
249
+
250
+        /** @var MultiStatus $multiStatus */
251
+        $multiStatus = $xml->expect('{DAV:}multistatus', $body);
252
+
253
+        $result = [];
254
+        foreach ($multiStatus->getResponses() as $response) {
255
+            $result[$response->getHref()] = $response->getResponseProperties();
256
+        }
257
+
258
+        return ['response' => $result, 'token' => $multiStatus->getSyncToken()];
259
+    }
260
+
261
+    /**
262
+     * @param IUser $user
263
+     */
264
+    public function updateUser(IUser $user) {
265
+        $systemAddressBook = $this->getLocalSystemAddressBook();
266
+        $addressBookId = $systemAddressBook['id'];
267
+        $converter = new Converter($this->accountManager);
268
+        $name = $user->getBackendClassName();
269
+        $userId = $user->getUID();
270
+
271
+        $cardId = "$name:$userId.vcf";
272
+        $card = $this->backend->getCard($addressBookId, $cardId);
273
+        if ($user->isEnabled()) {
274
+            if ($card === false) {
275
+                $vCard = $converter->createCardFromUser($user);
276
+                if ($vCard !== null) {
277
+                    $this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
278
+                }
279
+            } else {
280
+                $vCard = $converter->createCardFromUser($user);
281
+                if (is_null($vCard)) {
282
+                    $this->backend->deleteCard($addressBookId, $cardId);
283
+                } else {
284
+                    $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize());
285
+                }
286
+            }
287
+        } else {
288
+            $this->backend->deleteCard($addressBookId, $cardId);
289
+        }
290
+    }
291
+
292
+    /**
293
+     * @param IUser|string $userOrCardId
294
+     */
295
+    public function deleteUser($userOrCardId) {
296
+        $systemAddressBook = $this->getLocalSystemAddressBook();
297
+        if ($userOrCardId instanceof IUser){
298
+            $name = $userOrCardId->getBackendClassName();
299
+            $userId = $userOrCardId->getUID();
300
+
301
+            $userOrCardId = "$name:$userId.vcf";
302
+        }
303
+        $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId);
304
+    }
305
+
306
+    /**
307
+     * @return array|null
308
+     */
309
+    public function getLocalSystemAddressBook() {
310
+        if (is_null($this->localSystemAddressBook)) {
311
+            $systemPrincipal = "principals/system/system";
312
+            $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
313
+                '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
314
+            ]);
315
+        }
316
+
317
+        return $this->localSystemAddressBook;
318
+    }
319
+
320
+    public function syncInstance(\Closure $progressCallback = null) {
321
+        $systemAddressBook = $this->getLocalSystemAddressBook();
322
+        $this->userManager->callForSeenUsers(function($user) use ($systemAddressBook, $progressCallback) {
323
+            $this->updateUser($user);
324
+            if (!is_null($progressCallback)) {
325
+                $progressCallback();
326
+            }
327
+        });
328
+
329
+        // remove no longer existing
330
+        $allCards = $this->backend->getCards($systemAddressBook['id']);
331
+        foreach($allCards as $card) {
332
+            $vCard = Reader::read($card['carddata']);
333
+            $uid = $vCard->UID->getValue();
334
+            // load backend and see if user exists
335
+            if (!$this->userManager->userExists($uid)) {
336
+                $this->deleteUser($card['uri']);
337
+            }
338
+        }
339
+    }
340 340
 
341 341
 
342 342
 }
Please login to merge, or discard this patch.