summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-08-18 03:16:40 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-08-18 03:16:40 -0400
commit41c310c5fc3790d7e5f6cb4862f5b09537002ffb (patch)
tree396019cb69168fe99be8859f56a5a41f7cc95cf3 /lib
parent455e8380f33bc7b4d7658e2ea153aae8a250b318 (diff)
perform only a slim fetch in some cases
Diffstat (limited to 'lib')
-rw-r--r--lib/feedmapper.php32
-rw-r--r--lib/utils.php30
2 files changed, 56 insertions, 6 deletions
diff --git a/lib/feedmapper.php b/lib/feedmapper.php
index dfc0d6054..e3d8fa67f 100644
--- a/lib/feedmapper.php
+++ b/lib/feedmapper.php
@@ -173,10 +173,12 @@ class FeedMapper {
$l = \OC_L10N::get('news');
$title = $l->t('no title');
}
-
+
+ $favicon = $feed->getFavicon();
+
//FIXME: Detect when feed contains already a database id
$feedid = $this->findIdFromUrl($url);
- if ($feedid == null){
+ if ($feedid === null){
$query = \OCP\DB::prepare("
INSERT INTO " . self::tableName .
"(url, url_hash, title, favicon_link, folder_id, user_id, added, lastmodified)
@@ -187,7 +189,7 @@ class FeedMapper {
$url,
$url_hash,
$title,
- $feed->getFavicon(),
+ $favicon,
$folderid,
$this->userid
);
@@ -195,17 +197,35 @@ class FeedMapper {
$feedid = \OCP\DB::insertid(self::tableName);
}
+ else {
+ //update the db. it needs to be done, since it might be the first save after a full fetch
+ $stmt = \OCP\DB::prepare('
+ UPDATE ' . self::tableName .
+ ' SET favicon_link = ? , lastmodified = ?
+ WHERE id = ?
+ ');
+
+ $params=array(
+ $favicon,
+ $_ut,
+ $feedid
+ );
+ $stmt->execute($params);
+ }
$feed->setId($feedid);
$itemMapper = new ItemMapper();
$items = $feed->getItems();
- foreach($items as $item){
- $itemMapper->save($item, $feedid);
+ if ($items !== null) {
+ foreach($items as $item){
+ $itemMapper->save($item, $feedid);
+ }
}
-
+
return $feedid;
}
+
public function deleteById($id){
if ($id == null) {
diff --git a/lib/utils.php b/lib/utils.php
index 28b77e155..cc4dac232 100644
--- a/lib/utils.php
+++ b/lib/utils.php
@@ -98,6 +98,36 @@ class Utils {
}
}
+ /**
+ * Perform a "slim" fetch of a feed from remote.
+ * Differently from Utils::fetch(), it doesn't retrieve items nor a favicon
+ *
+ * @param url remote url of the feed
+ * @returns an instance of OC_News_Feed
+ */
+ public static function slimFetch($url){
+ $spfeed = new \SimplePie_Core();
+ $spfeed->set_feed_url( $url );
+ $spfeed->enable_cache( false );
+ $spfeed->set_stupidly_fast( true );
+
+ if (!$spfeed->init()) {
+ return null;
+ }
+
+ //temporary try-catch to bypass SimplePie bugs
+ try {
+ $title = $spfeed->get_title();
+
+ $feed = new Feed($url, $title);
+
+ return $feed;
+ }
+ catch (Exception $e) {
+ return null;
+ }
+ }
+
public static function checkFavicon($favicon) {
$file = new \SimplePie_File($favicon);
// size in bytes