Skip to content

Commit

Permalink
set timeout to lockinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Nov 22, 2019
1 parent e9f8b6d commit c1253bd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/Db/CoreRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

use OC;
use OC\DB\SchemaWrapper;
use OCA\FilesLock\Service\ConfigService;
use OCA\FilesLock\Service\MiscService;
use OCP\IDBConnection;
use OCP\ILogger;
Expand All @@ -57,6 +58,9 @@ class CoreRequestBuilder {
/** @var IDBConnection */
protected $dbConnection;

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

/** @var MiscService */
protected $miscService;

Expand All @@ -70,11 +74,15 @@ class CoreRequestBuilder {
*
* @param IDBConnection $connection
* @param ILogger $logger
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(IDBConnection $connection, ILogger $logger, MiscService $miscService) {
public function __construct(
IDBConnection $connection, ILogger $logger, ConfigService $configService, MiscService $miscService
) {
$this->dbConnection = $connection;
$this->logger = $logger;
$this->configService = $configService;
$this->miscService = $miscService;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Db/LocksRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\FilesLock\Exceptions\LockNotFoundException;
use OCA\FilesLock\Model\FileLock;
use OCA\FilesLock\Service\ConfigService;


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

return $lock;
Expand Down
29 changes: 27 additions & 2 deletions lib/Model/FileLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ class FileLock implements IQueryRow, JsonSerializable {
/** @var int */
private $fileId = 0;

/** @var int */
private $timeout = 1800;

/** @var int */
private $creation = 0;


/**
* FileLock constructor.
*
* @param int $timeout
*/
public function __construct() {
public function __construct(int $timeout = 1800) {
$this->timeout = $timeout;
}


Expand Down Expand Up @@ -167,6 +173,25 @@ public function setToken(string $token): self {
}


/**
* @return int
*/
public function getTimeout(): int {
return $this->timeout;
}

/**
* @param int $timeout
*
* @return FileLock
*/
public function setTimeout(int $timeout): self {
$this->timeout = $timeout;

return $this;
}


/**
* @return int
*/
Expand All @@ -193,7 +218,7 @@ public function toLockInfo(): LockInfo {
$lock = new LockInfo();
$lock->owner = $this->getUserId();
$lock->token = $this->getToken();
$lock->timeout = 100000;
$lock->timeout = $this->getTimeout();
$lock->created = $this->getCreation();
$lock->scope = LockInfo::EXCLUSIVE;
$lock->depth = 1;
Expand Down
8 changes: 8 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public function __construct(
}


/**
* @return int
*/
public function getTimeoutSeconds(): int {
return ((int)$this->getAppValue(ConfigService::LOCK_TIMEOUT)) * 60;
}


/**
* Get a value by key
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/LockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function lockFile(Node $file, IUser $user): FileLock {
throw new NotFileException('Must be a file, seems to be a folder.');
}

$lock = new FileLock();
$lock = new FileLock($this->configService->getTimeoutSeconds());
$lock->setUserId($user->getUID());
$lock->setFileId($file->getId());

Expand Down

0 comments on commit c1253bd

Please sign in to comment.