2016-05-30 05:16:14 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2016-05-30 05:16:14 -04:00
|
|
|
/**
|
2024-06-02 09:26:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-05-30 05:16:14 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Testing\Locking;
|
|
|
|
|
|
2023-11-23 04:22:34 -05:00
|
|
|
use OC\Lock\DBLockingProvider;
|
2016-05-30 05:16:14 -04:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2025-10-02 08:39:14 -04:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2016-05-30 05:16:14 -04:00
|
|
|
use OCP\IDBConnection;
|
2025-10-02 08:39:14 -04:00
|
|
|
use Override;
|
2016-05-30 05:16:14 -04:00
|
|
|
|
2022-04-22 09:00:20 -04:00
|
|
|
class FakeDBLockingProvider extends DBLockingProvider {
|
2016-05-30 05:16:14 -04:00
|
|
|
// Lock for 10 hours just to be sure
|
2020-04-10 10:54:27 -04:00
|
|
|
public const TTL = 36000;
|
2016-05-30 05:16:14 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Need a new child, because parent::connection is private instead of protected...
|
|
|
|
|
*/
|
2022-04-22 09:00:20 -04:00
|
|
|
protected IDBConnection $db;
|
2016-05-30 05:16:14 -04:00
|
|
|
|
2022-03-17 12:26:27 -04:00
|
|
|
public function __construct(
|
|
|
|
|
IDBConnection $connection,
|
2024-09-19 05:10:31 -04:00
|
|
|
ITimeFactory $timeFactory,
|
2022-03-17 12:26:27 -04:00
|
|
|
) {
|
2022-04-22 09:00:20 -04:00
|
|
|
parent::__construct($connection, $timeFactory);
|
2016-05-30 05:16:14 -04:00
|
|
|
$this->db = $connection;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 08:39:14 -04:00
|
|
|
#[Override]
|
2022-04-22 09:00:20 -04:00
|
|
|
public function releaseLock(string $path, int $type): void {
|
2025-10-02 08:39:14 -04:00
|
|
|
// we DON'T keep shared locks till the end of the request
|
2016-05-30 05:16:14 -04:00
|
|
|
if ($type === self::LOCK_SHARED) {
|
2025-10-02 08:39:14 -04:00
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
$qb->update('file_locks')
|
|
|
|
|
->set('lock', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
|
|
|
|
|
->where($qb->expr()->eq('key', $qb->createNamedParameter($path, IQueryBuilder::PARAM_STR)))
|
|
|
|
|
->andWhere($qb->expr()->eq('lock', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
|
|
|
|
|
->executeStatement();
|
2016-05-30 05:16:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::releaseLock($path, $type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __destruct() {
|
|
|
|
|
// Prevent cleaning up at the end of the live time.
|
|
|
|
|
// parent::__destruct();
|
|
|
|
|
}
|
|
|
|
|
}
|