Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OC\Files\Filesystem;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\FilesLock\Capability;
use OCA\FilesLock\ConfigLexicon;
use OCA\FilesLock\Listeners\LoadAdditionalScripts;
use OCA\FilesLock\Listeners\PropfindPropertiesListener;
use OCA\FilesLock\LockProvider;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function register(IRegistrationContext $context): void {
BeforeRemotePropfindEvent::class,
PropfindPropertiesListener::class
);
$context->registerConfigLexicon(ConfigLexicon::class);
}

#[\Override]
Expand Down
41 changes: 7 additions & 34 deletions lib/Command/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
use OCA\FilesLock\Exceptions\SuccessException;
use OCA\FilesLock\Exceptions\UnauthorizedUnlockException;
use OCA\FilesLock\Model\FileLock;
use OCA\FilesLock\Service\ConfigService;
use OCA\FilesLock\Service\FileService;
use OCA\FilesLock\Service\LockService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\InvalidPathException;
use OCP\Files\Lock\ILock;
use OCP\Files\Lock\LockContext;
Expand All @@ -33,41 +33,14 @@
use Symfony\Component\Console\Question\ConfirmationQuestion;

class Lock extends Base {
/** @var IUserManager */
private $userManager;

/** @var LocksRequest */
private $locksRequest;

/** @var FileService */
private $fileService;

/** @var LockService */
private $lockService;

/** @var ConfigService */
private $configService;

/**
* CacheUpdate constructor.
*
* @param IUserManager $userManager
* @param FileService $fileService
* @param LockService $lockService
* @param LocksRequest $locksRequest
* @param ConfigService $configService
*/
public function __construct(
IUserManager $userManager, LocksRequest $locksRequest, FileService $fileService,
LockService $lockService, ConfigService $configService,
private readonly IUserManager $userManager,
private readonly LocksRequest $locksRequest,
private readonly FileService $fileService,
private readonly LockService $lockService,
private readonly IAppConfig $appConfig,
) {
parent::__construct();

$this->userManager = $userManager;
$this->locksRequest = $locksRequest;
$this->fileService = $fileService;
$this->lockService = $lockService;
$this->configService = $configService;
}

/**
Expand Down Expand Up @@ -227,7 +200,7 @@ private function uninstallApp(InputInterface $input, OutputInterface $output) {
}

$this->locksRequest->uninstall();
$this->configService->unsetAppConfig();
$this->appConfig->deleteAppValues();
$output->writeln('<comment>FilesLock App fully uninstalled.</comment>');

throw new SuccessException();
Expand Down
44 changes: 44 additions & 0 deletions lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\FilesLock;

use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;

/**
* Config Lexicon for files_lock.
*
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*
* {@see ILexicon}
*/
class ConfigLexicon implements ILexicon {
public const LOCK_TIMEOUT = 'lock_timeout';

public function getStrictness(): Strictness {

Check failure on line 26 in lib/ConfigLexicon.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingOverrideAttribute

lib/ConfigLexicon.php:26:2: MissingOverrideAttribute: Method OCA\FilesLock\ConfigLexicon::getstrictness should have the "Override" attribute (see https://psalm.dev/358)
return Strictness::NOTICE;
}

public function getAppConfigs(): array {

Check failure on line 30 in lib/ConfigLexicon.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingOverrideAttribute

lib/ConfigLexicon.php:30:2: MissingOverrideAttribute: Method OCA\FilesLock\ConfigLexicon::getappconfigs should have the "Override" attribute (see https://psalm.dev/358)
return [
new Entry(
self::LOCK_TIMEOUT,
ValueType::INT,
defaultRaw: -1,
definition: 'Time in minutes until a lock expires. -1 = never expires.',
),
];
}

public function getUserConfigs(): array {

Check failure on line 41 in lib/ConfigLexicon.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingOverrideAttribute

lib/ConfigLexicon.php:41:2: MissingOverrideAttribute: Method OCA\FilesLock\ConfigLexicon::getuserconfigs should have the "Override" attribute (see https://psalm.dev/358)
return [];
}
}
15 changes: 8 additions & 7 deletions lib/Db/LocksRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

namespace OCA\FilesLock\Db;

use OCA\FilesLock\ConfigLexicon;
use OCA\FilesLock\Exceptions\LockNotFoundException;
use OCA\FilesLock\Model\FileLock;
use OCA\FilesLock\Service\ConfigService;
use OCA\FilesLock\Tools\Exceptions\RowNotFoundException;
use OCA\FilesLock\Tools\Traits\TArrayTools;
use OCP\AppFramework\Services\IAppConfig;

/**
* Class LocksRequestBuilder
Expand All @@ -22,12 +23,12 @@
*/
class LocksRequestBuilder extends CoreRequestBuilder {
use TArrayTools;
private int $timeout;

/** @var ConfigService */
private $configService;

public function __construct(ConfigService $configService) {
$this->configService = $configService;
public function __construct(
private readonly IAppConfig $appConfig,
) {
$this->timeout = $this->appConfig->getAppValueInt(ConfigLexicon::LOCK_TIMEOUT) * 60;
}

/**
Expand Down Expand Up @@ -117,7 +118,7 @@ public function getLocksFromRequest(CoreQueryBuilder $qb): array {
* @return FileLock
*/
public function parseLockSelectSql(array $data): FileLock {
$lock = new FileLock($this->configService->getTimeoutSeconds());
$lock = new FileLock($this->timeout);
$lock->importFromDatabase($data);

return $lock;
Expand Down
103 changes: 0 additions & 103 deletions lib/Service/ConfigService.php

This file was deleted.

16 changes: 7 additions & 9 deletions lib/Service/LockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
use OC\Files\Storage\DAV;
use OC\Files\Storage\Wrapper\Wrapper;
use OCA\FilesLock\AppInfo\Application;
use OCA\FilesLock\ConfigLexicon;
use OCA\FilesLock\Db\LocksRequest;
use OCA\FilesLock\Exceptions\LockNotFoundException;
use OCA\FilesLock\Exceptions\UnauthorizedUnlockException;
use OCA\FilesLock\Model\FileLock;
use OCA\FilesLock\Tools\Traits\TStringTools;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\InvalidPathException;
Expand All @@ -43,7 +45,6 @@ class LockService {
private IL10N $l10n;
private LocksRequest $locksRequest;
private FileService $fileService;
private ConfigService $configService;
private IAppManager $appManager;
private IEventDispatcher $eventDispatcher;
private IUserSession $userSession;
Expand All @@ -62,7 +63,7 @@ public function __construct(
IUserManager $userManager,
LocksRequest $locksRequest,
FileService $fileService,
ConfigService $configService,
private IAppConfig $appConfig,
IAppManager $appManager,
IEventDispatcher $eventDispatcher,
IUserSession $userSession,
Expand All @@ -74,7 +75,6 @@ public function __construct(
$this->userManager = $userManager;
$this->locksRequest = $locksRequest;
$this->fileService = $fileService;
$this->configService = $configService;
$this->appManager = $appManager;
$this->eventDispatcher = $eventDispatcher;
$this->userSession = $userSession;
Expand Down Expand Up @@ -159,6 +159,7 @@ public function getLockForNodeIds(array $nodeIds): array {

public function lock(LockContext $lockScope): FileLock {
$this->canLock($lockScope);
$timeout = $this->appConfig->getAppValueInt(ConfigLexicon::LOCK_TIMEOUT) * 60;

try {
$known = $this->getLockFromFileId($lockScope->getNode()->getId());
Expand All @@ -167,9 +168,7 @@ public function lock(LockContext $lockScope): FileLock {
if (
$known->getType() === $lockScope->getType() && ($known->getOwner() === $lockScope->getOwner() || $known->getToken() === $lockScope->getOwner())
) {
$known->setTimeout(
$known->getETA() !== FileLock::ETA_INFINITE ? $known->getTimeout() - $known->getETA() + $this->configService->getTimeoutSeconds() : 0
);
$known->setTimeout($known->getETA() !== FileLock::ETA_INFINITE ? $known->getTimeout() - $known->getETA() + $timeout : 0);
$this->logger->notice('extending existing lock', ['fileLock' => $known]);
$this->locksRequest->update($known);
$this->lockCache[$lockScope->getNode()->getId()] = $known;
Expand All @@ -180,7 +179,7 @@ public function lock(LockContext $lockScope): FileLock {
$this->injectMetadata($known);
throw new OwnerLockedException($known);
} catch (LockNotFoundException $e) {
$lock = FileLock::fromLockScope($lockScope, $this->configService->getTimeoutSeconds());
$lock = FileLock::fromLockScope($lockScope, $timeout);
$this->generateToken($lock);
$lock->setCreation(time());
$this->logger->notice('locking file', ['fileLock' => $lock]);
Expand Down Expand Up @@ -306,8 +305,7 @@ public function unlockFile(int $fileId, string $userId, bool $force = false, int
* @return FileLock[]
*/
public function getDeprecatedLocks(int $limit = 0): array {
$timeout = (int)$this->configService->getAppValue(ConfigService::LOCK_TIMEOUT);

$timeout = $this->appConfig->getAppValueInt(ConfigLexicon::LOCK_TIMEOUT);
if ($timeout === FileLock::ETA_INFINITE) {
return [];
}
Expand Down
Loading
Loading