summaryrefslogtreecommitdiffstats
path: root/lib/Db
diff options
context:
space:
mode:
authorSean Molenaar <SMillerDev@users.noreply.github.com>2018-03-27 15:35:06 +0200
committerBernhard Posselt <BernhardPosselt@users.noreply.github.com>2018-03-27 15:35:06 +0200
commit5b94705cf3918dc7986c6043b1fbe776bf22958f (patch)
tree4e8059818a0a913d24938e35238913a721fa6373 /lib/Db
parentf3c9d13551cef5968baea99c2f25085baee0ed5f (diff)
Core: Fix compatibility with nextcloud codestyle (#280)
Diffstat (limited to 'lib/Db')
-rw-r--r--lib/Db/EntityJSONSerializer.php14
-rw-r--r--lib/Db/Feed.php38
-rw-r--r--lib/Db/FeedMapper.php42
-rw-r--r--lib/Db/FeedType.php11
-rw-r--r--lib/Db/Folder.php33
-rw-r--r--lib/Db/FolderMapper.php39
-rw-r--r--lib/Db/IAPI.php11
-rw-r--r--lib/Db/Item.php75
-rw-r--r--lib/Db/ItemMapper.php116
-rw-r--r--lib/Db/MapperFactory.php39
-rw-r--r--lib/Db/Mysql/ItemMapper.php21
-rw-r--r--lib/Db/NewsMapper.php47
12 files changed, 299 insertions, 187 deletions
diff --git a/lib/Db/EntityJSONSerializer.php b/lib/Db/EntityJSONSerializer.php
index 2a7ad9189..72fbf99ec 100644
--- a/lib/Db/EntityJSONSerializer.php
+++ b/lib/Db/EntityJSONSerializer.php
@@ -5,18 +5,20 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
-trait EntityJSONSerializer {
+trait EntityJSONSerializer
+{
- public function serializeFields($properties) {
+ public function serializeFields($properties)
+ {
$result = [];
foreach($properties as $property) {
$result[$property] = $this->$property;
diff --git a/lib/Db/Feed.php b/lib/Db/Feed.php
index 974f2ed8c..7541ac545 100644
--- a/lib/Db/Feed.php
+++ b/lib/Db/Feed.php
@@ -5,10 +5,10 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
@@ -63,7 +63,8 @@ use \OCP\AppFramework\Db\Entity;
* @method string getBasicAuthPassword()
* @method void setBasicAuthPassword(string $value)
*/
-class Feed extends Entity implements IAPI, \JsonSerializable {
+class Feed extends Entity implements IAPI, \JsonSerializable
+{
use EntityJSONSerializer;
@@ -92,7 +93,8 @@ class Feed extends Entity implements IAPI, \JsonSerializable {
protected $basicAuthUser;
protected $basicAuthPassword;
- public function __construct(){
+ public function __construct()
+ {
$this->addType('parentId', 'integer');
$this->addType('added', 'integer');
$this->addType('folderId', 'integer');
@@ -111,8 +113,10 @@ class Feed extends Entity implements IAPI, \JsonSerializable {
/**
* Turns entitie attributes into an array
*/
- public function jsonSerialize() {
- $serialized = $this->serializeFields([
+ public function jsonSerialize()
+ {
+ $serialized = $this->serializeFields(
+ [
'id',
'userId',
'urlHash',
@@ -135,7 +139,8 @@ class Feed extends Entity implements IAPI, \JsonSerializable {
'lastUpdateError',
'basicAuthUser',
'basicAuthPassword'
- ]);
+ ]
+ );
$url = parse_url($this->link, PHP_URL_HOST);
@@ -150,8 +155,10 @@ class Feed extends Entity implements IAPI, \JsonSerializable {
}
- public function toAPI() {
- return $this->serializeFields([
+ public function toAPI()
+ {
+ return $this->serializeFields(
+ [
'id',
'url',
'title',
@@ -164,11 +171,13 @@ class Feed extends Entity implements IAPI, \JsonSerializable {
'pinned',
'updateErrorCount',
'lastUpdateError'
- ]);
+ ]
+ );
}
- public function setUrl($url) {
+ public function setUrl($url)
+ {
$url = trim($url);
if(strpos($url, 'http') === 0) {
parent::setUrl($url);
@@ -177,7 +186,8 @@ class Feed extends Entity implements IAPI, \JsonSerializable {
}
- public function setLink($url) {
+ public function setLink($url)
+ {
$url = trim($url);
if(strpos($url, 'http') === 0) {
parent::setLink($url);
diff --git a/lib/Db/FeedMapper.php b/lib/Db/FeedMapper.php
index ad54ffc37..00f4007a9 100644
--- a/lib/Db/FeedMapper.php
+++ b/lib/Db/FeedMapper.php
@@ -5,10 +5,10 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
@@ -18,15 +18,18 @@ use OCP\IDBConnection;
use OCP\AppFramework\Db\Entity;
-class FeedMapper extends NewsMapper {
+class FeedMapper extends NewsMapper
+{
- public function __construct(IDBConnection $db, Time $time) {
+ public function __construct(IDBConnection $db, Time $time)
+ {
parent::__construct($db, 'news_feeds', Feed::class, $time);
}
- public function find($id, $userId){
+ public function find($id, $userId)
+ {
$sql = 'SELECT `feeds`.*, COUNT(`items`.`id`) AS `unread_count` ' .
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
@@ -45,7 +48,8 @@ class FeedMapper extends NewsMapper {
}
- public function findAllFromUser($userId){
+ public function findAllFromUser($userId)
+ {
$sql = 'SELECT `feeds`.*, COUNT(`items`.`id`) AS `unread_count` ' .
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT OUTER JOIN `*PREFIX*news_folders` `folders` '.
@@ -69,7 +73,8 @@ class FeedMapper extends NewsMapper {
}
- public function findAll(){
+ public function findAll()
+ {
$sql = 'SELECT `feeds`.*, COUNT(`items`.`id`) AS `unread_count` ' .
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT OUTER JOIN `*PREFIX*news_folders` `folders` '.
@@ -91,7 +96,8 @@ class FeedMapper extends NewsMapper {
}
- public function findByUrlHash($hash, $userId){
+ public function findByUrlHash($hash, $userId)
+ {
$sql = 'SELECT `feeds`.*, COUNT(`items`.`id`) AS `unread_count` ' .
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
@@ -110,7 +116,8 @@ class FeedMapper extends NewsMapper {
}
- public function delete(Entity $entity){
+ public function delete(Entity $entity)
+ {
parent::delete($entity);
// someone please slap me for doing this manually :P
@@ -122,12 +129,13 @@ class FeedMapper extends NewsMapper {
/**
- * @param int $deleteOlderThan if given gets all entries with a delete date
- * older than that timestamp
- * @param string $userId if given returns only entries from the given user
+ * @param int $deleteOlderThan if given gets all entries with a delete date
+ * older than that timestamp
+ * @param string $userId if given returns only entries from the given user
* @return array with the database rows
*/
- public function getToDelete($deleteOlderThan=null, $userId=null) {
+ public function getToDelete($deleteOlderThan=null, $userId=null)
+ {
$sql = 'SELECT * FROM `*PREFIX*news_feeds` ' .
'WHERE `deleted_at` > 0 ';
$params = [];
@@ -151,9 +159,11 @@ class FeedMapper extends NewsMapper {
/**
* Deletes all feeds of a user, delete items first since the user_id
* is not defined in there
+ *
* @param string $userId the name of the user
*/
- public function deleteUser($userId) {
+ public function deleteUser($userId)
+ {
$sql = 'DELETE FROM `*PREFIX*news_feeds` WHERE `user_id` = ?';
$this->execute($sql, [$userId]);
}
diff --git a/lib/Db/FeedType.php b/lib/Db/FeedType.php
index dd12d153d..a8ae887f6 100644
--- a/lib/Db/FeedType.php
+++ b/lib/Db/FeedType.php
@@ -5,16 +5,17 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
-class FeedType {
+class FeedType
+{
const FEED = 0;
const FOLDER = 1;
const STARRED = 2;
diff --git a/lib/Db/Folder.php b/lib/Db/Folder.php
index 096e14323..4a6ec8ba1 100644
--- a/lib/Db/Folder.php
+++ b/lib/Db/Folder.php
@@ -5,10 +5,10 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
@@ -30,9 +30,9 @@ use \OCP\AppFramework\Db\Entity;
* @method void setDeletedAt(integer $value)
* @method string getLastModified()
* @method void setLastModified(string $value)
-
*/
-class Folder extends Entity implements IAPI, \JsonSerializable {
+class Folder extends Entity implements IAPI, \JsonSerializable
+{
use EntityJSONSerializer;
@@ -43,7 +43,8 @@ class Folder extends Entity implements IAPI, \JsonSerializable {
protected $deletedAt;
protected $lastModified;
- public function __construct(){
+ public function __construct()
+ {
$this->addType('parentId', 'integer');
$this->addType('opened', 'boolean');
$this->addType('deletedAt', 'integer');
@@ -52,21 +53,27 @@ class Folder extends Entity implements IAPI, \JsonSerializable {
/**
* Turns entitie attributes into an array
*/
- public function jsonSerialize() {
- return $this->serializeFields([
+ public function jsonSerialize()
+ {
+ return $this->serializeFields(
+ [
'id',
'parentId',
'name',
'userId',
'opened',
'deletedAt',
- ]);
+ ]
+ );
}
- public function toAPI() {
- return $this->serializeFields([
+ public function toAPI()
+ {
+ return $this->serializeFields(
+ [
'id',
'name'
- ]);
+ ]
+ );
}
} \ No newline at end of file
diff --git a/lib/Db/FolderMapper.php b/lib/Db/FolderMapper.php
index 4b25c9820..d60864586 100644
--- a/lib/Db/FolderMapper.php
+++ b/lib/Db/FolderMapper.php
@@ -5,10 +5,10 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
@@ -17,13 +17,16 @@ use OCA\News\Utility\Time;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Entity;
-class FolderMapper extends NewsMapper {
+class FolderMapper extends NewsMapper
+{
- public function __construct(IDBConnection $db, Time $time) {
+ public function __construct(IDBConnection $db, Time $time)
+ {
parent::__construct($db, 'news_folders', Folder::class, $time);
}
- public function find($id, $userId){
+ public function find($id, $userId)
+ {
$sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
'WHERE `id` = ? ' .
'AND `user_id` = ?';
@@ -32,7 +35,8 @@ class FolderMapper extends NewsMapper {
}
- public function findAllFromUser($userId){
+ public function findAllFromUser($userId)
+ {
$sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
'WHERE `user_id` = ? ' .
'AND `deleted_at` = 0';
@@ -42,7 +46,8 @@ class FolderMapper extends NewsMapper {
}
- public function findByName($folderName, $userId){
+ public function findByName($folderName, $userId)
+ {
$sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
'WHERE `name` = ? ' .
'AND `user_id` = ?';
@@ -52,7 +57,8 @@ class FolderMapper extends NewsMapper {
}
- public function delete(Entity $entity){
+ public function delete(Entity $entity)
+ {
parent::delete($entity);
// someone please slap me for doing this manually :P
@@ -71,12 +77,13 @@ class FolderMapper extends NewsMapper {
/**
- * @param int $deleteOlderThan if given gets all entries with a delete date
- * older than that timestamp
- * @param string $userId if given returns only entries from the given user
+ * @param int $deleteOlderThan if given gets all entries with a delete date
+ * older than that timestamp
+ * @param string $userId if given returns only entries from the given user
* @return array with the database rows
*/
- public function getToDelete($deleteOlderThan=null, $userId=null) {
+ public function getToDelete($deleteOlderThan=null, $userId=null)
+ {
$sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
'WHERE `deleted_at` > 0 ';
$params = [];
@@ -99,9 +106,11 @@ class FolderMapper extends NewsMapper {
/**
* Deletes all folders of a user
+ *
* @param string $userId the name of the user
*/
- public function deleteUser($userId) {
+ public function deleteUser($userId)
+ {
$sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?';
$this->execute($sql, [$userId]);
}
diff --git a/lib/Db/IAPI.php b/lib/Db/IAPI.php
index 80977cfb2..c6f844147 100644
--- a/lib/Db/IAPI.php
+++ b/lib/Db/IAPI.php
@@ -5,14 +5,15 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
-interface IAPI {
+interface IAPI
+{
public function toAPI();
}
diff --git a/lib/Db/Item.php b/lib/Db/Item.php
index a781048fd..1c31f9d70 100644
--- a/lib/Db/Item.php
+++ b/lib/Db/Item.php
@@ -7,8 +7,8 @@
*
* @author Alessandro Cosentino <cosenal@gmail.com>
* @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
@@ -46,7 +46,8 @@ use \OCP\AppFramework\Db\Entity;
* @method void setUnread(bool $value)
* @method void setStarred(bool $value)
*/
-class Item extends Entity implements IAPI, \JsonSerializable {
+class Item extends Entity implements IAPI, \JsonSerializable
+{
use EntityJSONSerializer;
@@ -70,7 +71,8 @@ class Item extends Entity implements IAPI, \JsonSerializable {
protected $unread = false;
protected $starred = false;
- public function __construct() {
+ public function __construct()
+ {
$this->addType('pubDate', 'integer');
$this->addType('updatedDate', 'integer');
$this->addType('feedId', 'integer');
@@ -79,18 +81,21 @@ class Item extends Entity implements IAPI, \JsonSerializable {
$this->addType('starred', 'boolean');
}
- public function isUnread() {
+ public function isUnread()
+ {
return $this->unread;
}
- public function isStarred() {
+ public function isStarred()
+ {
return $this->starred;
}
/**
* Turns entity attributes into an array
*/
- public function jsonSerialize() {
+ public function jsonSerialize()
+ {
return [
'id' => $this->getId(),
'guid' => $this->getGuid(),
@@ -113,7 +118,8 @@ class Item extends Entity implements IAPI, \JsonSerializable {
];
}
- public function toAPI() {
+ public function toAPI()
+ {
return [
'id' => $this->getId(),
'guid' => $this->getGuid(),
@@ -136,7 +142,8 @@ class Item extends Entity implements IAPI, \JsonSerializable {
];
}
- public function toExport($feeds) {
+ public function toExport($feeds)
+ {
return [
'guid' => $this->getGuid(),
'url' => $this->getUrl(),
@@ -154,11 +161,13 @@ class Item extends Entity implements IAPI, \JsonSerializable {
];
}
- public function getIntro() {
+ public function getIntro()
+ {
return strip_tags($this->getBody());
}
- public static function fromImport($import) {
+ public static function fromImport($import)
+ {
$item = new static();
$item->setGuid($import['guid']);
$item->setGuidHash($import['guid']);
@@ -177,15 +186,18 @@ class Item extends Entity implements IAPI, \JsonSerializable {
return $item;
}
- public function setAuthor($name) {
+ public function setAuthor($name)
+ {
parent::setAuthor(strip_tags($name));
}
- public function setTitle($title) {
+ public function setTitle($title)
+ {
parent::setTitle(strip_tags($title));
}
- public function generateSearchIndex() {
+ public function generateSearchIndex()
+ {
$this->setSearchIndex(
mb_strtolower(
html_entity_decode(strip_tags($this->getBody())) .
@@ -199,36 +211,47 @@ class Item extends Entity implements IAPI, \JsonSerializable {
$this->setContentHash($this->computeContentHash());
}
- private function computeContentHash() {
- return md5($this->getTitle() . $this->getUrl() . $this->getBody() .
+ private function computeContentHash()
+ {
+ return md5(
+ $this->getTitle() . $this->getUrl() . $this->getBody() .
$this->getEnclosureLink() . $this->getEnclosureMime() .
- $this->getAuthor());
+ $this->getAuthor()
+ );
}
- private function computeFingerprint() {
- return md5($this->getTitle() . $this->getUrl() . $this->getBody() .
- $this->getEnclosureLink());
+ private function computeFingerprint()
+ {
+ return md5(
+ $this->getTitle() . $this->getUrl() . $this->getBody() .
+ $this->getEnclosureLink()
+ );
}
- public function setUrl($url) {
+ public function setUrl($url)
+ {
$url = trim($url);
if (strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0) {
parent::setUrl($url);
}
}
- public function setBody($body) {
+ public function setBody($body)
+ {
// FIXME: this should not happen if the target="_blank" is already
// on the link
- parent::setBody(str_replace(
- '<a', '<a target="_blank" rel="noreferrer"', $body
- ));
+ parent::setBody(
+ str_replace(
+ '<a', '<a target="_blank" rel="noreferrer"', $body
+ )
+ );
}
/**
* @return int
*/
- public function cropApiLastModified() {
+ public function cropApiLastModified()
+ {
$lastModified = $this->getLastModified();
if (strlen((string)$lastModified) > 10) {
return (int)substr($lastModified, 0, -6);
diff --git a/lib/Db/ItemMapper.php b/lib/Db/ItemMapper.php
index 777d0d392..57561928a 100644
--- a/lib/Db/ItemMapper.php
+++ b/lib/Db/ItemMapper.php
@@ -5,10 +5,10 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Db;
@@ -19,14 +19,17 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
-class ItemMapper extends NewsMapper {
+class ItemMapper extends NewsMapper
+{
- public function __construct(IDBConnection $db, Time $time) {
+ public function __construct(IDBConnection $db, Time $time)
+ {
parent::__construct($db, 'news_items', Item::class, $time);
}
private function makeSelectQuery($prependTo = '', $oldestFirst = false,
- $distinctFingerprint = false) {
+ $distinctFingerprint = false
+ ) {
if ($oldestFirst) {
$ordering = 'ASC';
} else {
@@ -48,11 +51,13 @@ class ItemMapper extends NewsMapper {
/**
* check if type is feed or all items should be shown
- * @param bool $showAll
- * @param int|null $type
+ *
+ * @param bool $showAll
+ * @param int|null $type
* @return string
*/
- private function buildStatusQueryPart($showAll, $type = null) {
+ private function buildStatusQueryPart($showAll, $type = null)
+ {
$sql = '';
if (isset($type) && $type === FeedType::STARRED) {
@@ -66,34 +71,40 @@ class ItemMapper extends NewsMapper {
return $sql;
}
- private function buildSearchQueryPart(array $search = []) {
+ private function buildSearchQueryPart(array $search = [])
+ {
return str_repeat('AND `items`.`search_index` LIKE ? ', count($search));
}
/**
* wrap and escape search parameters in a like statement
*
- * @param string[] $search an array of strings that should be searched
+ * @param string[] $search an array of strings that should be searched
* @return array with like parameters
*/
- private function buildLikeParameters($search = []) {
- return array_map(function ($param) {
- $param = addcslashes($param, '\\_%');
- return '%' . mb_strtolower($param, 'UTF-8') . '%';
- }, $search);
+ private function buildLikeParameters($search = [])
+ {
+ return array_map(
+ function ($param) {
+ $param = addcslashes($param, '\\_%');
+ return '%' . mb_strtolower($param, 'UTF-8') . '%';
+ }, $search
+ );
}
/**
- * @param int $id
+ * @param int $id
* @param string $userId
* @return \OCA\News\Db\Item
*/
- public function find($id, $userId) {
+ public function find($id, $userId)
+ {
$sql = $this->makeSelectQuery('AND `items`.`id` = ? ');
return $this->findEntity($sql, [$userId, $id]);
}
- public function starredCount($userId) {
+ public function starredCount($userId)
+ {
$sql = 'SELECT COUNT(*) AS size FROM `*PREFIX*news_items` `items` ' .
'JOIN `*PREFIX*news_feeds` `feeds` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
@@ -113,7 +124,8 @@ class ItemMapper extends NewsMapper {
}
- public function readAll($highestItemId, $time, $userId) {
+ public function readAll($highestItemId, $time, $userId)
+ {
$sql = 'UPDATE `*PREFIX*news_items` ' .
'SET unread = ? ' .
', `last_modified` = ? ' .
@@ -127,7 +139,8 @@ class ItemMapper extends NewsMapper {
}
- public function readFolder($folderId, $highestItemId, $time, $userId) {
+ public function readFolder($folderId, $highestItemId, $time, $userId)
+ {
$sql = 'UPDATE `*PREFIX*news_items` ' .
'SET unread = ? ' .
', `last_modified` = ? ' .
@@ -143,7 +156,8 @@ class ItemMapper extends NewsMapper {
}
- public function readFeed($feedId, $highestItemId, $time, $userId) {
+ public function readFeed($feedId, $highestItemId, $time, $userId)
+ {
$sql = 'UPDATE `*PREFIX*news_items` ' .
'SET unread = ? ' .
', `last_modified` = ? ' .
@@ -160,7 +174,8 @@ class ItemMapper extends NewsMapper {
}
- private function getOperator($oldestFirst) {
+ private function getOperator($oldestFirst)
+ {
if ($oldestFirst) {
return '>';
} else {
@@ -169,7 +184,8 @@ class ItemMapper extends NewsMapper {
}
- public function findAllNew($updatedSince, $type, $showAll, $userId) {
+ public function findAllNew($updatedSince, $type, $showAll, $userId)
+ {
$sql = $this->buildStatusQueryPart($showAll, $type);
$sql .= 'AND `items`.`last_modified` >= ? ';
@@ -179,7 +195,8 @@ class ItemMapper extends NewsMapper {
}
- public function findAllNewFolder($id, $updatedSince, $showAll, $userId) {
+ public function findAllNewFolder($id, $updatedSince, $showAll, $userId)
+ {
$sql = $this->buildStatusQueryPart($showAll);
$sql .= 'AND `feeds`.`folder_id` = ? ' .
@@ -190,7 +207,8 @@ class ItemMapper extends NewsMapper {
}
- public function findAllNewFeed($id, $updatedSince, $showAll, $userId) {
+ public function findAllNewFeed($id, $updatedSince, $showAll, $userId)
+ {
$sql = $this->buildStatusQueryPart($showAll);
$sql .= 'AND `items`.`feed_id` = ? ' .
@@ -201,7 +219,8 @@ class ItemMapper extends NewsMapper {
}
- private function findEntitiesIgnoringNegativeLimit($sql, $params, $limit) {
+ private function findEntitiesIgnoringNegativeLimit($sql, $params, $limit)
+ {
// ignore limit if negative to offer a way to return all feeds
if ($limit >= 0) {
return $this->findEntities($sql, $params, $limit);
@@ -212,7 +231,8 @@ class ItemMapper extends NewsMapper {
public function findAllFeed($id, $limit, $offset, $showAll, $oldestFirst,
- $userId, $search = []) {
+ $userId, $search = []
+ ) {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
$params[] = $id;
@@ -232,7 +252,8 @@ class ItemMapper extends NewsMapper {
public function findAllFolder($id, $limit, $offset, $showAll, $oldestFirst,
- $userId, $search = []) {
+ $userId, $search = []
+ ) {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
$params[] = $id;
@@ -252,7 +273,8 @@ class ItemMapper extends NewsMapper {
public function findAll($limit, $offset, $type, $showAll, $oldestFirst, $userId,
- $search = []) {
+ $search = []
+ ) {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
$sql = $this->buildStatusQueryPart($showAll, $type);
@@ -270,7 +292,8 @@ class ItemMapper extends NewsMapper {
}
- public function findAllUnreadOrStarred($userId) {
+ public function findAllUnreadOrStarred($userId)
+ {
$params = [$userId, true, true];
$sql = 'AND (`items`.`unread` = ? OR `items`.`starred` = ?) ';
$sql = $this->makeSelectQuery($sql);
@@ -278,10 +301,12 @@ class ItemMapper extends NewsMapper {
}
- public function findByGuidHash($guidHash, $feedId, $userId) {
+ public function findByGuidHash($guidHash, $feedId, $userId)
+ {
$sql = $this->makeSelectQuery(
'AND `items`.`guid_hash` = ? ' .
- 'AND `feeds`.`id` = ? ');
+ 'AND `feeds`.`id` = ? '
+ );
return $this->findEntity($sql, [$userId, $guidHash, $feedId]);
}
@@ -290,9 +315,11 @@ class ItemMapper extends NewsMapper {
/**
* Delete all items for feeds that have over $threshold unread and not
* starred items
+ *
* @param int $threshold the number of items that should be deleted
*/
- public function deleteReadOlderThanThreshold($threshold) {
+ public function deleteReadOlderThanThreshold($threshold)
+ {
$params = [false, false, $threshold];
$sql = 'SELECT (COUNT(*) - `feeds`.`articles_per_update`) AS `size`, ' .
@@ -332,7 +359,8 @@ class ItemMapper extends NewsMapper {
}
- public function getNewestItemId($userId) {
+ public function getNewestItemId($userId)
+ {
$sql = 'SELECT MAX(`items`.`id`) AS `max_id` ' .
'FROM `*PREFIX*news_items` `items` ' .
'JOIN `*PREFIX*news_feeds` `feeds` ' .
@@ -348,9 +376,11 @@ class ItemMapper extends NewsMapper {
/**
* Deletes all items of a user
+ *
* @param string $userId the name of the user
*/
- public function deleteUser($userId) {
+ public function deleteUser($userId)