Skip to content

Commit

Permalink
Add updatedDate to item model (#43)
Browse files Browse the repository at this point in the history
* Update picoFeed to 0.1.25

* Add updated_date to database

* Add updatedDate to item model

* Bump version to 9.0.5

* Check for updatedDate when updating a feed

* Fix unit test to check for newer updatedDate
  • Loading branch information
schaal authored and BernhardPosselt committed Oct 1, 2016
1 parent f46ed33 commit e45511f
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 10 deletions.
7 changes: 7 additions & 0 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@
<unsigned>true</unsigned>
<notnull>false</notnull>
</field>
<field>
<name>updated_date</name>
<type>integer</type>
<length>8</length>
<unsigned>true</unsigned>
<notnull>false</notnull>
</field>
<field>
<name>body</name>
<type>clob</type>
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Before you update to a new version, [check the changelog](https://github.com/nextcloud/news/blob/master/CHANGELOG.md) to avoid surprises.
**Important**: To enable feed updates you will need to enable either [Nextcloud system cron](https://docs.nextcloud.com/server/10/admin_manual/configuration_server/background_jobs_configuration.html#cron) or use [an updater](https://github.com/owncloud/news-updater) which uses the built in update API and disable cron updates. More information can be found [in the README](https://github.com/nextcloud/news).]]></description>
<version>9.0.4</version>
<version>9.0.5</version>
<licence>agpl</licence>
<author>Bernhard Posselt</author>
<author>Alessandro Cosentino</author>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"require": {
"ezyang/htmlpurifier": "4.7",
"fguillot/picofeed": "0.1.23",
"fguillot/picofeed": "0.1.25",
"pear/net_url2": "2.2",
"riimu/kit-pathjoin": "1.1.2"
}
Expand Down
6 changes: 6 additions & 0 deletions lib/Db/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Item extends Entity implements IAPI, \JsonSerializable {
protected $title;
protected $author;
protected $pubDate;
protected $updatedDate;
protected $body;
protected $enclosureMime;
protected $enclosureLink;
Expand All @@ -69,6 +70,7 @@ class Item extends Entity implements IAPI, \JsonSerializable {

public function __construct() {
$this->addType('pubDate', 'integer');
$this->addType('updatedDate', 'integer');
$this->addType('feedId', 'integer');
$this->addType('status', 'integer');
$this->addType('rtl', 'boolean');
Expand Down Expand Up @@ -122,6 +124,7 @@ public function jsonSerialize() {
'title' => $this->getTitle(),
'author' => $this->getAuthor(),
'pubDate' => $this->getPubDate(),
'updatedDate' => $this->getUpdatedDate(),
'body' => $this->getBody(),
'enclosureMime' => $this->getEnclosureMime(),
'enclosureLink' => $this->getEnclosureLink(),
Expand All @@ -144,6 +147,7 @@ public function toAPI() {
'title' => $this->getTitle(),
'author' => $this->getAuthor(),
'pubDate' => $this->getPubDate(),
'updatedDate' => $this->getUpdatedDate(),
'body' => $this->getBody(),
'enclosureMime' => $this->getEnclosureMime(),
'enclosureLink' => $this->getEnclosureLink(),
Expand All @@ -164,6 +168,7 @@ public function toExport($feeds) {
'title' => $this->getTitle(),
'author' => $this->getAuthor(),
'pubDate' => $this->getPubDate(),
'updatedDate' => $this->getUpdatedDate(),
'body' => $this->getBody(),
'enclosureMime' => $this->getEnclosureMime(),
'enclosureLink' => $this->getEnclosureLink(),
Expand All @@ -186,6 +191,7 @@ public static function fromImport($import) {
$item->setTitle($import['title']);
$item->setAuthor($import['author']);
$item->setPubDate($import['pubDate']);
$item->setUpdatedDate($import['updatedDate']);
$item->setBody($import['body']);
$item->setEnclosureMime($import['enclosureMime']);
$item->setEnclosureLink($import['enclosureLink']);
Expand Down
3 changes: 2 additions & 1 deletion lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ protected function buildItem($parsedItem, $parsedFeed) {
$item->setUrl($parsedItem->getUrl());
$item->setGuid($parsedItem->getId());
$item->setGuidHash($item->getGuid());
$item->setPubDate($parsedItem->getDate()->getTimestamp());
$item->setPubDate($parsedItem->getPublishedDate()->getTimestamp());
$item->setUpdatedDate($parsedItem->getUpdatedDate()->getTimestamp());
$item->setRtl($this->determineRtl($parsedItem, $parsedFeed));

// unescape content because angularjs helps against XSS
Expand Down
3 changes: 2 additions & 1 deletion lib/Service/FeedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function update($feedId, $userId, $forceUpdate=false){

// in case of update
if ($forceUpdate ||
$item->getPubDate() > $dbItem->getPubDate()) {
$item->getUpdatedDate() > $dbItem->getUpdatedDate()) {

$dbItem->setTitle($item->getTitle());
$dbItem->setUrl($item->getUrl());
Expand All @@ -255,6 +255,7 @@ public function update($feedId, $userId, $forceUpdate=false){
$dbItem->setRtl($item->getRtl());
$dbItem->setLastModified($item->getLastModified());
$dbItem->setPubDate($item->getPubDate());
$dbItem->setUpdatedDate($item->getUpdatedDate());
$dbItem->setEnclosureMime($item->getEnclosureMime());
$dbItem->setEnclosureLink($item->getEnclosureLink());
$dbItem->setBody(
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Controller/ExportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public function testGetAllArticles(){
);

$this->assertEquals('[{"guid":null,"url":null,"title":null,' .
'"author":null,"pubDate":null,"body":null,"enclosureMime":null,' .
'"author":null,"pubDate":null,"updatedDate":null,"body":null,"enclosureMime":null,' .
'"enclosureLink":null,"unread":false,"starred":false,' .
'"feedLink":"http:\/\/goo","rtl":null},{"guid":null,"url":null,' .
'"title":null,"author":null,"pubDate":null,"body":null,' .
'"title":null,"author":null,"pubDate":null,"updatedDate":null,"body":null,' .
'"enclosureMime":null,"enclosureLink":null,"unread":false,' .
'"starred":false,"feedLink":"http:\/\/gee","rtl":null}]',
$return->render());
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Db/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function testToAPI() {
$item->setTitle('title');
$item->setAuthor('author');
$item->setPubDate(123);
$item->setUpdatedDate(234);
$item->setBody('body');
$item->setEnclosureMime('audio/ogg');
$item->setEnclosureLink('enclink');
Expand All @@ -81,6 +82,7 @@ public function testToAPI() {
'title' => 'title',
'author' => 'author',
'pubDate' => 123,
'updatedDate' => 234,
'body' => 'body',
'enclosureMime' => 'audio/ogg',
'enclosureLink' => 'enclink',
Expand All @@ -104,6 +106,7 @@ public function testJSONSerialize() {
$item->setTitle('title');
$item->setAuthor('author');
$item->setPubDate(123);
$item->setUpdatedDate(234);
$item->setBody('<body><div>this is a test</body>');
$item->setEnclosureMime('audio/ogg');
$item->setEnclosureLink('enclink');
Expand All @@ -123,6 +126,7 @@ public function testJSONSerialize() {
'title' => 'title',
'author' => 'author',
'pubDate' => 123,
'updatedDate' => 234,
'body' => '<body><div>this is a test</body>',
'enclosureMime' => 'audio/ogg',
'enclosureLink' => 'enclink',
Expand All @@ -145,6 +149,7 @@ public function testToExport() {
$item->setTitle('title');
$item->setAuthor('author');
$item->setPubDate(123);
$item->setUpdatedDate(234);
$item->setBody('body');
$item->setEnclosureMime('audio/ogg');
$item->setEnclosureLink('enclink');
Expand All @@ -165,6 +170,7 @@ public function testToExport() {
'title' => 'title',
'author' => 'author',
'pubDate' => 123,
'updatedDate' => 234,
'body' => 'body',
'enclosureMime' => 'audio/ogg',
'enclosureLink' => 'enclink',
Expand All @@ -184,6 +190,7 @@ private function createImportItem($isRead) {
$item->setTitle('title');
$item->setAuthor('author');
$item->setPubDate(123);
$item->setUpdatedDate(234);
$item->setBody('body');
$item->setEnclosureMime('audio/ogg');
$item->setEnclosureLink('enclink');
Expand Down Expand Up @@ -221,6 +228,7 @@ public function testFromImport() {
'title' => $item->getTitle(),
'author' => $item->getAuthor(),
'pubDate' => $item->getPubDate(),
'updatedDate' => $item->getUpdatedDate(),
'body' => $item->getBody(),
'enclosureMime' => $item->getEnclosureMime(),
'enclosureLink' => $item->getEnclosureLink(),
Expand All @@ -244,6 +252,7 @@ public function testFromImportRead() {
'title' => $item->getTitle(),
'author' => $item->getAuthor(),
'pubDate' => $item->getPubDate(),
'updatedDate' => $item->getUpdatedDate(),
'body' => $item->getBody(),
'enclosureMime' => $item->getEnclosureMime(),
'enclosureLink' => $item->getEnclosureLink(),
Expand Down
12 changes: 9 additions & 3 deletions tests/Unit/Fetcher/FeedFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
private $title;
private $guid;
private $pub;
private $updated;
private $body;
private $author;
private $enclosureLink;
Expand Down Expand Up @@ -110,6 +111,7 @@ protected function setUp(){
$this->body2 = 'let the bodies hit the floor ' .
'<a target="_blank" href="test">test</a>';
$this->pub = 23111;
$this->updated = 23444;
$this->author = '&lt;boogieman';
$this->enclosureLink = 'http://enclosure.you';

Expand Down Expand Up @@ -209,11 +211,15 @@ private function createItem($enclosureType=null) {
$item = new Item();

date_default_timezone_set('America/Los_Angeles');
$date = new \DateTime();
$date->setTimestamp($this->pub);
$this->expectItem('getDate', $date);

$pubdate = \Datetime::createFromFormat('U',$this->pub);
$this->expectItem('getPublishedDate', $pubdate);
$item->setPubDate($this->pub);

$update = \Datetime::createFromFormat('U',$this->updated);
$this->expectItem('getUpdatedDate', $update);
$item->setUpdatedDate($this->updated);

$item->setStatus(0);
$item->setUnread();
$item->setUrl($this->permalink);
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Service/FeedServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ private function createUpdateItem() {
$item->setGuidHash(md5('hi'));
$item->setFeedId(3);
$item->setPubDate(2);
$item->setUpdatedDate(2);
$item->setTitle('hey');
$item->setAuthor('aut');
$item->setBody('new');
Expand All @@ -396,14 +397,15 @@ private function createUpdateItem2() {
$item->setGuidHash(md5('hi'));
$item->setFeedId(3);
$item->setPubDate(1);
$item->setUpdatedDate(1);
$item->setTitle('ho');
$item->setAuthor('auto');
$item->setBody('old');
$item->setRead();
return $item;
}

public function testUpdateUpdatesWhenPubdateIsNewer() {
public function testUpdateUpdatesWhenUpdateddateIsNewer() {
$feed = $this->createUpdateFeed();
$item = $this->createUpdateItem();
$item2 = $this->createUpdateItem2();
Expand Down

0 comments on commit e45511f

Please sign in to comment.