Skip to content

Commit

Permalink
Make DB locking detectable
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Mar 15, 2016
1 parent 32e9132 commit 59fd288
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
!/apps/user_ldap
!/apps/provisioning_api
!/apps/systemtags
!/apps/testing
!/apps/updatenotification
/apps/files_external/3rdparty/irodsphp/PHPUnitTest
/apps/files_external/3rdparty/irodsphp/web
Expand Down
1 change: 1 addition & 0 deletions apps/testing/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
\OC::$server->getConfig(),
\OC::$server->getRequest()
);
API::register('get', '/apps/testing/api/v1/lockprovisioning', [$locking, 'isLockingEnabled'], 'files_lockprovisioning', API::ADMIN_AUTH);
API::register('get', '/apps/testing/api/v1/lockprovisioning/{type}/{user}', [$locking, 'isLocked'], 'files_lockprovisioning', API::ADMIN_AUTH);
API::register('post', '/apps/testing/api/v1/lockprovisioning/{type}/{user}', [$locking, 'acquireLock'], 'files_lockprovisioning', API::ADMIN_AUTH);
API::register('put', '/apps/testing/api/v1/lockprovisioning/{type}/{user}', [$locking, 'changeLock'], 'files_lockprovisioning', API::ADMIN_AUTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use OCP\IDBConnection;
use OCP\ILogger;

class FakeDBLocking extends \OC\Lock\DBLockingProvider {
class FakeDBLockingProvider extends \OC\Lock\DBLockingProvider {
// Lock for 10 hours just to be sure
const TTL = 36000;

Expand Down
21 changes: 17 additions & 4 deletions apps/testing/locking/provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace OCA\Testing\Locking;

use OC\Lock\DBLockingProvider;
use OC\Lock\MemcacheLockingProvider;
use OC\User\NoUserException;
use OCP\AppFramework\Http;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -61,12 +63,11 @@ public function __construct(ILockingProvider $lockingProvider, IDBConnection $co
* @return ILockingProvider
*/
protected function getLockingProvider() {
return \OC::$server->query('OCA\Testing\Locking\FakeDBLocking');
/*
if ($this->lockingProvider instanceof DBLockingProvider) {
return \OC::$server->query('OCA\Testing\Locking\FakeDBLocking');
return \OC::$server->query('OCA\Testing\Locking\FakeDBLockingProvider');
} else {
throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
}
*/
}

/**
Expand All @@ -88,6 +89,18 @@ protected function getPath($parameters) {
return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
}

/**
* @return \OC_OCS_Result
*/
public function isLockingEnabled() {
try {
$this->getLockingProvider();
return new \OC_OCS_Result(null, 100);
} catch (\RuntimeException $e) {
return new \OC_OCS_Result(null, Http::STATUS_NOT_IMPLEMENTED, $e->getMessage());
}
}

/**
* @param array $parameters
* @return \OC_OCS_Result
Expand Down

0 comments on commit 59fd288

Please sign in to comment.