summaryrefslogtreecommitdiffstats
path: root/lib/Db/Mysql
diff options
context:
space:
mode:
authorDaniel Opitz <danopz@users.noreply.github.com>2017-08-14 10:34:53 +0200
committerBernhard Posselt <BernhardPosselt@users.noreply.github.com>2017-08-14 10:34:53 +0200
commita97dd58e3b499b60ac8b37786d402d7f2e371a88 (patch)
tree98bb8a6c750fb33fbef38d22407fa29fbf6c7b1e /lib/Db/Mysql
parent7d8a85c82c4c13a71b70ddb4ecb8c40ede4c9b70 (diff)
Split binary to booleans (#203)
* replaced old status with 2 flags for unread and starred * add fields to db, replace int(1,0) with booleans in sql queries, removed StatusFlags class + refactor code relying to it * add repair step for migration * again use integer(1,0) instead of bool in sql queries, because of sqlite doesn't support true/false * add/fix unit tests for new boolean status * set unread/starred flags as statements in sql * fixed mysql unknown column items.unread, fixed marking of read items on repair step * remove unnecessary bool casts * add empty checks to Items::is* methods * update migration to use native sql instead of the querybuilder * don't cast the flags manually, let the api do the work
Diffstat (limited to 'lib/Db/Mysql')
-rw-r--r--lib/Db/Mysql/ItemMapper.php23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/Db/Mysql/ItemMapper.php b/lib/Db/Mysql/ItemMapper.php
index 8053c3d87..ad373eafb 100644
--- a/lib/Db/Mysql/ItemMapper.php
+++ b/lib/Db/Mysql/ItemMapper.php
@@ -16,9 +16,6 @@ namespace OCA\News\Db\Mysql;
use OCA\News\Utility\Time;
use OCP\IDBConnection;
-use OCA\News\Db\StatusFlag;
-
-
class ItemMapper extends \OCA\News\Db\ItemMapper {
public function __construct(IDBConnection $db, Time $time){
@@ -29,19 +26,19 @@ class ItemMapper extends \OCA\News\Db\ItemMapper {
/**
* 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
+ * @param int $threshold the number of items that should be deleted
*/
public function deleteReadOlderThanThreshold($threshold){
- $status = StatusFlag::STARRED | StatusFlag::UNREAD;
$sql = 'SELECT (COUNT(*) - `feeds`.`articles_per_update`) AS `size`, ' .
'`feeds`.`id` AS `feed_id`, `feeds`.`articles_per_update` ' .
'FROM `*PREFIX*news_items` `items` ' .
'JOIN `*PREFIX*news_feeds` `feeds` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND NOT ((`items`.`status` & ?) > 0) ' .
+ 'AND `items`.`unread` = ? ' .
+ 'AND `items`.`starred` = ? ' .
'GROUP BY `feeds`.`id`, `feeds`.`articles_per_update` ' .
'HAVING COUNT(*) > ?';
- $params = [$status, $threshold];
+ $params = [false, false, $threshold];
$result = $this->execute($sql, $params);
while($row = $result->fetch()) {
@@ -50,10 +47,11 @@ class ItemMapper extends \OCA\News\Db\ItemMapper {
$limit = $size - $threshold;
if($limit > 0) {
- $params = [$status, $row['feed_id'], $limit];
+ $params = [false, false, $row['feed_id'], $limit];
$sql = 'DELETE FROM `*PREFIX*news_items` ' .
- 'WHERE NOT ((`status` & ?) > 0) ' .
+ 'WHERE `unread` = ? ' .
+ 'AND `starred` = ? ' .
'AND `feed_id` = ? ' .
'ORDER BY `id` ASC ' .
'LIMIT ?';
@@ -71,16 +69,15 @@ class ItemMapper extends \OCA\News\Db\ItemMapper {
$sql = 'UPDATE `*PREFIX*news_items` `items`
JOIN `*PREFIX*news_feeds` `feeds`
ON `feeds`.`id` = `items`.`feed_id`
- SET `items`.`status` = `items`.`status` & ?,
+ SET `items`.`unread` = ?,
`items`.`last_modified` = ?
WHERE `items`.`fingerprint` = ?
AND `feeds`.`user_id` = ?';
- $params = [~StatusFlag::UNREAD, $lastModified,
- $item->getFingerprint(), $userId];
+ $params = [false, $lastModified, $item->getFingerprint(), $userId];
$this->execute($sql, $params);
} else {
$item->setLastModified($lastModified);
- $item->setUnread();
+ $item->setUnread(true);
$this->update($item);
}
}