Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ONLYOFFICE/onlyoffice-nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntipkin-A <Artem.Antipkin@onlyoffice.com>2022-10-05 15:19:03 +0300
committerAntipkin-A <Artem.Antipkin@onlyoffice.com>2022-10-05 15:19:03 +0300
commit956528ef03cef5aae1db8c7ec60ea81fce5095f9 (patch)
treee9e00c2395e83bfe602243b0a06094bc90c75337
parent3a3117fe7eb2608757ecd9ed6b238f19e4792a1a (diff)
lock refactoring
-rw-r--r--controller/callbackcontroller.php65
1 files changed, 47 insertions, 18 deletions
diff --git a/controller/callbackcontroller.php b/controller/callbackcontroller.php
index 9ccb0a8..8dbf6c2 100644
--- a/controller/callbackcontroller.php
+++ b/controller/callbackcontroller.php
@@ -571,14 +571,13 @@ class CallbackController extends Controller {
try {
$lockContext = new LockContext($file, ILock::TYPE_APP, $this->appName);
$this->lockManager->runInScope($lockContext, $retryOperation);
- if (!$isForcesave) {
- $this->lockManager->unlock($lockContext);
- }
-
- $this->logger->debug("$this->appName has unlocked file $fileId", ["app" => $this->appName]);
} catch (NoLockProviderException $e) {
$retryOperation();
- } catch (PreConditionNotMetException $e) {}
+ }
+
+ if (!$isForcesave) {
+ $this->unlock($file);
+ }
if (RemoteInstance::isRemoteFile($file)) {
if ($isForcesave) {
@@ -612,22 +611,12 @@ class CallbackController extends Controller {
break;
case self::TrackerStatus_Editing:
- try {
- if (empty($this->lockManager->getLocks($file->getId()))) {
- $this->lockManager->lock(new LockContext($file, ILock::TYPE_APP, $this->appName));
-
- $this->logger->debug("$this->appName has locked file $fileId", ["app" => $this->appName]);
- }
- } catch (PreConditionNotMetException | OwnerLockedException | NoLockProviderException $e) {}
+ $this->lock($file);
$result = 0;
break;
case self::TrackerStatus_Closed:
- try {
- $this->lockManager->unlock(new LockContext($file, ILock::TYPE_APP, $this->appName));
-
- $this->logger->debug("$this->appName has unlocked file $fileId", ["app" => $this->appName]);
- } catch (PreConditionNotMetException | NoLockProviderException $e) {}
+ $this->unlock($file);
$result = 0;
break;
@@ -810,6 +799,46 @@ class CallbackController extends Controller {
}
/**
+ * Lock file by lock provider if exists
+ *
+ * @param File $file - file
+ */
+ private function lock($file) {
+ if (!$this->lockManager->isLockProviderAvailable()) {
+ return;
+ }
+
+ $fileId = $file->getId();
+
+ try {
+ if (empty($this->lockManager->getLocks($fileId))) {
+ $this->lockManager->lock(new LockContext($file, ILock::TYPE_APP, $this->appName));
+
+ $this->logger->debug("$this->appName has locked file $fileId", ["app" => $this->appName]);
+ }
+ } catch (PreConditionNotMetException | OwnerLockedException | NoLockProviderException $e) {}
+ }
+
+ /**
+ * Unlock file by lock provider if exists
+ *
+ * @param File $file - file
+ */
+ private function unlock($file) {
+ if (!$this->lockManager->isLockProviderAvailable()) {
+ return;
+ }
+
+ $fileId = $file->getId();
+
+ try {
+ $this->lockManager->unlock(new LockContext($file, ILock::TYPE_APP, $this->appName));
+
+ $this->logger->debug("$this->appName has unlocked file $fileId", ["app" => $this->appName]);
+ } catch (PreConditionNotMetException | NoLockProviderException $e) {}
+ }
+
+ /**
* Retry operation if a LockedException occurred
* Other exceptions will still be thrown
*