From 4d87d388b868f5c10a04b16220c79317075855d2 Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 21:19:06 +0800 Subject: [PATCH 1/7] Update ReaderMapper.php --- lib/Db/ReaderMapper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Db/ReaderMapper.php b/lib/Db/ReaderMapper.php index 516783a..50969a6 100644 --- a/lib/Db/ReaderMapper.php +++ b/lib/Db/ReaderMapper.php @@ -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 @@ -28,12 +28,12 @@ abstract class ReaderMapper extends Mapper { $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); } From 3ea424693be99372087ad144ee7854cbe9945f53 Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 21:19:47 +0800 Subject: [PATCH 2/7] Update BookmarkMapper.php --- lib/Db/BookmarkMapper.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/Db/BookmarkMapper.php b/lib/Db/BookmarkMapper.php index c7f5c7a..c8a26c3 100644 --- a/lib/Db/BookmarkMapper.php +++ b/lib/Db/BookmarkMapper.php @@ -36,21 +36,24 @@ class BookmarkMapper extends ReaderMapper { * @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; - } + 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))); - return $this->findEntities($sql, $args); + 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); +} + /** * @brief write bookmark to database * From 4798977aeae384795e2994f275b491e83e49e917 Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 21:20:20 +0800 Subject: [PATCH 3/7] Update PreferenceMapper.php --- lib/Db/PreferenceMapper.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/Db/PreferenceMapper.php b/lib/Db/PreferenceMapper.php index 16af9be..3248b96 100644 --- a/lib/Db/PreferenceMapper.php +++ b/lib/Db/PreferenceMapper.php @@ -10,6 +10,7 @@ namespace OCA\Epubreader\Db; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\Epubreader\Utility\Time; use OCP\IDBConnection; @@ -29,22 +30,22 @@ class PreferenceMapper extends ReaderMapper { * @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))); + + + + } - return $this->findEntities($sql, $args); + return $this->findEntities($query); } /** From ec7597142c9594ef0c3ff9c3c0fa6e83090357b9 Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 21:48:51 +0800 Subject: [PATCH 4/7] Update PreferenceMapper.php remove 4 empty lines. --- lib/Db/PreferenceMapper.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Db/PreferenceMapper.php b/lib/Db/PreferenceMapper.php index 3248b96..e4db648 100644 --- a/lib/Db/PreferenceMapper.php +++ b/lib/Db/PreferenceMapper.php @@ -38,11 +38,7 @@ class PreferenceMapper extends ReaderMapper { ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId))); if (!empty($name)) { - $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name))); - - - - + $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name))); } return $this->findEntities($query); From 1ae0fad1eaf4e715c5b36fdec3763954db43391c Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 21:59:19 +0800 Subject: [PATCH 5/7] Update BookmarkMapper.php indent this function properly line 39-55. --- lib/Db/BookmarkMapper.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Db/BookmarkMapper.php b/lib/Db/BookmarkMapper.php index c8a26c3..8f5ff09 100644 --- a/lib/Db/BookmarkMapper.php +++ b/lib/Db/BookmarkMapper.php @@ -36,23 +36,23 @@ class BookmarkMapper extends ReaderMapper { * @param string $name * @return array */ - 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))); + 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 ($type !== null) { + $query->andWhere($query->expr()->eq('type', $query->createNamedParameter($type))); + } - if ($name !== null) { - $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name))); - } + if ($name !== null) { + $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name))); + } - return $this->findEntities($query); -} + return $this->findEntities($query); + } /** * @brief write bookmark to database From cc0b8fb6d6a0524f7b56a3f6f08894baa965060e Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 22:05:28 +0800 Subject: [PATCH 6/7] Update BookmarkMapper.php From 1f0cd40dc7988411681162485388e6e020d3f18c Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 22:15:42 +0800 Subject: [PATCH 7/7] Update BookmarkMapper.php --- lib/Db/BookmarkMapper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Db/BookmarkMapper.php b/lib/Db/BookmarkMapper.php index 8f5ff09..6ed45ee 100644 --- a/lib/Db/BookmarkMapper.php +++ b/lib/Db/BookmarkMapper.php @@ -39,20 +39,20 @@ class BookmarkMapper extends ReaderMapper { 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))); + ->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))); + $query->andWhere($query->expr()->eq('type', $query->createNamedParameter($type))); } if ($name !== null) { - $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name))); + $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name))); } return $this->findEntities($query); - } + } /** * @brief write bookmark to database