diff options
-rw-r--r-- | bl/feedbl.php | 21 | ||||
-rw-r--r-- | tests/bl/FeedBlTest.php | 27 | ||||
-rw-r--r-- | tests/utility/FetcherTest.php | 1 | ||||
-rw-r--r-- | utility/feedfetcher.php | 4 | ||||
-rw-r--r-- | utility/ifeedfetcher.php | 2 |
5 files changed, 31 insertions, 24 deletions
diff --git a/bl/feedbl.php b/bl/feedbl.php index 0bd0e9e0d..661f1f8f5 100644 --- a/bl/feedbl.php +++ b/bl/feedbl.php @@ -111,33 +111,32 @@ class FeedBl extends Bl { // newest item for($i=count($items)-1; $i>=0; $i--){ $item = $items[$i]; + $item->setFeedId($feed->getId()); - // if a database exception is being thrown the unique constraint - // on the item guid hash is being violated and we need to update - // the item + // if a doesnotexist exception is being thrown the entry does not + // exist and the item needs to be created, otherwise + // update it try { - $item->setFeedId($feed->getId()); - $this->itemMapper->insert($item); - } catch(\DatabaseException $ex){ + $existing = $this->itemMapper->findByGuidHash( + $item->getGuidHash(), $feedId, $userId); // in case of an update the existing item has to be deleted // if the pub_date changed because we sort by id on the // client side since this is the only reliable way to do it // to not get weird behaviour - $existing = $this->itemMapper->findByGuidHash( - $item->getGuidHash(), $feedId, $userId); - if($existing->getPubDate() !== $item->getPubDate()){ // because the item is being replaced we need to keep - // status flags + // status flags but we want the new entry to be unread $item->setStatus($existing->getStatus()); $item->setUnread(); $this->itemMapper->delete($existing); $this->itemMapper->insert($item); } - + + } catch(DoesNotExistException $ex){ + $this->itemMapper->insert($item); } } diff --git a/tests/bl/FeedBlTest.php b/tests/bl/FeedBlTest.php index 9a9bd2002..818562fb9 100644 --- a/tests/bl/FeedBlTest.php +++ b/tests/bl/FeedBlTest.php @@ -146,10 +146,13 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { $item = new Item(); $item->setGuidHash(md5('hi')); + $item->setFeedId(3); $items = array( $item ); + $ex = new DoesNotExistException('hi'); + $fetchReturn = array($feed, $items); $this->mapper->expects($this->once()) @@ -161,9 +164,15 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('fetch') ->will($this->returnValue($fetchReturn)); $this->itemMapper->expects($this->once()) + ->method('findByGuidHash') + ->with($this->equalTo($items[0]->getGuidHash()), + $this->equalTo($items[0]->getFeedId()), + $this->equalTo($this->user)) + ->will($this->throwException($ex)); + $this->itemMapper->expects($this->once()) ->method('insert') ->with($this->equalTo($items[0])); - + $this->bl->update($feed->getId(), $this->user); } @@ -192,15 +201,15 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { ->method('fetch') ->will($this->returnValue($fetchReturn)); $this->itemMapper->expects($this->once()) - ->method('insert') - ->with($this->equalTo($items[0])) - ->will($this->throwException($ex)); - $this->itemMapper->expects($this->once()) ->method('findByGuidHash') ->with($this->equalTo($item->getGuidHash()), $this->equalTo($feed->getId()), $this->equalTo($this->user)) ->will($this->returnValue($item)); + $this->itemMapper->expects($this->never()) + ->method('insert'); + $this->itemMapper->expects($this->never()) + ->method('delete'); $this->bl->update($feed->getId(), $this->user); } @@ -233,20 +242,16 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility { $this->fetcher->expects($this->once()) ->method('fetch') ->will($this->returnValue($fetchReturn)); - $this->itemMapper->expects($this->at(0)) - ->method('insert') - ->with($this->equalTo($items[0])) - ->will($this->throwException($ex)); $this->itemMapper->expects($this->once()) ->method('findByGuidHash') ->with($this->equalTo($item->getGuidHash()), $this->equalTo($feed->getId()), $this->equalTo($this->user)) ->will($this->returnValue($item2)); - $this->itemMapper->expects($this->at(2)) + $this->itemMapper->expects($this->at(1)) ->method('delete') ->with($this->equalTo($item2)); - $this->itemMapper->expects($this->at(3)) + $this->itemMapper->expects($this->at(2)) ->method('insert') ->with($this->equalTo($item)); diff --git a/tests/utility/FetcherTest.php b/tests/utility/FetcherTest.php index 0da3b9265..bbf2622e8 100644 --- a/tests/utility/FetcherTest.php +++ b/tests/utility/FetcherTest.php @@ -75,6 +75,7 @@ class FetcherTest extends \OCA\AppFramework\Utility\TestUtility { $this->fetcher->fetch($url); } + public function testMultipleFetchersOnlyOneShouldHandle(){ $url = 'hi'; $return = 'zeas'; diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php index bf8cbd35b..54c416d71 100644 --- a/utility/feedfetcher.php +++ b/utility/feedfetcher.php @@ -125,7 +125,7 @@ class FeedFetcher implements IFeedFetcher { } - public function checkFavicon($favicon) { + private function checkFavicon($favicon) { if ($favicon === null || $favicon == false) return false; @@ -146,7 +146,7 @@ class FeedFetcher implements IFeedFetcher { } - public function discoverFavicon($url) { + private function discoverFavicon($url) { //try webroot favicon $favicon = \SimplePie_Misc::absolutize_url('/favicon.ico', $url); diff --git a/utility/ifeedfetcher.php b/utility/ifeedfetcher.php index 765a8e91f..2bf663c0f 100644 --- a/utility/ifeedfetcher.php +++ b/utility/ifeedfetcher.php @@ -30,6 +30,7 @@ interface IFeedFetcher { /** * @param string url the url that the user entered in the add feed dialog * box + * @throws FetcherException if the fetcher encounters a problem * @return array with the first element being the feed and the * second element being an array of items. Those items will be saved into * into the database @@ -42,4 +43,5 @@ interface IFeedFetcher { * used exclusively to fetch the feed and the items of the page */ function canHandle($url); + }
\ No newline at end of file |