|
34 | 34 | use OCP\Files\Lock\ILock; |
35 | 35 | use OCP\Files\Lock\ILockManager; |
36 | 36 | use OCP\Files\Lock\LockScope; |
| 37 | +use OCP\Files\Lock\NoLockProviderException; |
| 38 | +use OCP\Files\Lock\OwnerLockedException; |
37 | 39 | use OCP\IRequest; |
38 | 40 | use OCP\Lock\ILockingProvider; |
| 41 | +use OCP\PreConditionNotMetException; |
39 | 42 | use function json_encode; |
40 | 43 | use OC\Files\Node\File; |
41 | 44 | use OCA\Text\Db\Document; |
@@ -477,29 +480,40 @@ private function ensureDocumentsFolder(): bool { |
477 | 480 | return true; |
478 | 481 | } |
479 | 482 |
|
480 | | - public function lock(int $fileId) { |
| 483 | + public function lock(int $fileId): bool { |
481 | 484 | if (!$this->lockManager->isLockProviderAvailable()) { |
482 | | - return; |
| 485 | + return true; |
483 | 486 | } |
484 | 487 |
|
485 | 488 | $file = $this->getFileById($fileId); |
486 | | - $this->lockManager->lock(new LockScope( |
487 | | - $file, |
488 | | - ILock::TYPE_APP, |
489 | | - Application::APP_NAME |
490 | | - )); |
| 489 | + try { |
| 490 | + $this->lockManager->lock(new LockScope( |
| 491 | + $file, |
| 492 | + ILock::TYPE_APP, |
| 493 | + Application::APP_NAME |
| 494 | + )); |
| 495 | + } catch (NoLockProviderException $e) { |
| 496 | + } catch (OwnerLockedException $e) { |
| 497 | + return false; |
| 498 | + } catch (PreConditionNotMetException $e) { |
| 499 | + } |
| 500 | + return true; |
491 | 501 | } |
492 | 502 |
|
493 | | - public function unlock(int $fileId) { |
| 503 | + public function unlock(int $fileId): void { |
494 | 504 | if (!$this->lockManager->isLockProviderAvailable()) { |
495 | 505 | return; |
496 | 506 | } |
497 | 507 |
|
498 | 508 | $file = $this->getFileById($fileId); |
499 | | - $this->lockManager->unlock(new LockScope( |
500 | | - $file, |
501 | | - ILock::TYPE_APP, |
502 | | - Application::APP_NAME |
503 | | - )); |
| 509 | + try { |
| 510 | + $this->lockManager->unlock(new LockScope( |
| 511 | + $file, |
| 512 | + ILock::TYPE_APP, |
| 513 | + Application::APP_NAME |
| 514 | + )); |
| 515 | + } catch (NoLockProviderException $e) { |
| 516 | + } catch (PreConditionNotMetException $e) { |
| 517 | + } |
504 | 518 | } |
505 | 519 | } |
0 commit comments