summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-05-30 15:35:51 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-05-30 15:35:51 -0400
commit39330d521b0cdc2a79fa57018438faa93bb6babf (patch)
tree78d72b9ef8f1cec3fe3377a7100d227f38674840 /lib
parenta6e57a9a1f4427de872c4bf0050cc0ee38d2adfe (diff)
not add same items twice
Diffstat (limited to 'lib')
-rw-r--r--lib/itemmapper.php60
1 files changed, 40 insertions, 20 deletions
diff --git a/lib/itemmapper.php b/lib/itemmapper.php
index 65f1eb2e2..09ebd6f09 100644
--- a/lib/itemmapper.php
+++ b/lib/itemmapper.php
@@ -47,35 +47,55 @@ class OC_News_ItemMapper {
return $items;
}
+ public function findIdFromGuid($guid, $feedid){
+ $stmt = OCP\DB::prepare('
+ SELECT * FROM ' . self::tableName . '
+ WHERE guid = ?
+ AND feedid = ?
+ ');
+ $result = $stmt->execute(array($guid, $feedid));
+ $row = $result->fetchRow();
+ $id = null;
+ if ($row != null){
+ $id = $row['id'];
+ }
+ return $id;
+ }
+
/**
* @brief Save the feed and all its items into the database
* @returns The id of the feed in the database table.
*/
public function insert(OC_News_Item $item, $feedid){
$guid = $item->getGuid();
- $title = $item->getTitle();
- $query = OCP\DB::prepare('
- INSERT INTO ' . self::tableName .
- '(url, title, guid, feedid)
- VALUES (?, ?, ?, ?)
- ');
+ $itemid = $this->findIdFromGuid($guid, $feedid);
+
+ if ($itemid == null){
+ $title = $item->getTitle();
+
+ $query = OCP\DB::prepare('
+ INSERT INTO ' . self::tableName .
+ '(url, title, guid, feedid)
+ VALUES (?, ?, ?, ?)
+ ');
- if(empty($title)) {
- $l = OC_L10N::get('news');
- $title = $l->t('no title');
- }
+ if(empty($title)) {
+ $l = OC_L10N::get('news');
+ $title = $l->t('no title');
+ }
- $params=array(
- htmlspecialchars_decode($item->getUrl()),
- htmlspecialchars_decode($title),
- $guid,
- $feedid
- );
-
- $query->execute($params);
-
- $itemid = OCP\DB::insertid(self::tableName);
+ $params=array(
+ htmlspecialchars_decode($item->getUrl()),
+ htmlspecialchars_decode($title),
+ $guid,
+ $feedid
+ );
+
+ $query->execute($params);
+
+ $itemid = OCP\DB::insertid(self::tableName);
+ }
$item->setId($itemid);
return $itemid;
}