summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-03-26 13:07:12 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-03-26 14:40:23 +0200
commitf4fd0224db82b1bab3e7f661686718fa9aebdf3b (patch)
treecf48b9c0f9877e5d6842838df17463a0e11c87c2 /apps/federatedfilesharing
parente2b44d199bea7da74811689ec3ab787135e22de6 (diff)
downloadnextcloud-server-f4fd0224db82b1bab3e7f661686718fa9aebdf3b.tar.gz
nextcloud-server-f4fd0224db82b1bab3e7f661686718fa9aebdf3b.zip
Do not use \OCP\DB anymore
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/federatedfilesharing')
-rw-r--r--apps/federatedfilesharing/lib/Controller/RequestHandlerController.php29
-rw-r--r--apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php30
2 files changed, 43 insertions, 16 deletions
diff --git a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php
index bc81db50b28..90346546a23 100644
--- a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php
+++ b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php
@@ -427,9 +427,19 @@ class RequestHandlerController extends OCSController {
$token = isset($_POST['token']) ? $_POST['token'] : null;
- $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?');
- $query->execute(array($id, $token));
- $share = $query->fetchRow();
+ $qb = $this->connection->getQueryBuilder();
+ $qb->select('*')
+ ->from('share_external')
+ ->where(
+ $qb->expr()->andX(
+ $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
+ $qb->expr()->eq('share_token', $qb->createNamedParameter($token))
+ )
+ );
+
+ $result = $qb->execute();
+ $share = $result->fetch();
+ $result->closeCursor();
if ($token && $id && !empty($share)) {
@@ -439,8 +449,17 @@ class RequestHandlerController extends OCSController {
$mountpoint = $share['mountpoint'];
$user = $share['user'];
- $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external` WHERE `remote_id` = ? AND `share_token` = ?');
- $query->execute(array($id, $token));
+ $qb = $this->connection->getQueryBuilder();
+ $qb->delete('share_external')
+ ->where(
+ $qb->expr()->andX(
+ $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
+ $qb->expr()->eq('share_token', $qb->createNamedParameter($token))
+ )
+ );
+
+ $result = $qb->execute();
+ $result->closeCursor();
if ($share['accepted']) {
$path = trim($mountpoint, '/');
diff --git a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
index 035b7da15ca..d76f93751a4 100644
--- a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
+++ b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
@@ -119,11 +119,13 @@ class RequestHandlerControllerTest extends TestCase {
}
protected function tearDown() {
- $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share_external`');
- $query->execute();
+ $qb = $this->connection->getQueryBuilder();
+ $qb->delete('share_external');
+ $qb->execute();
- $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`');
- $query->execute();
+ $qb = $this->connection->getQueryBuilder();
+ $qb->delete('share');
+ $qb->execute();
parent::tearDown();
}
@@ -142,9 +144,15 @@ class RequestHandlerControllerTest extends TestCase {
$this->s2s->createShare(null);
- $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share_external` WHERE `remote_id` = ?');
- $result = $query->execute(array('1'));
- $data = $result->fetchRow();
+ $qb = $this->connection->getQueryBuilder();
+ $qb->select('*')
+ ->from('share_external')
+ ->where(
+ $qb->expr()->eq('remote_id', $qb->createNamedParameter(1))
+ );
+ $result = $qb->execute();
+ $data = $result->fetch();
+ $result->closeCursor();
$this->assertSame('localhost', $data['remote']);
$this->assertSame('token', $data['share_token']);
@@ -187,7 +195,7 @@ class RequestHandlerControllerTest extends TestCase {
$this->share->expects($this->any())->method('verifyShare')->willReturn(true);
- $dummy = \OCP\DB::prepare('
+ $dummy = \OC_DB::prepare('
INSERT INTO `*PREFIX*share`
(`share_type`, `uid_owner`, `item_type`, `item_source`, `item_target`, `file_source`, `file_target`, `permissions`, `stime`, `token`, `share_with`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
@@ -195,7 +203,7 @@ class RequestHandlerControllerTest extends TestCase {
$dummy->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, self::TEST_FILES_SHARING_API_USER1, 'test', '1', '/1', '1', '/test.txt', '1', time(), 'token1', 'foo@bar'));
$dummy->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, self::TEST_FILES_SHARING_API_USER1, 'test', '1', '/1', '1', '/test.txt', '1', time(), 'token2', 'bar@bar'));
- $verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
+ $verify = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $verify->execute();
$data = $result->fetchAll();
$this->assertCount(2, $data);
@@ -203,7 +211,7 @@ class RequestHandlerControllerTest extends TestCase {
$_POST['token'] = 'token1';
$this->s2s->declineShare(array('id' => $data[0]['id']));
- $verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
+ $verify = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $verify->execute();
$data = $result->fetchAll();
$this->assertCount(1, $data);
@@ -212,7 +220,7 @@ class RequestHandlerControllerTest extends TestCase {
$_POST['token'] = 'token2';
$this->s2s->declineShare(array('id' => $data[0]['id']));
- $verify = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
+ $verify = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $verify->execute();
$data = $result->fetchAll();
$this->assertEmpty($data);