summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-05-29 16:07:12 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-05-29 16:07:12 -0400
commita6e57a9a1f4427de872c4bf0050cc0ee38d2adfe (patch)
tree82f1a064079526950bcb7a9bbf9cd1262df93564
parent07fdf6ad3c3cc659a06099cd2011aab1ce2c8c5e (diff)
adds indices to database schema
-rw-r--r--appinfo/database.xml35
-rw-r--r--lib/feedmapper.php9
-rw-r--r--lib/item.php16
-rw-r--r--lib/itemmapper.php30
-rw-r--r--lib/utils.php3
5 files changed, 62 insertions, 31 deletions
diff --git a/appinfo/database.xml b/appinfo/database.xml
index 30f337e5b..7ef656da3 100644
--- a/appinfo/database.xml
+++ b/appinfo/database.xml
@@ -93,13 +93,23 @@
</field>
<index>
- <name>id</name>
+ <name>feed_id</name>
<unique>true</unique>
+ <primary>true</primary>
<field>
<name>id</name>
<sorting>descending</sorting>
</field>
</index>
+
+ <index>
+ <name>feed_url</name>
+ <unique>true</unique>
+ <primary>false</primary>
+ <field>
+ <name>url</name>
+ </field>
+ </index>
</declaration>
</table>
@@ -115,15 +125,19 @@
<length>4</length>
</field>
<field>
- <name>url</name>
+ <name>guid</name>
<type>text</type>
<notnull>true</notnull>
<length>100</length>
</field>
<field>
+ <name>url</name>
+ <type>text</type>
+ <length>100</length>
+ </field>
+ <field>
<name>title</name>
<type>text</type>
- <notnull>true</notnull>
<length>100</length>
</field>
<field>
@@ -132,15 +146,28 @@
<notnull>true</notnull>
<length>4</length>
</field>
+ <field>
+ <name>body</name>
+ <type>text</type>
+ <length>4000</length>
+ </field>
<index>
- <name>id</name>
+ <name>item_id</name>
<unique>true</unique>
<field>
<name>id</name>
<sorting>descending</sorting>
</field>
</index>
+ <index>
+ <name>item_guid</name>
+ <unique>true</unique>
+ <field>
+ <name>guid</name>
+ <sorting>descending</sorting>
+ </field>
+ </index>
</declaration>
</table>
</database>
diff --git a/lib/feedmapper.php b/lib/feedmapper.php
index 7b148b142..a08d730b1 100644
--- a/lib/feedmapper.php
+++ b/lib/feedmapper.php
@@ -55,8 +55,8 @@ class OC_News_FeedMapper {
$title = $row['title'];
$feed = new OC_News_Feed($url, $title, null,$id);
- $itemMapper = new OC_News_ItemMapper($feed);
- $items = $itemMapper->findAll();
+ $itemMapper = new OC_News_ItemMapper();
+ $items = $itemMapper->findAll($id);
$feed->setItems($items);
return $feed;
@@ -103,7 +103,6 @@ class OC_News_FeedMapper {
}
//FIXME: Detect when feed contains already a database id
-
$feedid = $this->findIdFromUrl($url);
if ($feedid == null){
$query = OCP\DB::prepare('
@@ -125,11 +124,11 @@ class OC_News_FeedMapper {
}
$feed->setId($feedid);
- $itemMapper = new OC_News_ItemMapper($feed);
+ $itemMapper = new OC_News_ItemMapper();
$items = $feed->getItems();
foreach($items as $item){
- $itemMapper->insert($item);
+ $itemMapper->insert($item, $feedid);
}
return $feedid;
}
diff --git a/lib/item.php b/lib/item.php
index a5a49937c..e048e9d11 100644
--- a/lib/item.php
+++ b/lib/item.php
@@ -37,22 +37,32 @@ class OC_News_Item {
private $url;
private $title;
+ private $guid;
private $body;
private $status; //a bit-field set with status flags
private $id; //id of the item in the database table
- public function __construct($url, $title, $id = null){
+ public function __construct($url, $title, $guid, $id = null){
$this->title = $title;
$this->url = $url;
+ $this->guid = $guid;
$this->status |= StatusFlag::Unread;
}
+ public function getGuid(){
+ return $this->guid;
+ }
+
+ public function setGuid($guid){
+ $this->guid = $guid;
+ }
+
public function getId(){
- return $this->$id;;
+ return $this->id;
}
public function setId($id){
- $this->$id = $id;
+ $this->id = $id;
}
public function setRead(){
diff --git a/lib/itemmapper.php b/lib/itemmapper.php
index c8368ba9e..65f1eb2e2 100644
--- a/lib/itemmapper.php
+++ b/lib/itemmapper.php
@@ -20,25 +20,19 @@
*
*/
-/**
+/**e 49
* This class maps an item to a row of the items table in the database.
* It follows the Data Mapper pattern (see http://martinfowler.com/eaaCatalog/dataMapper.html).
*/
class OC_News_ItemMapper {
const tableName = '*PREFIX*news_items';
- private $feed;
-
- public function __construct(OC_News_Feed $feed){
- $this->feed = $feed;
- }
/**
- * @brief Retrieve an item from the database
- * @param id The id of the feed in the database table.
+ * @brief Retrieve all the item corresponding to a feed from the database
+ * @param feedid The id of the feed in the database table.
*/
- public function findAll(){
- $feedid = $this->feed->getId();
+ public function findAll($feedid){
$stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE feedid = ?');
$result = $stmt->execute(array($feedid));
@@ -46,7 +40,8 @@ class OC_News_ItemMapper {
while ($row = $result->fetchRow()) {
$url = $row['url'];
$title = $row['title'];
- $items[] = new OC_News_Item($url, $title);
+ $guid = $row['guid'];
+ $items[] = new OC_News_Item($url, $title, $guid);
}
return $items;
@@ -56,18 +51,16 @@ class OC_News_ItemMapper {
* @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 = $this->feed->getId();
+ public function insert(OC_News_Item $item, $feedid){
+ $guid = $item->getGuid();
+ $title = $item->getTitle();
$query = OCP\DB::prepare('
INSERT INTO ' . self::tableName .
- '(url, title, feedid)
- VALUES (?, ?, ?)
+ '(url, title, guid, feedid)
+ VALUES (?, ?, ?, ?)
');
- $title = $item->getTitle();
-
if(empty($title)) {
$l = OC_L10N::get('news');
$title = $l->t('no title');
@@ -76,6 +69,7 @@ class OC_News_ItemMapper {
$params=array(
htmlspecialchars_decode($item->getUrl()),
htmlspecialchars_decode($title),
+ $guid,
$feedid
);
diff --git a/lib/utils.php b/lib/utils.php
index e5ea27626..dd752aea4 100644
--- a/lib/utils.php
+++ b/lib/utils.php
@@ -41,7 +41,8 @@ class OC_News_Utils {
foreach($spitems as $spitem) { //FIXME: maybe we can avoid this loop
$itemUrl = $spitem->get_permalink();
$itemTitle = $spitem->get_title();
- $items[] = new OC_News_Item($itemUrl, $itemTitle);
+ $itemGUID = $spitem->get_id();
+ $items[] = new OC_News_Item($itemUrl, $itemTitle, $itemGUID);
}
$feed = new OC_News_Feed($url, $title, $items);