summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@owncloud.com>2016-05-08 17:41:37 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2016-05-11 13:36:46 +0200
commitaf707fba41634b70115d47de86efe2ce2bf3d3b6 (patch)
treea41b36f73a514fc5dc211242b26b1d0799feb2eb /lib/private
parent46bdf6ea2b1e10c2f4d2fae214ecc81b188fa981 (diff)
downloadnextcloud-server-af707fba41634b70115d47de86efe2ce2bf3d3b6.tar.gz
nextcloud-server-af707fba41634b70115d47de86efe2ce2bf3d3b6.zip
use the query builder instead of raw sql statements
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Authentication/Token/DefaultTokenMapper.php45
1 files changed, 27 insertions, 18 deletions
diff --git a/lib/private/Authentication/Token/DefaultTokenMapper.php b/lib/private/Authentication/Token/DefaultTokenMapper.php
index f4d979183e6..18adbe48d78 100644
--- a/lib/private/Authentication/Token/DefaultTokenMapper.php
+++ b/lib/private/Authentication/Token/DefaultTokenMapper.php
@@ -24,6 +24,7 @@ namespace OC\Authentication\Token;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Mapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
class DefaultTokenMapper extends Mapper {
@@ -38,24 +39,25 @@ class DefaultTokenMapper extends Mapper {
* @param string $token
*/
public function invalidate($token) {
- $sql = 'DELETE FROM `' . $this->getTableName() . '` '
- . 'WHERE `token` = ?';
- return $this->execute($sql, [
- $token
- ]);
+ $qb = $this->db->getQueryBuilder();
+ $qb->delete('authtoken')
+ ->andWhere($qb->expr()->eq('token', $qb->createParameter('token')))
+ ->setParameter('token', $token)
+ ->execute();
}
/**
* @param int $olderThan
*/
public function invalidateOld($olderThan) {
- $sql = 'DELETE FROM `' . $this->getTableName() . '` '
- . 'WHERE `last_activity` < ? '
- . 'AND `type` = ?';
- $this->execute($sql, [
- $olderThan,
- IToken::TEMPORARY_TOKEN,
- ]);
+ /* @var $qb IQueryBuilder */
+ $qb = $this->db->getQueryBuilder();
+ $qb->delete('authtoken')
+ ->where($qb->expr()->lt('last_activity', $qb->createParameter('last_activity')))
+ ->andWhere($qb->expr()->eq('type', $qb->createParameter('type')))
+ ->setParameter('last_activity', $olderThan, IQueryBuilder::PARAM_INT)
+ ->setParameter('type', IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT)
+ ->execute();
}
/**
@@ -66,12 +68,19 @@ class DefaultTokenMapper extends Mapper {
* @return DefaultToken
*/
public function getToken($token) {
- $sql = 'SELECT `id`, `uid`, `password`, `name`, `token`, `last_activity` '
- . 'FROM `' . $this->getTableName() . '` '
- . 'WHERE `token` = ?';
- return $this->findEntity($sql, [
- $token
- ]);
+ /* @var $qb IQueryBuilder */
+ $qb = $this->db->getQueryBuilder();
+ $result = $qb->select('id', 'uid', 'password', 'name', 'type', 'token', 'last_activity')
+ ->from('authtoken')
+ ->where($qb->expr()->eq('token', $qb->createParameter('token')))
+ ->setParameter('token', $token)
+ ->execute();
+
+ $data = $result->fetch();
+ if ($data === false) {
+ throw new DoesNotExistException('token does not exist');
+ }
+ return DefaultToken::fromRow($data);
}
}