Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use QbMapper to replace the Mapper removed in nextcloud version 26.0.0 #48

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions lib/Db/BookmarkMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ public function __construct(IDBConnection $db, $UserId, Time $time) {
* @param string $name
* @return array
*/
public function get($fileId, $name, $type=null) {
$sql = "SELECT * FROM `*PREFIX*reader_bookmarks` WHERE file_id=? AND `user_id`=?";
$args = [ $fileId, $this->userId ];
if (!(null === $type)) {
$sql .= " AND `type`=?";
$args[] = $type;
}
if (!(null === $name)) {
$sql .= " AND `name`=?";
$args[] = $name;
}

return $this->findEntities($sql, $args);
public function get($fileId, $name, $type = null) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId)))
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId)));

if ($type !== null) {
$query->andWhere($query->expr()->eq('type', $query->createNamedParameter($type)));
}

if ($name !== null) {
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
}

return $this->findEntities($query);
Comment on lines +39 to +54

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function get($fileId, $name, $type = null) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId)))
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId)));
if ($type !== null) {
$query->andWhere($query->expr()->eq('type', $query->createNamedParameter($type)));
}
if ($name !== null) {
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
}
return $this->findEntities($query);
public function get($fileId, $name, $type = null) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId)))
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId)));
if ($type !== null) {
$query->andWhere($query->expr()->eq('type', $query->createNamedParameter($type)));
}
if ($name !== null) {
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
}
return $this->findEntities($query);

}

/**
Expand Down
25 changes: 11 additions & 14 deletions lib/Db/PreferenceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace OCA\Epubreader\Db;

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\Epubreader\Utility\Time;
use OCP\IDBConnection;

Expand All @@ -29,22 +30,18 @@ public function __construct(IDBConnection $db, $UserId, Time $time) {
* @return array
*/
public function get($scope, $fileId, $name=null) {
if(!empty($name)) {
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=? AND `name`=?";
$args = array(
$scope,
$fileId,
$this->userId,
$name);
} else {
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=?";
$args = array(
$scope,
$fileId,
$this->userId);
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
->where($query->expr()->eq('scope', $query->createNamedParameter($scope)))
->andWhere($query->expr()->eq('file_id', $query->createNamedParameter($fileId)))
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId)));

if (!empty($name)) {
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));

}

return $this->findEntities($sql, $args);
return $this->findEntities($query);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return $this->findEntities($query);
return $this->findEntities($query);

}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Db/ReaderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
namespace OCA\Epubreader\Db;

use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Db\Entity;

use OCA\Epubreader\Utility\Time;

abstract class ReaderMapper extends Mapper {
abstract class ReaderMapper extends QBMapper {

/**
* @var Time
Expand All @@ -28,12 +28,12 @@ public function __construct(IDBConnection $db, $table, $entity, Time $time) {
$this->time = $time;
}

public function update(Entity $entity) {
public function update(Entity $entity): Entity {
$entity->setLastModified($this->time->getMicroTime());
return parent::update($entity);
}

public function insert(Entity $entity) {
public function insert(Entity $entity): Entity {
$entity->setLastModified($this->time->getMicroTime());
return parent::insert($entity);
}
Expand Down