summaryrefslogtreecommitdiffstats
path: root/bl
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-25 12:54:38 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-25 12:54:38 +0100
commit0f9e0e3de77de68cc75ccd69395665f9e1346951 (patch)
treebe6398f7134c3192e4ee0f89a88cbbfadfffc808 /bl
parent77ec6f08aa4fb223fba859ca0f6060e84006da43 (diff)
implemented feed update
Diffstat (limited to 'bl')
-rw-r--r--bl/feedbl.php48
-rw-r--r--bl/itembl.php6
2 files changed, 42 insertions, 12 deletions
diff --git a/bl/feedbl.php b/bl/feedbl.php
index 1340de632..105a43a05 100644
--- a/bl/feedbl.php
+++ b/bl/feedbl.php
@@ -26,21 +26,28 @@
namespace OCA\News\Bl;
use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Core\API;
use \OCA\News\Db\Feed;
use \OCA\News\Db\FeedMapper;
+use \OCA\News\Db\ItemMapper;
use \OCA\News\Utility\FeedFetcher;
use \OCA\News\Utility\FetcherException;
class FeedBl extends Bl {
private $feedFetcher;
+ private $itemMapper;
+ private $api;
public function __construct(FeedMapper $feedMapper,
- FeedFetcher $feedFetcher, ItemBl $itemBl){
+ FeedFetcher $feedFetcher,
+ ItemMapper $itemMapper,
+ API $api){
parent::__construct($feedMapper);
$this->feedFetcher = $feedFetcher;
- $this->itemBl = $itemBl;
+ $this->itemMapper = $itemMapper;
+ $this->api = $api;
}
@@ -66,7 +73,7 @@ class FeedBl extends Bl {
// insert items
foreach($items as $item){
$item->setFeedId($feed->getId());
- $this->itemBl->create($item);
+ $this->itemMapper->insert($item);
}
return $feed;
@@ -75,17 +82,46 @@ class FeedBl extends Bl {
}
}
+
+ // FIXME: this method is not covered by any tests
public function updateAll(){
- // TODO: needs test
$feeds = $this->mapper->findAll();
foreach($feeds as $feed){
- $this->update($feed->getId(), $feed->getUser());
+ try {
+ $this->update($feed->getId(), $feed->getUser());
+ } catch(BLException $ex){
+ continue;
+ }
}
}
public function update($feedId, $userId){
- // TODO: update given feed
+ $feed = $this->mapper->find($feedId, $userId);
+ try {
+ list($feed, $items) = $this->feedFetcher->fetch($feed->getUrl());
+
+ // update items
+ foreach($items as $item){
+
+ // 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
+ try {
+ $item->setFeedId($feed->getId());
+ $this->itemMapper->insert($item);
+ } catch(\DatabaseException $ex){
+ $existing = $this->itemMapper->findByGuidHash(
+ $item->getGuidHash(), $userId);
+ $item->setId($existing->getId());
+ $this->itemMapper->update($item);
+ }
+ }
+
+ } catch(FetcherException $ex){
+ // failed updating is not really a problem, so only log it
+ $this->api->log('Can not update feed: Not found or bad source');
+ }
}
diff --git a/bl/itembl.php b/bl/itembl.php
index c45ee3a91..4a3f302c7 100644
--- a/bl/itembl.php
+++ b/bl/itembl.php
@@ -117,10 +117,4 @@ class ItemBl extends Bl {
}
- // ATTENTION: this does no validation and is only for creating
- // items from the fetcher
- public function create($item){
- $this->mapper->insert($item);
- }
-
}