@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | $this->server = $parameters['host']; |
72 | 72 | $this->documentLibrary = $parameters['documentLibrary']; |
73 | 73 | |
74 | - if(strpos($this->documentLibrary, '"') !== false) { |
|
74 | + if (strpos($this->documentLibrary, '"') !== false) { |
|
75 | 75 | // they are, amongst others, not allowed and we use it in the filter |
76 | 76 | // cf. https://support.microsoft.com/en-us/kb/2933738 |
77 | 77 | // TODO: verify, it talks about files and folders mostly |
78 | 78 | throw new \InvalidArgumentException('Illegal character in Document Library Name'); |
79 | 79 | } |
80 | 80 | |
81 | - if(!isset($parameters['user']) || !isset($parameters['password'])) { |
|
81 | + if (!isset($parameters['user']) || !isset($parameters['password'])) { |
|
82 | 82 | throw new \UnexpectedValueException('No user or password given'); |
83 | 83 | } |
84 | 84 | $this->authUser = $parameters['user']; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @since 6.0.0 |
97 | 97 | */ |
98 | 98 | public function getId() { |
99 | - return 'SharePoint::' . $this->server . '::' . $this->documentLibrary . '::' . $this->authUser; |
|
99 | + return 'SharePoint::'.$this->server.'::'.$this->documentLibrary.'::'.$this->authUser; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $items = $collection->getData(); |
165 | 165 | foreach ($items as $item) { |
166 | 166 | /** @var ListItem $fields */ |
167 | - if(!$this->spClient->isHidden($item)) { |
|
167 | + if (!$this->spClient->isHidden($item)) { |
|
168 | 168 | $files[] = $item->getProperty('Name'); |
169 | 169 | } |
170 | 170 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | 'atime' => time(), |
205 | 205 | ]; |
206 | 206 | |
207 | - if(!is_null($stat['mtime'])) { |
|
207 | + if (!is_null($stat['mtime'])) { |
|
208 | 208 | return $stat; |
209 | 209 | } |
210 | 210 | |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | } catch (NotFoundException $e) { |
229 | 229 | return false; |
230 | 230 | } |
231 | - if($object instanceof File) { |
|
231 | + if ($object instanceof File) { |
|
232 | 232 | return 'file'; |
233 | - } else if($object instanceof Folder) { |
|
233 | + } else if ($object instanceof Folder) { |
|
234 | 234 | return 'dir'; |
235 | 235 | } else { |
236 | 236 | return false; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function unlink($path) { |
269 | 269 | // file methods get called twice at least, returning true |
270 | - if(!$this->file_exists($path)) { |
|
270 | + if (!$this->file_exists($path)) { |
|
271 | 271 | return true; |
272 | 272 | } |
273 | 273 | try { |
@@ -288,16 +288,16 @@ discard block |
||
288 | 288 | $item = $this->getFileOrFolder($newPath); |
289 | 289 | $this->spClient->delete($item); |
290 | 290 | $this->fileCache->remove($newPath); |
291 | - } catch(NotFoundException $e) { |
|
291 | + } catch (NotFoundException $e) { |
|
292 | 292 | // noop |
293 | 293 | } |
294 | 294 | |
295 | 295 | try { |
296 | 296 | $isRenamed = $this->spClient->rename($oldPath, $newPath); |
297 | - if($isRenamed) { |
|
297 | + if ($isRenamed) { |
|
298 | 298 | $entry = $this->fileCache->get($oldPath); |
299 | 299 | $this->fileCache->remove($newPath); |
300 | - if($entry !== false) { |
|
300 | + if ($entry !== false) { |
|
301 | 301 | $this->fileCache->set($newPath, $entry); |
302 | 302 | } |
303 | 303 | $this->fileCache->remove($oldPath); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $tmpFile = $this->tempManager->getTemporaryFile(); |
331 | 331 | |
332 | 332 | $fp = fopen($tmpFile, 'w+'); |
333 | - if(!$this->spClient->getFileViaStream($serverUrl, $fp)) { |
|
333 | + if (!$this->spClient->getFileViaStream($serverUrl, $fp)) { |
|
334 | 334 | fclose($fp); |
335 | 335 | return false; |
336 | 336 | } |
@@ -360,20 +360,20 @@ discard block |
||
360 | 360 | case 'cb+': |
361 | 361 | case 'c+b': |
362 | 362 | //fseek 0 |
363 | - if($mode[0] === 'x' && $this->file_exists($path)) { |
|
363 | + if ($mode[0] === 'x' && $this->file_exists($path)) { |
|
364 | 364 | return false; |
365 | 365 | } |
366 | 366 | $tmpFile = $this->tempManager->getTemporaryFile(); |
367 | - if($mode[0] !== 'w' && $this->file_exists($path)) { |
|
367 | + if ($mode[0] !== 'w' && $this->file_exists($path)) { |
|
368 | 368 | $content = $this->fopen($path, 'r'); |
369 | - if($content === false) { |
|
369 | + if ($content === false) { |
|
370 | 370 | // should not happen, but let's be safe |
371 | 371 | return false; |
372 | 372 | } |
373 | 373 | $this->file_put_contents($tmpFile, $content); |
374 | 374 | } |
375 | 375 | $fp = fopen($tmpFile, $mode); |
376 | - return CallbackWrapper::wrap($fp, null, null, function () use ($path, $tmpFile) { |
|
376 | + return CallbackWrapper::wrap($fp, null, null, function() use ($path, $tmpFile) { |
|
377 | 377 | $this->writeBack($tmpFile, $path); |
378 | 378 | }); |
379 | 379 | |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * @param array $parameters |
422 | 422 | */ |
423 | 423 | private function fixDI(array $parameters) { |
424 | - if(isset($parameters['contextFactory']) |
|
424 | + if (isset($parameters['contextFactory']) |
|
425 | 425 | && $parameters['contextFactory'] instanceof ContextsFactory) |
426 | 426 | { |
427 | 427 | $this->contextsFactory = $parameters['contextFactory']; |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | $this->contextsFactory = new ContextsFactory(); |
430 | 430 | } |
431 | 431 | |
432 | - if(isset($parameters['sharePointClientFactory']) |
|
432 | + if (isset($parameters['sharePointClientFactory']) |
|
433 | 433 | && $parameters['sharePointClientFactory'] instanceof SharePointClientFactory) |
434 | 434 | { |
435 | 435 | $spcFactory = $parameters['sharePointClientFactory']; |
@@ -439,18 +439,18 @@ discard block |
||
439 | 439 | $this->spClient = $spcFactory->getClient( |
440 | 440 | $this->contextsFactory, |
441 | 441 | $this->server, |
442 | - [ 'user' => $this->authUser, 'password' => $this->authPwd], |
|
442 | + ['user' => $this->authUser, 'password' => $this->authPwd], |
|
443 | 443 | $this->documentLibrary |
444 | 444 | ); |
445 | 445 | |
446 | - if(isset($parameters['cappedMemoryCache'])) { |
|
446 | + if (isset($parameters['cappedMemoryCache'])) { |
|
447 | 447 | $this->fileCache = $parameters['cappedMemoryCache']; |
448 | 448 | } else { |
449 | 449 | // there's no API to get such |
450 | 450 | $this->fileCache = new CappedMemoryCache(); |
451 | 451 | } |
452 | 452 | |
453 | - if(isset($parameters['tempManager'])) { |
|
453 | + if (isset($parameters['tempManager'])) { |
|
454 | 454 | $this->tempManager = $parameters['tempManager']; |
455 | 455 | } else { |
456 | 456 | $this->tempManager = \OC::$server->getTempManager(); |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | */ |
464 | 464 | private function getFolderContents($serverUrl) { |
465 | 465 | $entry = $this->fileCache->get($serverUrl); |
466 | - if($entry === null || !isset($entry['children'])) { |
|
466 | + if ($entry === null || !isset($entry['children'])) { |
|
467 | 467 | $folder = isset($entry['instance']) ? $entry['instance'] : null; |
468 | 468 | $contents = $this->spClient->fetchFolderContents($serverUrl, null, $folder); |
469 | 469 | $cacheItem = $entry ?: []; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $url = $item->getProperty(self::SP_PROPERTY_URL); |
478 | 478 | $itemEntry = $this->fileCache->get($url); |
479 | 479 | $itemEntry = $itemEntry ?: []; |
480 | - if(!isset($itemEntry['instance'])) { |
|
480 | + if (!isset($itemEntry['instance'])) { |
|
481 | 481 | $itemEntry['instance'] = $item; |
482 | 482 | $this->fileCache->set($url, $itemEntry); |
483 | 483 | } |
@@ -496,9 +496,9 @@ discard block |
||
496 | 496 | */ |
497 | 497 | private function getFileOrFolder($serverUrl) { |
498 | 498 | $entry = $this->fileCache->get($serverUrl); |
499 | - if($entry === false) { |
|
499 | + if ($entry === false) { |
|
500 | 500 | throw new NotFoundException('File or Folder not found'); |
501 | - } else if($entry === null || !isset($entry['instance'])) { |
|
501 | + } else if ($entry === null || !isset($entry['instance'])) { |
|
502 | 502 | try { |
503 | 503 | $file = $this->spClient->fetchFileOrFolder($serverUrl, [self::SP_PROPERTY_SIZE, self::SP_PROPERTY_MTIME]); |
504 | 504 | } catch (NotFoundException $e) { |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | */ |
523 | 523 | private function formatPath($path) { |
524 | 524 | $path = trim($path, '/'); |
525 | - $serverUrl = '/' . $this->documentLibrary; |
|
526 | - if($path !== '') { |
|
527 | - $serverUrl .= '/' . $path; |
|
525 | + $serverUrl = '/'.$this->documentLibrary; |
|
526 | + if ($path !== '') { |
|
527 | + $serverUrl .= '/'.$path; |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | $pathParts = explode('/', $serverUrl); |
531 | 531 | $filename = array_pop($pathParts); |
532 | - if($filename === '.') { |
|
532 | + if ($filename === '.') { |
|
533 | 533 | // remove /. from the end of the path |
534 | 534 | $serverUrl = mb_substr($serverUrl, 0, mb_strlen($serverUrl) - 2); |
535 | 535 | } |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | * @throws \Exception |
71 | 71 | */ |
72 | 72 | public function fetchFileOrFolder($path, array $properties = null) { |
73 | - $fetchFileFunc = function ($path, $props) { return $this->fetchFile($path, $props);}; |
|
74 | - $fetchFolderFunc = function ($path, $props) { return $this->fetchFolder($path, $props);}; |
|
75 | - $fetchers = [ $fetchFileFunc, $fetchFolderFunc ]; |
|
76 | - if(strpos($path, '.') === false) { |
|
73 | + $fetchFileFunc = function($path, $props) { return $this->fetchFile($path, $props); }; |
|
74 | + $fetchFolderFunc = function($path, $props) { return $this->fetchFolder($path, $props); }; |
|
75 | + $fetchers = [$fetchFileFunc, $fetchFolderFunc]; |
|
76 | + if (strpos($path, '.') === false) { |
|
77 | 77 | $fetchers = array_reverse($fetchers); |
78 | 78 | } |
79 | 79 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $instance = call_user_func_array($fetchFunction, [$path, $properties]); |
83 | 83 | return $instance; |
84 | 84 | } catch (\Exception $e) { |
85 | - if(preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1 |
|
85 | + if (preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1 |
|
86 | 86 | && $e->getMessage() !== 'Unknown Error' |
87 | 87 | && $e->getMessage() !== 'File Not Found.' |
88 | 88 | ) { |
@@ -143,18 +143,18 @@ discard block |
||
143 | 143 | * @throws \Exception |
144 | 144 | */ |
145 | 145 | public function getFileViaStream($relativeServerPath, $fp) { |
146 | - if(!is_resource($fp)) { |
|
146 | + if (!is_resource($fp)) { |
|
147 | 147 | throw new \InvalidArgumentException('file resource expected'); |
148 | 148 | } |
149 | 149 | $relativeServerPath = rawurlencode($relativeServerPath); |
150 | - $url = $this->context->getServiceRootUrl() . |
|
150 | + $url = $this->context->getServiceRootUrl(). |
|
151 | 151 | "web/getfilebyserverrelativeurl('$relativeServerPath')/\$value"; |
152 | 152 | $options = new RequestOptions($url); |
153 | 153 | $options->StreamHandle = $fp; |
154 | 154 | |
155 | 155 | try { |
156 | 156 | $ok = $this->context->executeQueryDirect($options); |
157 | - } catch(\Exception $e) { |
|
157 | + } catch (\Exception $e) { |
|
158 | 158 | $this->resetClientContext(); |
159 | 159 | throw $e; |
160 | 160 | } |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function overwriteFileViaStream($relativeServerPath, $fp, $localPath) { |
182 | 182 | $serverRelativeUrl = rawurlencode($relativeServerPath); |
183 | - $url = $this->context->getServiceRootUrl() . "web/getfilebyserverrelativeurl('$serverRelativeUrl')/\$value"; |
|
183 | + $url = $this->context->getServiceRootUrl()."web/getfilebyserverrelativeurl('$serverRelativeUrl')/\$value"; |
|
184 | 184 | $request = new RequestOptions($url); |
185 | 185 | $request->Method = 'POST'; // yes, POST |
186 | - $request->addCustomHeader('X-HTTP-Method','PUT'); // yes, PUT |
|
186 | + $request->addCustomHeader('X-HTTP-Method', 'PUT'); // yes, PUT |
|
187 | 187 | $this->context->ensureFormDigest($request); |
188 | 188 | //FIXME: Proper StreamHandle handling is not upstream, yet |
189 | 189 | $request->StreamHandle = $fp; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | try { |
193 | 193 | $ok = $this->context->executeQueryDirect($request); |
194 | - } catch(\Exception $e) { |
|
194 | + } catch (\Exception $e) { |
|
195 | 195 | $this->resetClientContext(); |
196 | 196 | throw $e; |
197 | 197 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | try { |
220 | 220 | $this->context->executeQuery(); |
221 | 221 | return $file; |
222 | - } catch(\Exception $e) { |
|
222 | + } catch (\Exception $e) { |
|
223 | 223 | $this->resetClientContext(); |
224 | 224 | throw $e; |
225 | 225 | } |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | |
239 | 239 | try { |
240 | 240 | $item = $this->fetchFileOrFolder($oldPath); |
241 | - if($item instanceof File) { |
|
241 | + if ($item instanceof File) { |
|
242 | 242 | $this->renameFile($item, $newPath); |
243 | - } else if($item instanceof Folder) { |
|
243 | + } else if ($item instanceof Folder) { |
|
244 | 244 | $this->renameFolder($item, $newPath); |
245 | 245 | } else { |
246 | 246 | return false; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | } else if ($item instanceof Folder) { |
291 | 291 | $this->deleteFolder($item); |
292 | 292 | } |
293 | - } catch(\Exception $e) { |
|
293 | + } catch (\Exception $e) { |
|
294 | 294 | $this->resetClientContext(); |
295 | 295 | throw $e; |
296 | 296 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function fetchFolderContents($relativeServerPath, $properties = null, Folder $folder = null) { |
322 | 322 | $this->ensureConnection(); |
323 | - if($folder === null) { |
|
323 | + if ($folder === null) { |
|
324 | 324 | $folder = $this->context->getWeb()->getFolderByServerRelativeUrl($relativeServerPath); |
325 | 325 | } |
326 | 326 | |
@@ -338,20 +338,20 @@ discard block |
||
338 | 338 | public function isHidden(ClientObject $file) { |
339 | 339 | // ClientObject itself does not have getListItemAllFields but is |
340 | 340 | // the common denominator of File and Folder |
341 | - if(!$file instanceof File && !$file instanceof Folder) { |
|
341 | + if (!$file instanceof File && !$file instanceof Folder) { |
|
342 | 342 | throw new \InvalidArgumentException('File or Folder expected'); |
343 | 343 | } |
344 | - if($file instanceof File) { |
|
344 | + if ($file instanceof File) { |
|
345 | 345 | // it's expensive, we only check folders |
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | $fields = $file->getListItemAllFields(); |
349 | - if($fields->getProperties() === []) { |
|
349 | + if ($fields->getProperties() === []) { |
|
350 | 350 | $this->loadAndExecute($fields, ['Id', 'Hidden']); |
351 | 351 | } |
352 | 352 | $id = $fields->getProperty('Id'); |
353 | 353 | $hidden = $fields->getProperty('Hidden'); // TODO: get someone to test this in SP 2013 |
354 | - if($hidden === false || $id !== null) { |
|
354 | + if ($hidden === false || $id !== null) { |
|
355 | 355 | // avoids listing hidden "Forms" folder (and its contents). |
356 | 356 | // Have not found a different mechanism to detect whether |
357 | 357 | // a file or folder is hidden. There used to be a Hidden |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | * @throws NotFoundException |
372 | 372 | */ |
373 | 373 | private function getDocumentLibrary() { |
374 | - if(!is_null($this->documentLibrary)) { |
|
374 | + if (!is_null($this->documentLibrary)) { |
|
375 | 375 | return $this->documentLibrary; |
376 | 376 | } |
377 | 377 | |
378 | - $lists = $this->context->getWeb()->getLists()->filter('Title eq \'' . $this->documentLibraryTitle . '\'')->top(1); |
|
378 | + $lists = $this->context->getWeb()->getLists()->filter('Title eq \''.$this->documentLibraryTitle.'\'')->top(1); |
|
379 | 379 | $this->context->load($lists)->executeQuery(); |
380 | 380 | if ($lists->getCount() === 1 && $lists->getData()[0] instanceof SPList) { |
381 | 381 | $this->documentLibrary = $lists->getData()[0]; |
@@ -391,18 +391,18 @@ discard block |
||
391 | 391 | * @throws \InvalidArgumentException |
392 | 392 | */ |
393 | 393 | private function ensureConnection() { |
394 | - if($this->context instanceof ClientContext) { |
|
394 | + if ($this->context instanceof ClientContext) { |
|
395 | 395 | return; |
396 | 396 | } |
397 | 397 | |
398 | - if(!is_string($this->credentials['user']) || empty($this->credentials['user'])) { |
|
398 | + if (!is_string($this->credentials['user']) || empty($this->credentials['user'])) { |
|
399 | 399 | throw new \InvalidArgumentException('No user given'); |
400 | 400 | } |
401 | - if(!is_string($this->credentials['password']) || empty($this->credentials['password'])) { |
|
401 | + if (!is_string($this->credentials['password']) || empty($this->credentials['password'])) { |
|
402 | 402 | throw new \InvalidArgumentException('No password given'); |
403 | 403 | } |
404 | 404 | $this->authContext = $this->contextsFactory->getAuthContext($this->credentials['user'], $this->credentials['password']); |
405 | - $this->authContext->AuthType = CURLAUTH_NTLM; # Basic auth does not work somehow… |
|
405 | + $this->authContext->AuthType = CURLAUTH_NTLM; # Basic auth does not work somehow… |
|
406 | 406 | $this->context = $this->contextsFactory->getClientContext($this->sharePointUrl, $this->authContext); |
407 | 407 | # Auth is not triggered yet. This will happen when something is requested from SharePoint (on demand), e.g.: |
408 | 408 | } |