summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/feedmapper.php15
-rw-r--r--db/itemmapper.php10
-rw-r--r--tests/unit/db/FeedMapperTest.php35
-rw-r--r--tests/unit/db/ItemMapperTest.php53
4 files changed, 63 insertions, 50 deletions
diff --git a/db/feedmapper.php b/db/feedmapper.php
index f2c3a8ada..3c931aabb 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -43,11 +43,12 @@ class FeedMapper extends Mapper implements IMapper {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
+ $params = array($id, $userId);
$row = $this->findOneQuery($sql, $params);
$feed = new Feed();
@@ -76,10 +77,11 @@ class FeedMapper extends Mapper implements IMapper {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $userId);
+ $params = array($userId);
return $this->findAllRows($sql, $params);
}
@@ -97,11 +99,12 @@ class FeedMapper extends Mapper implements IMapper {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $hash, $userId);
+ $params = array($hash, $userId);
$row = $this->findOneQuery($sql, $params);
$feed = new Feed();
diff --git a/db/itemmapper.php b/db/itemmapper.php
index ca93a8b2a..daff18466 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -65,6 +65,11 @@ class ItemMapper extends Mapper implements IMapper {
// code: we take them variables and we cast the shit out of them
$status = (int) $status;
+ // prepare for the unexpected
+ if(!is_numeric($status)) {
+ die(); die(); die('If you can read this something is terribly wrong');
+ }
+
// now im gonna slowly stick them in the query, be careful!
return $this->makeSelectQuery(
'AND ((`items`.`status` & ' . $status . ') = ' . $status . ') ' .
@@ -89,9 +94,10 @@ class ItemMapper extends Mapper implements IMapper {
'JOIN `*PREFIX*news_items` `items` ' .
'ON `items`.`feed_id` = `feeds`.`id` ' .
'AND `feeds`.`user_id` = ? ' .
- 'WHERE ((`items`.`status` & ?) = ?)';
+ 'WHERE ((`items`.`status` & ' . StatusFlag::STARRED . ') = ' .
+ StatusFlag::STARRED . ')';
- $params = array($userId, StatusFlag::STARRED, StatusFlag::STARRED);
+ $params = array($userId);
$result = $this->execute($sql, $params)->fetchRow();
diff --git a/tests/unit/db/FeedMapperTest.php b/tests/unit/db/FeedMapperTest.php
index 58ea8c4ed..1f8d08ef8 100644
--- a/tests/unit/db/FeedMapperTest.php
+++ b/tests/unit/db/FeedMapperTest.php
@@ -60,11 +60,12 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
+ $params = array($id, $userId);
$this->setMapperResult($sql, $params, $rows);
$result = $this->mapper->find($id, $userId);
@@ -80,11 +81,12 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
+ $params = array($id, $userId);
$this->setMapperResult($sql, $params);
$this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
@@ -103,11 +105,12 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`id` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
- $params = array(StatusFlag::UNREAD, StatusFlag::UNREAD, $id, $userId);
+ $params = array($id, $userId);
$this->setMapperResult($sql, $params, $rows);
$this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
@@ -140,12 +143,13 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
$this->setMapperResult($sql,
- array(StatusFlag::UNREAD, StatusFlag::UNREAD, $userId), $rows);
+ array($userId), $rows);
$result = $this->mapper->findAllFromUser($userId);
$this->assertEquals($this->feeds, $result);
@@ -161,12 +165,13 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
$this->setMapperResult($sql,
- array(StatusFlag::UNREAD, StatusFlag::UNREAD, $urlHash, $this->user), $row);
+ array($urlHash, $this->user), $row);
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
$this->assertEquals($this->feeds[0], $result);
@@ -179,12 +184,13 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
$this->setMapperResult($sql,
- array(StatusFlag::UNREAD, StatusFlag::UNREAD, $urlHash, $this->user));
+ array($urlHash, $this->user));
$this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
@@ -201,12 +207,13 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'FROM `*PREFIX*news_feeds` `feeds` ' .
'LEFT JOIN `*PREFIX*news_items` `items` ' .
'ON `feeds`.`id` = `items`.`feed_id` ' .
- 'AND (`items`.`status` & ?) = ? ' .
+ 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' .
+ StatusFlag::UNREAD . ' ' .
'WHERE `feeds`.`url_hash` = ? ' .
'AND `feeds`.`user_id` = ? ' .
'GROUP BY `feeds`.`id`';
$this->setMapperResult($sql,
- array(StatusFlag::UNREAD, StatusFlag::UNREAD, $urlHash, $this->user), $rows);
+ array($urlHash, $this->user), $rows);
$this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index 9446f4256..ee3678b3d 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -78,9 +78,11 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'AND `feeds`.`user_id` = ? ' . $prependTo;
}
- private function makeSelectQueryStatus($prependTo) {
+ private function makeSelectQueryStatus($prependTo, $status) {
+ $status = (int) $status;
+
return $this->makeSelectQuery(
- 'AND ((`items`.`status` & ?) = ?) ' .
+ 'AND ((`items`.`status` & ' . $status . ') = ' . $status . ') ' .
$prependTo
);
}
@@ -105,10 +107,10 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'JOIN `*PREFIX*news_items` `items` ' .
'ON `items`.`feed_id` = `feeds`.`id` ' .
'AND `feeds`.`user_id` = ? ' .
- 'WHERE ((`items`.`status` & ?) = ?)';
+ 'WHERE ((`items`.`status` & ' . StatusFlag::STARRED . ') = '
+ . StatusFlag::STARRED . ')';
- $this->setMapperResult($sql, array($userId, StatusFlag::STARRED,
- StatusFlag::STARRED), $row);
+ $this->setMapperResult($sql, array($userId), $row);
$result = $this->mapper->starredCount($userId);
$this->assertEquals($row[0]['size'], $result);
@@ -131,9 +133,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllNew(){
$sql = 'AND `items`.`id` >= ?';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status,
- $this->updatedSince);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user, $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllNew($this->updatedSince,
@@ -146,9 +147,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllNewFeed(){
$sql = 'AND `items`.`feed_id` = ? ' .
'AND `items`.`id` >= ?';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status, $this->id,
- $this->updatedSince);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user, $this->id, $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllNewFeed($this->id, $this->updatedSince,
@@ -161,10 +161,9 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllNewFolder(){
$sql = 'AND `feeds`.`folder_id` = ? ' .
'AND `items`.`id` >= ?';
- $sql = $this->makeSelectQueryStatus($sql);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
- $params = array($this->user, $this->status, $this->status, $this->id,
- $this->updatedSince);
+ $params = array($this->user, $this->id, $this->updatedSince);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllNewFolder($this->id, $this->updatedSince,
$this->status, $this->user);
@@ -177,9 +176,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = 'AND `items`.`feed_id` = ? ' .
'AND `items`.`id` > ? ' .
'ORDER BY `items`.`id` DESC ';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status, $this->id,
- $this->offset);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user, $this->id, $this->offset);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFeed($this->id, $this->limit,
$this->offset, $this->status, $this->user);
@@ -191,8 +189,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllFeedOffsetZero(){
$sql = 'AND `items`.`feed_id` = ? ' .
'ORDER BY `items`.`id` DESC ';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status, $this->id);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user, $this->id);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFeed($this->id, $this->limit,
0, $this->status, $this->user);
@@ -205,8 +203,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$sql = 'AND `feeds`.`folder_id` = ? ' .
'AND `items`.`id` > ? ' .
'ORDER BY `items`.`id` DESC ';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status, $this->id,
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user, $this->id,
$this->offset);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFolder($this->id, $this->limit,
@@ -219,8 +217,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllFolderOffsetZero(){
$sql = 'AND `feeds`.`folder_id` = ? ' .
'ORDER BY `items`.`id` DESC ';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status, $this->id);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user, $this->id);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAllFolder($this->id, $this->limit,
0, $this->status, $this->user);
@@ -232,9 +230,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAll(){
$sql = 'AND `items`.`id` > ? ' .
'ORDER BY `items`.`id` DESC ';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status,
- $this->offset);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user, $this->offset);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAll($this->limit,
$this->offset, $this->status, $this->user);
@@ -245,8 +242,8 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFindAllOffsetZero(){
$sql = 'ORDER BY `items`.`id` DESC ';
- $sql = $this->makeSelectQueryStatus($sql);
- $params = array($this->user, $this->status, $this->status);
+ $sql = $this->makeSelectQueryStatus($sql, $this->status);
+ $params = array($this->user);
$this->setMapperResult($sql, $params, $this->rows);
$result = $this->mapper->findAll($this->limit,
0, $this->status, $this->user);