Completed
Pull Request — master (#4106)
by Blizzz
12:50
created
apps/files_external/lib/Lib/Storage/SharePoint.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 		$this->server = $parameters['host'];
67 67
 		$this->documentLibrary = $parameters['documentLibrary'];
68 68
 
69
-		if(strpos($this->documentLibrary, '"') !== false) {
69
+		if (strpos($this->documentLibrary, '"') !== false) {
70 70
 			// they are, amongst others, not allowed and we use it in the filter
71 71
 			// cf. https://support.microsoft.com/en-us/kb/2933738
72 72
 			// TODO: verify, it talks about files and folders mostly
73 73
 			throw new \InvalidArgumentException('Illegal character in Document Library Name');
74 74
 		}
75 75
 
76
-		if(!isset($parameters['user']) || !isset($parameters['password'])) {
76
+		if (!isset($parameters['user']) || !isset($parameters['password'])) {
77 77
 			throw new \UnexpectedValueException('No user or password given');
78 78
 		}
79 79
 		$this->authUser = $parameters['user'];
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @since 6.0.0
92 92
 	 */
93 93
 	public function getId() {
94
-		return 'SharePoint::' . $this->server . '::' . $this->documentLibrary . '::' . $this->authUser;
94
+		return 'SharePoint::'.$this->server.'::'.$this->documentLibrary.'::'.$this->authUser;
95 95
 	}
96 96
 
97 97
 	/**
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		try {
133 133
 			$cacheEntry = $this->fileCache->get($serverUrl);
134 134
 			$folder = null;
135
-			if(is_array($cacheEntry) && isset($cacheEntry['instance'])) {
135
+			if (is_array($cacheEntry) && isset($cacheEntry['instance'])) {
136 136
 				$folder = $cacheEntry['instance'];
137 137
 			}
138 138
 			$this->spClient->deleteFolder($serverUrl, $folder);
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 				$items = $collection->getData();
164 164
 				foreach ($items as $item) {
165 165
 					/** @var ListItem $fields */
166
-					if(!$this->spClient->isHidden($item)) {
166
+					if (!$this->spClient->isHidden($item)) {
167 167
 						$files[] = $item->getProperty('Name');
168 168
 					}
169 169
 				}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 			'atime' => time(),
204 204
 		];
205 205
 
206
-		if(!is_null($stat['mtime'])) {
206
+		if (!is_null($stat['mtime'])) {
207 207
 			return $stat;
208 208
 		}
209 209
 
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 		} catch (NotFoundException $e) {
228 228
 			return false;
229 229
 		}
230
-		if($object instanceof File) {
230
+		if ($object instanceof File) {
231 231
 			return 'file';
232
-		} else if($object instanceof Folder) {
232
+		} else if ($object instanceof Folder) {
233 233
 			return 'dir';
234 234
 		} else {
235 235
 			return false;
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
 	public function unlink($path) {
268 268
 		//  FIXME:: all is totally wrong
269 269
 		$path = trim($path);
270
-		if($path === '/' || $path === '') {
270
+		if ($path === '/' || $path === '') {
271 271
 			return false;
272 272
 		}
273
-		foreach([true, false] as $asFile) {
273
+		foreach ([true, false] as $asFile) {
274 274
 			try {
275 275
 				$fsObject = $this->spClient->fetchFileOrFolder($path, $asFile);
276 276
 				$fsObject->deleteObject();
277 277
 				return true;
278
-			} catch(\Exception $e) {
278
+			} catch (\Exception $e) {
279 279
 				// NOOP
280 280
 			}
281 281
 		}
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 	 * @param array $parameters
317 317
 	 */
318 318
 	private function fixDI(array $parameters) {
319
-		if(isset($parameters['contextFactory'])
319
+		if (isset($parameters['contextFactory'])
320 320
 			&& $parameters['contextFactory'] instanceof ContextsFactory)
321 321
 		{
322 322
 			$this->contextsFactory = $parameters['contextFactory'];
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 			$this->contextsFactory = new ContextsFactory();
325 325
 		}
326 326
 
327
-		if(isset($parameters['sharePointClientFactory'])
327
+		if (isset($parameters['sharePointClientFactory'])
328 328
 			&& $parameters['sharePointClientFactory'] instanceof SharePointClientFactory)
329 329
 		{
330 330
 			$spcFactory = $parameters['sharePointClientFactory'];
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
 		$this->spClient = $spcFactory->getClient(
335 335
 			$this->contextsFactory,
336 336
 			$this->server,
337
-			[ 'user' => $this->authUser, 'password' => $this->authPwd],
337
+			['user' => $this->authUser, 'password' => $this->authPwd],
338 338
 			$this->documentLibrary
339 339
 		);
340 340
 
341
-		if(isset($parameters['cappedMemoryCache'])) {
341
+		if (isset($parameters['cappedMemoryCache'])) {
342 342
 			$this->fileCache = $parameters['cappedMemoryCache'];
343 343
 		} else {
344 344
 			$this->fileCache = new CappedMemoryCache('256');
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	 */
352 352
 	private function getFolderContents($serverUrl) {
353 353
 		$entry = $this->fileCache->get($serverUrl);
354
-		if($entry === null || !isset($entry['children'])) {
354
+		if ($entry === null || !isset($entry['children'])) {
355 355
 			$folder = isset($entry['instance']) ? $entry['instance'] : null;
356 356
 			$contents = $this->spClient->fetchFolderContents($serverUrl, null, $folder);
357 357
 			$cacheItem = $entry ?: [];
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 					$url = $item->getProperty(self::SP_PROPERTY_URL);
366 366
 					$itemEntry = $this->fileCache->get($url);
367 367
 					$itemEntry = $itemEntry ?: [];
368
-					if(!isset($itemEntry['instance'])) {
368
+					if (!isset($itemEntry['instance'])) {
369 369
 						$itemEntry['instance'] = $item;
370 370
 						$this->fileCache->set($url, $itemEntry);
371 371
 					}
@@ -384,9 +384,9 @@  discard block
 block discarded – undo
384 384
 	 */
385 385
 	private function getFileOrFolder($serverUrl) {
386 386
 		$entry = $this->fileCache->get($serverUrl);
387
-		if($entry === false) {
387
+		if ($entry === false) {
388 388
 			throw new NotFoundException('File or Folder not found');
389
-		} else if($entry === null || !isset($entry['instance'])) {
389
+		} else if ($entry === null || !isset($entry['instance'])) {
390 390
 			try {
391 391
 				$file = $this->spClient->fetchFileOrFolder($serverUrl, [self::SP_PROPERTY_SIZE, self::SP_PROPERTY_MTIME]);
392 392
 			} catch (NotFoundException $e) {
@@ -410,14 +410,14 @@  discard block
 block discarded – undo
410 410
 	 */
411 411
 	private function formatPath($path) {
412 412
 		$path = trim($path, '/');
413
-		$serverUrl = '/' . $this->documentLibrary;
414
-		if($path !== '') {
415
-			$serverUrl .= '/' . $path;
413
+		$serverUrl = '/'.$this->documentLibrary;
414
+		if ($path !== '') {
415
+			$serverUrl .= '/'.$path;
416 416
 		}
417 417
 
418 418
 		$pathParts = explode('/', $serverUrl);
419 419
 		$filename = array_pop($pathParts);
420
-		if($filename === '.') {
420
+		if ($filename === '.') {
421 421
 			// remove /. from the end of the path
422 422
 			$serverUrl = mb_substr($serverUrl, 0, mb_strlen($serverUrl) - 2);
423 423
 		}
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/SharePoint/SharePointClient.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 	 * @throws \Exception
68 68
 	 */
69 69
 	public function fetchFileOrFolder($path, array $properties = null) {
70
-		$fetchFileFunc = function ($path, $props) { return $this->fetchFile($path, $props);};
71
-		$fetchFolderFunc = function ($path, $props) { return $this->fetchFolder($path, $props);};
72
-		$fetchers = [ $fetchFileFunc, $fetchFolderFunc ];
73
-		if(strpos($path, '.') === false) {
70
+		$fetchFileFunc = function($path, $props) { return $this->fetchFile($path, $props); };
71
+		$fetchFolderFunc = function($path, $props) { return $this->fetchFolder($path, $props); };
72
+		$fetchers = [$fetchFileFunc, $fetchFolderFunc];
73
+		if (strpos($path, '.') === false) {
74 74
 			$fetchers = array_reverse($fetchers);
75 75
 		}
76 76
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 				$instance = call_user_func_array($fetchFunction, [$path, $properties]);
80 80
 				return $instance;
81 81
 			} catch (\Exception $e) {
82
-				if(preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1
82
+				if (preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1
83 83
 					&& $e->getMessage() !== 'Unknown Error'
84 84
 					&& $e->getMessage() !== 'File Not Found.'
85 85
 				) {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 		$serverUrlParts = explode('/', $relativeServerPath);
122 122
 		$newFolderName = array_pop($serverUrlParts);
123
-		$parentUrl =  implode('/', $serverUrlParts);
123
+		$parentUrl = implode('/', $serverUrlParts);
124 124
 
125 125
 		$parentFolder = $this->context->getWeb()->getFolderByServerRelativeUrl($parentUrl);
126 126
 		$folder = $parentFolder->getFolders()->add($newFolderName);
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 		$this->ensureConnection();
139 139
 
140 140
 		try {
141
-			if($folder === null) {
141
+			if ($folder === null) {
142 142
 				$folder = $this->context->getWeb()->getFolderByServerRelativeUrl($relativeServerPath);
143 143
 			}
144 144
 			$folder->deleteObject();
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 */
158 158
 	public function fetchFolderContents($relativeServerPath, $properties = null, Folder $folder = null) {
159 159
 		$this->ensureConnection();
160
-		if($folder === null) {
160
+		if ($folder === null) {
161 161
 			$folder = $this->context->getWeb()->getFolderByServerRelativeUrl($relativeServerPath);
162 162
 		}
163 163
 
@@ -175,20 +175,20 @@  discard block
 block discarded – undo
175 175
 	public function isHidden(ClientObject $file) {
176 176
 		// ClientObject itself does not have getListItemAllFields but is
177 177
 		// the common denominator of File and Folder
178
-		if(!$file instanceof File && !$file instanceof Folder) {
178
+		if (!$file instanceof File && !$file instanceof Folder) {
179 179
 			throw new \InvalidArgumentException('File or Folder expected');
180 180
 		}
181
-		if($file instanceof File) {
181
+		if ($file instanceof File) {
182 182
 			// it's expensive, we only check folders
183 183
 			return false;
184 184
 		}
185 185
 		$fields = $file->getListItemAllFields();
186
-		if($fields->getProperties() === []) {
186
+		if ($fields->getProperties() === []) {
187 187
 			$this->loadAndExecute($fields, ['Id', 'Hidden']);
188 188
 		}
189 189
 		$id = $fields->getProperty('Id');
190 190
 		$hidden = $fields->getProperty('Hidden'); // TODO: get someone to test this in SP 2013
191
-		if($hidden === false || $id !== null) {
191
+		if ($hidden === false || $id !== null) {
192 192
 			// avoids listing hidden "Forms" folder (and its contents).
193 193
 			// Have not found a different mechanism to detect whether
194 194
 			// a file or folder is hidden. There used to be a Hidden
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 	 * @throws NotFoundException
209 209
 	 */
210 210
 	private function getDocumentLibrary() {
211
-		if(!is_null($this->documentLibrary)) {
211
+		if (!is_null($this->documentLibrary)) {
212 212
 			return $this->documentLibrary;
213 213
 		}
214 214
 
215
-		$lists = $this->context->getWeb()->getLists()->filter('Title eq \'' . $this->documentLibraryTitle . '\'')->top(1);
215
+		$lists = $this->context->getWeb()->getLists()->filter('Title eq \''.$this->documentLibraryTitle.'\'')->top(1);
216 216
 		$this->context->load($lists)->executeQuery();
217 217
 		if ($lists->getCount() === 1 && $lists->getData()[0] instanceof SPList) {
218 218
 			$this->documentLibrary = $lists->getData()[0];
@@ -228,18 +228,18 @@  discard block
 block discarded – undo
228 228
 	 * @throws \InvalidArgumentException
229 229
 	 */
230 230
 	private function ensureConnection() {
231
-		if($this->context instanceof ClientContext) {
231
+		if ($this->context instanceof ClientContext) {
232 232
 			return;
233 233
 		}
234 234
 
235
-		if(!is_string($this->credentials['user']) || empty($this->credentials['user'])) {
235
+		if (!is_string($this->credentials['user']) || empty($this->credentials['user'])) {
236 236
 			throw new \InvalidArgumentException('No user given');
237 237
 		}
238
-		if(!is_string($this->credentials['password']) || empty($this->credentials['password'])) {
238
+		if (!is_string($this->credentials['password']) || empty($this->credentials['password'])) {
239 239
 			throw new \InvalidArgumentException('No password given');
240 240
 		}
241 241
 		$this->authContext = $this->contextsFactory->getAuthContext($this->credentials['user'], $this->credentials['password']);
242
-		$this->authContext->AuthType = CURLAUTH_NTLM;		# Basic auth does not work somehow…
242
+		$this->authContext->AuthType = CURLAUTH_NTLM; # Basic auth does not work somehow…
243 243
 		$this->createClientContext();
244 244
 		# Auth is not triggered yet. This will happen when something is requested from SharePoint (on demand), e.g.:
245 245
 	}
Please login to merge, or discard this patch.