diff options
Diffstat (limited to 'apps/testing/lib/Controller/LockingController.php')
-rw-r--r-- | apps/testing/lib/Controller/LockingController.php | 112 |
1 files changed, 26 insertions, 86 deletions
diff --git a/apps/testing/lib/Controller/LockingController.php b/apps/testing/lib/Controller/LockingController.php index c1fd3423996..edc66d012ee 100644 --- a/apps/testing/lib/Controller/LockingController.php +++ b/apps/testing/lib/Controller/LockingController.php @@ -1,26 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Testing\Controller; use OC\Lock\DBLockingProvider; @@ -40,21 +24,6 @@ use OCP\Lock\LockedException; class LockingController extends OCSController { - /** @var ILockingProvider */ - protected $lockingProvider; - - /** @var FakeDBLockingProvider */ - protected $fakeDBLockingProvider; - - /** @var IDBConnection */ - protected $connection; - - /** @var IConfig */ - protected $config; - - /** @var IRootFolder */ - protected $rootFolder; - /** * @param string $appName * @param IRequest $request @@ -64,27 +33,22 @@ class LockingController extends OCSController { * @param IConfig $config * @param IRootFolder $rootFolder */ - public function __construct($appName, - IRequest $request, - ILockingProvider $lockingProvider, - FakeDBLockingProvider $fakeDBLockingProvider, - IDBConnection $connection, - IConfig $config, - IRootFolder $rootFolder) { + public function __construct( + $appName, + IRequest $request, + protected ILockingProvider $lockingProvider, + protected FakeDBLockingProvider $fakeDBLockingProvider, + protected IDBConnection $connection, + protected IConfig $config, + protected IRootFolder $rootFolder, + ) { parent::__construct($appName, $request); - - $this->lockingProvider = $lockingProvider; - $this->fakeDBLockingProvider = $fakeDBLockingProvider; - $this->connection = $connection; - $this->config = $config; - $this->rootFolder = $rootFolder; } /** - * @return ILockingProvider * @throws \RuntimeException */ - protected function getLockingProvider() { + protected function getLockingProvider(): ILockingProvider { if ($this->lockingProvider instanceof DBLockingProvider) { return $this->fakeDBLockingProvider; } @@ -92,21 +56,17 @@ class LockingController extends OCSController { } /** - * @param string $user - * @param string $path - * @return string * @throws NotFoundException */ - protected function getPath($user, $path) { + protected function getPath(string $user, string $path): string { $node = $this->rootFolder->getUserFolder($user)->get($path); return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/')); } /** - * @return DataResponse * @throws OCSException */ - public function isLockingEnabled() { + public function isLockingEnabled(): DataResponse { try { $this->getLockingProvider(); return new DataResponse(); @@ -116,13 +76,9 @@ class LockingController extends OCSController { } /** - * @param int $type - * @param string $user - * @param string $path - * @return DataResponse * @throws OCSException */ - public function acquireLock($type, $user, $path) { + public function acquireLock(int $type, string $user, string $path): DataResponse { try { $path = $this->getPath($user, $path); } catch (NoUserException $e) { @@ -135,7 +91,7 @@ class LockingController extends OCSController { try { $lockingProvider->acquireLock($path, $type); - $this->config->setAppValue('testing', 'locking_' . $path, $type); + $this->config->setAppValue('testing', 'locking_' . $path, (string)$type); return new DataResponse(); } catch (LockedException $e) { throw new OCSException('', Http::STATUS_LOCKED, $e); @@ -143,13 +99,9 @@ class LockingController extends OCSController { } /** - * @param int $type - * @param string $user - * @param string $path - * @return DataResponse * @throws OCSException */ - public function changeLock($type, $user, $path) { + public function changeLock(int $type, string $user, string $path): DataResponse { try { $path = $this->getPath($user, $path); } catch (NoUserException $e) { @@ -162,7 +114,7 @@ class LockingController extends OCSController { try { $lockingProvider->changeLock($path, $type); - $this->config->setAppValue('testing', 'locking_' . $path, $type); + $this->config->setAppValue('testing', 'locking_' . $path, (string)$type); return new DataResponse(); } catch (LockedException $e) { throw new OCSException('', Http::STATUS_LOCKED, $e); @@ -170,13 +122,9 @@ class LockingController extends OCSController { } /** - * @param int $type - * @param string $user - * @param string $path - * @return DataResponse * @throws OCSException */ - public function releaseLock($type, $user, $path) { + public function releaseLock(int $type, string $user, string $path): DataResponse { try { $path = $this->getPath($user, $path); } catch (NoUserException $e) { @@ -197,13 +145,9 @@ class LockingController extends OCSController { } /** - * @param int $type - * @param string $user - * @param string $path - * @return DataResponse * @throws OCSException */ - public function isLocked($type, $user, $path) { + public function isLocked(int $type, string $user, string $path): DataResponse { try { $path = $this->getPath($user, $path); } catch (NoUserException $e) { @@ -221,11 +165,7 @@ class LockingController extends OCSController { throw new OCSException('', Http::STATUS_LOCKED); } - /** - * @param int $type - * @return DataResponse - */ - public function releaseAll($type = null) { + public function releaseAll(?int $type = null): DataResponse { $lockingProvider = $this->getLockingProvider(); foreach ($this->config->getAppKeys('testing') as $lock) { @@ -233,11 +173,11 @@ class LockingController extends OCSController { $path = substr($lock, strlen('locking_')); if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); + $lockingProvider->releaseLock($path, (int)$this->config->getAppValue('testing', $lock)); } elseif ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); + $lockingProvider->releaseLock($path, (int)$this->config->getAppValue('testing', $lock)); } else { - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); + $lockingProvider->releaseLock($path, (int)$this->config->getAppValue('testing', $lock)); } } } |