Completed
Pull Request — master (#4106)
by Blizzz
15:12 queued 15s
created
apps/files_external/lib/Lib/Storage/SharePoint.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 		$this->server = $parameters['host'];
71 71
 		$this->documentLibrary = $parameters['documentLibrary'];
72 72
 
73
-		if(strpos($this->documentLibrary, '"') !== false) {
73
+		if (strpos($this->documentLibrary, '"') !== false) {
74 74
 			// they are, amongst others, not allowed and we use it in the filter
75 75
 			// cf. https://support.microsoft.com/en-us/kb/2933738
76 76
 			// TODO: verify, it talks about files and folders mostly
77 77
 			throw new \InvalidArgumentException('Illegal character in Document Library Name');
78 78
 		}
79 79
 
80
-		if(!isset($parameters['user']) || !isset($parameters['password'])) {
80
+		if (!isset($parameters['user']) || !isset($parameters['password'])) {
81 81
 			throw new \UnexpectedValueException('No user or password given');
82 82
 		}
83 83
 		$this->authUser = $parameters['user'];
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @since 6.0.0
96 96
 	 */
97 97
 	public function getId() {
98
-		return 'SharePoint::' . $this->server . '::' . $this->documentLibrary . '::' . $this->authUser;
98
+		return 'SharePoint::'.$this->server.'::'.$this->documentLibrary.'::'.$this->authUser;
99 99
 	}
100 100
 
101 101
 	/**
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		try {
137 137
 			$cacheEntry = $this->fileCache->get($serverUrl);
138 138
 			$folder = null;
139
-			if(is_array($cacheEntry) && isset($cacheEntry['instance'])) {
139
+			if (is_array($cacheEntry) && isset($cacheEntry['instance'])) {
140 140
 				$folder = $cacheEntry['instance'];
141 141
 			}
142 142
 			$this->spClient->deleteFolder($serverUrl, $folder);
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 				$items = $collection->getData();
168 168
 				foreach ($items as $item) {
169 169
 					/** @var ListItem $fields */
170
-					if(!$this->spClient->isHidden($item)) {
170
+					if (!$this->spClient->isHidden($item)) {
171 171
 						$files[] = $item->getProperty('Name');
172 172
 					}
173 173
 				}
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 			'atime' => time(),
208 208
 		];
209 209
 
210
-		if(!is_null($stat['mtime'])) {
210
+		if (!is_null($stat['mtime'])) {
211 211
 			return $stat;
212 212
 		}
213 213
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 		} catch (NotFoundException $e) {
232 232
 			return false;
233 233
 		}
234
-		if($object instanceof File) {
234
+		if ($object instanceof File) {
235 235
 			return 'file';
236
-		} else if($object instanceof Folder) {
236
+		} else if ($object instanceof Folder) {
237 237
 			return 'dir';
238 238
 		} else {
239 239
 			return false;
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	 * @param array $parameters
341 341
 	 */
342 342
 	private function fixDI(array $parameters) {
343
-		if(isset($parameters['contextFactory'])
343
+		if (isset($parameters['contextFactory'])
344 344
 			&& $parameters['contextFactory'] instanceof ContextsFactory)
345 345
 		{
346 346
 			$this->contextsFactory = $parameters['contextFactory'];
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			$this->contextsFactory = new ContextsFactory();
349 349
 		}
350 350
 
351
-		if(isset($parameters['sharePointClientFactory'])
351
+		if (isset($parameters['sharePointClientFactory'])
352 352
 			&& $parameters['sharePointClientFactory'] instanceof SharePointClientFactory)
353 353
 		{
354 354
 			$spcFactory = $parameters['sharePointClientFactory'];
@@ -358,18 +358,18 @@  discard block
 block discarded – undo
358 358
 		$this->spClient = $spcFactory->getClient(
359 359
 			$this->contextsFactory,
360 360
 			$this->server,
361
-			[ 'user' => $this->authUser, 'password' => $this->authPwd],
361
+			['user' => $this->authUser, 'password' => $this->authPwd],
362 362
 			$this->documentLibrary
363 363
 		);
364 364
 
365
-		if(isset($parameters['cappedMemoryCache'])) {
365
+		if (isset($parameters['cappedMemoryCache'])) {
366 366
 			$this->fileCache = $parameters['cappedMemoryCache'];
367 367
 		} else {
368 368
 			// there's no API to get such
369 369
 			$this->fileCache = new CappedMemoryCache();
370 370
 		}
371 371
 
372
-		if(isset($parameters['tempManager'])) {
372
+		if (isset($parameters['tempManager'])) {
373 373
 			$this->tempManager = $parameters['tempManager'];
374 374
 		} else {
375 375
 			$this->tempManager = \OC::$server->getTempManager();
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	 */
383 383
 	private function getFolderContents($serverUrl) {
384 384
 		$entry = $this->fileCache->get($serverUrl);
385
-		if($entry === null || !isset($entry['children'])) {
385
+		if ($entry === null || !isset($entry['children'])) {
386 386
 			$folder = isset($entry['instance']) ? $entry['instance'] : null;
387 387
 			$contents = $this->spClient->fetchFolderContents($serverUrl, null, $folder);
388 388
 			$cacheItem = $entry ?: [];
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 					$url = $item->getProperty(self::SP_PROPERTY_URL);
397 397
 					$itemEntry = $this->fileCache->get($url);
398 398
 					$itemEntry = $itemEntry ?: [];
399
-					if(!isset($itemEntry['instance'])) {
399
+					if (!isset($itemEntry['instance'])) {
400 400
 						$itemEntry['instance'] = $item;
401 401
 						$this->fileCache->set($url, $itemEntry);
402 402
 					}
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
 	 */
416 416
 	private function getFileOrFolder($serverUrl) {
417 417
 		$entry = $this->fileCache->get($serverUrl);
418
-		if($entry === false) {
418
+		if ($entry === false) {
419 419
 			throw new NotFoundException('File or Folder not found');
420
-		} else if($entry === null || !isset($entry['instance'])) {
420
+		} else if ($entry === null || !isset($entry['instance'])) {
421 421
 			try {
422 422
 				$file = $this->spClient->fetchFileOrFolder($serverUrl, [self::SP_PROPERTY_SIZE, self::SP_PROPERTY_MTIME]);
423 423
 			} catch (NotFoundException $e) {
@@ -441,14 +441,14 @@  discard block
 block discarded – undo
441 441
 	 */
442 442
 	private function formatPath($path) {
443 443
 		$path = trim($path, '/');
444
-		$serverUrl = '/' . $this->documentLibrary;
445
-		if($path !== '') {
446
-			$serverUrl .= '/' . $path;
444
+		$serverUrl = '/'.$this->documentLibrary;
445
+		if ($path !== '') {
446
+			$serverUrl .= '/'.$path;
447 447
 		}
448 448
 
449 449
 		$pathParts = explode('/', $serverUrl);
450 450
 		$filename = array_pop($pathParts);
451
-		if($filename === '.') {
451
+		if ($filename === '.') {
452 452
 			// remove /. from the end of the path
453 453
 			$serverUrl = mb_substr($serverUrl, 0, mb_strlen($serverUrl) - 2);
454 454
 		}
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/SharePoint/SharePointClient.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	 * @throws \Exception
69 69
 	 */
70 70
 	public function fetchFileOrFolder($path, array $properties = null) {
71
-		$fetchFileFunc = function ($path, $props) { return $this->fetchFile($path, $props);};
72
-		$fetchFolderFunc = function ($path, $props) { return $this->fetchFolder($path, $props);};
73
-		$fetchers = [ $fetchFileFunc, $fetchFolderFunc ];
74
-		if(strpos($path, '.') === false) {
71
+		$fetchFileFunc = function($path, $props) { return $this->fetchFile($path, $props); };
72
+		$fetchFolderFunc = function($path, $props) { return $this->fetchFolder($path, $props); };
73
+		$fetchers = [$fetchFileFunc, $fetchFolderFunc];
74
+		if (strpos($path, '.') === false) {
75 75
 			$fetchers = array_reverse($fetchers);
76 76
 		}
77 77
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 				$instance = call_user_func_array($fetchFunction, [$path, $properties]);
81 81
 				return $instance;
82 82
 			} catch (\Exception $e) {
83
-				if(preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1
83
+				if (preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1
84 84
 					&& $e->getMessage() !== 'Unknown Error'
85 85
 					&& $e->getMessage() !== 'File Not Found.'
86 86
 				) {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 
123 123
 		$serverUrlParts = explode('/', $relativeServerPath);
124 124
 		$newFolderName = array_pop($serverUrlParts);
125
-		$parentUrl =  implode('/', $serverUrlParts);
125
+		$parentUrl = implode('/', $serverUrlParts);
126 126
 
127 127
 		$parentFolder = $this->context->getWeb()->getFolderByServerRelativeUrl($parentUrl);
128 128
 		$folder = $parentFolder->getFolders()->add($newFolderName);
@@ -145,18 +145,18 @@  discard block
 block discarded – undo
145 145
 	 * @throws \Exception
146 146
 	 */
147 147
 	public function getFileViaStream($relativeServerPath, $fp) {
148
-		if(!is_resource($fp)) {
148
+		if (!is_resource($fp)) {
149 149
 			throw new \InvalidArgumentException('file resource expected');
150 150
 		}
151 151
 		$relativeServerPath = rawurlencode($relativeServerPath);
152
-		$url = $this->context->getServiceRootUrl() .
152
+		$url = $this->context->getServiceRootUrl().
153 153
 			"web/getfilebyserverrelativeurl('$relativeServerPath')/\$value";
154 154
 		$options = new RequestOptions($url);
155 155
 		$options->addCurlOption(CURLOPT_FILE, $fp);
156 156
 
157 157
 		try {
158 158
 			$ok = $this->context->executeQueryDirect($options);
159
-		} catch(\Exception $e) {
159
+		} catch (\Exception $e) {
160 160
 			$this->createClientContext();
161 161
 			throw $e;
162 162
 		}
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 		$this->ensureConnection();
178 178
 
179 179
 		try {
180
-			if($folder === null) {
180
+			if ($folder === null) {
181 181
 				$folder = $this->context->getWeb()->getFolderByServerRelativeUrl($relativeServerPath);
182 182
 			}
183 183
 			$folder->deleteObject();
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 */
197 197
 	public function fetchFolderContents($relativeServerPath, $properties = null, Folder $folder = null) {
198 198
 		$this->ensureConnection();
199
-		if($folder === null) {
199
+		if ($folder === null) {
200 200
 			$folder = $this->context->getWeb()->getFolderByServerRelativeUrl($relativeServerPath);
201 201
 		}
202 202
 
@@ -214,20 +214,20 @@  discard block
 block discarded – undo
214 214
 	public function isHidden(ClientObject $file) {
215 215
 		// ClientObject itself does not have getListItemAllFields but is
216 216
 		// the common denominator of File and Folder
217
-		if(!$file instanceof File && !$file instanceof Folder) {
217
+		if (!$file instanceof File && !$file instanceof Folder) {
218 218
 			throw new \InvalidArgumentException('File or Folder expected');
219 219
 		}
220
-		if($file instanceof File) {
220
+		if ($file instanceof File) {
221 221
 			// it's expensive, we only check folders
222 222
 			return false;
223 223
 		}
224 224
 		$fields = $file->getListItemAllFields();
225
-		if($fields->getProperties() === []) {
225
+		if ($fields->getProperties() === []) {
226 226
 			$this->loadAndExecute($fields, ['Id', 'Hidden']);
227 227
 		}
228 228
 		$id = $fields->getProperty('Id');
229 229
 		$hidden = $fields->getProperty('Hidden'); // TODO: get someone to test this in SP 2013
230
-		if($hidden === false || $id !== null) {
230
+		if ($hidden === false || $id !== null) {
231 231
 			// avoids listing hidden "Forms" folder (and its contents).
232 232
 			// Have not found a different mechanism to detect whether
233 233
 			// a file or folder is hidden. There used to be a Hidden
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
 	 * @throws NotFoundException
248 248
 	 */
249 249
 	private function getDocumentLibrary() {
250
-		if(!is_null($this->documentLibrary)) {
250
+		if (!is_null($this->documentLibrary)) {
251 251
 			return $this->documentLibrary;
252 252
 		}
253 253
 
254
-		$lists = $this->context->getWeb()->getLists()->filter('Title eq \'' . $this->documentLibraryTitle . '\'')->top(1);
254
+		$lists = $this->context->getWeb()->getLists()->filter('Title eq \''.$this->documentLibraryTitle.'\'')->top(1);
255 255
 		$this->context->load($lists)->executeQuery();
256 256
 		if ($lists->getCount() === 1 && $lists->getData()[0] instanceof SPList) {
257 257
 			$this->documentLibrary = $lists->getData()[0];
@@ -267,18 +267,18 @@  discard block
 block discarded – undo
267 267
 	 * @throws \InvalidArgumentException
268 268
 	 */
269 269
 	private function ensureConnection() {
270
-		if($this->context instanceof ClientContext) {
270
+		if ($this->context instanceof ClientContext) {
271 271
 			return;
272 272
 		}
273 273
 
274
-		if(!is_string($this->credentials['user']) || empty($this->credentials['user'])) {
274
+		if (!is_string($this->credentials['user']) || empty($this->credentials['user'])) {
275 275
 			throw new \InvalidArgumentException('No user given');
276 276
 		}
277
-		if(!is_string($this->credentials['password']) || empty($this->credentials['password'])) {
277
+		if (!is_string($this->credentials['password']) || empty($this->credentials['password'])) {
278 278
 			throw new \InvalidArgumentException('No password given');
279 279
 		}
280 280
 		$this->authContext = $this->contextsFactory->getAuthContext($this->credentials['user'], $this->credentials['password']);
281
-		$this->authContext->AuthType = CURLAUTH_NTLM;		# Basic auth does not work somehow…
281
+		$this->authContext->AuthType = CURLAUTH_NTLM; # Basic auth does not work somehow…
282 282
 		$this->createClientContext();
283 283
 		# Auth is not triggered yet. This will happen when something is requested from SharePoint (on demand), e.g.:
284 284
 	}
Please login to merge, or discard this patch.