Skip to content

Commit

Permalink
Add new field nextUpdateTime to feed
Browse files Browse the repository at this point in the history
Co-authored-by: Sean Molenaar <[email protected]>
Signed-off-by: Benjamin Brahmer <[email protected]>
  • Loading branch information
Grotax and SMillerDev committed Dec 22, 2024
1 parent f68d17c commit 02ffadb
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 329 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
# Unreleased
## [25.x.x]
### Changed
- API add new field to Feed that indicates when the next update will be done "nextUpdateTime" (#2993)

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions docs/api/api-v1-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ The following attributes are **not sanitized** meaning: including them in your w
"added": 1367063790,
"folderId": 4,
"unreadCount": 9,
"nextUpdateTime": 2071387335,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
"link": "http://theoatmeal.com/",
"pinned": true // if a feed should be sorted before other feeds, added in 6.0.3,
Expand Down Expand Up @@ -341,6 +342,7 @@ Creates a new feed and returns the feed
"title": "The Oatmeal - Comics, Quizzes, & Stories",
"faviconLink": "http://theoatmeal.com/favicon.ico",
"added": 1367063790,
"nextUpdateTime": 2071387335,
"folderId": 4,
"unreadCount": 9,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
Expand Down
2 changes: 2 additions & 0 deletions docs/api/api-v1-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ The following attributes are **not sanitized** meaning: including them in your w
"title": "The Oatmeal - Comics, Quizzes, & Stories",
"faviconLink": "http://theoatmeal.com/favicon.ico",
"added": 1367063790,
"nextUpdateTime": 2071387335,
"folderId": 4,
"unreadCount": 9,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
Expand Down Expand Up @@ -341,6 +342,7 @@ Creates a new feed and returns the feed
"title": "The Oatmeal - Comics, Quizzes, & Stories",
"faviconLink": "http://theoatmeal.com/favicon.ico",
"added": 1367063790,
"nextUpdateTime": 2071387335,
"folderId": 4,
"unreadCount": 9,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
Expand Down
29 changes: 26 additions & 3 deletions lib/Db/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Feed extends Entity implements IAPI, \JsonSerializable
protected $basicAuthUser = '';
/** @var string|null */
protected $basicAuthPassword = '';
/** @var int|null */
protected ?int $nextUpdateTime = null;
/** @var Item[] */
public $items = [];

Expand Down Expand Up @@ -110,6 +112,7 @@ public function __construct()
$this->addType('lastUpdateError', 'string');
$this->addType('basicAuthUser', 'string');
$this->addType('basicAuthPassword', 'string');
$this->addType('nextUpdateTime', 'int');
}

/**
Expand Down Expand Up @@ -296,6 +299,14 @@ public function getUserId(): string
return $this->userId;
}

/**
* @return int|null
*/
public function getNextUpdateTime(): ?int
{
return $this->nextUpdateTime;
}

/**
* Turns entity attributes into an array
*/
Expand Down Expand Up @@ -323,7 +334,8 @@ public function jsonSerialize(): array
'updateErrorCount',
'lastUpdateError',
'basicAuthUser',
'basicAuthPassword'
'basicAuthPassword',
'nextUpdateTime'
]);

if (is_null($this->link)) {
Expand Down Expand Up @@ -648,6 +660,15 @@ public function setUserId(string $userId): Feed
return $this;
}

/**
* @param int $nextUpdateTime
*/
public function setNextUpdateTime(?int $nextUpdateTime): void
{
$this->nextUpdateTime = $nextUpdateTime;
$this->markFieldUpdated('nextUpdateTime');
}

public function toAPI(): array
{
return $this->serializeFields(
Expand All @@ -664,7 +685,8 @@ public function toAPI(): array
'pinned',
'updateErrorCount',
'lastUpdateError',
'items'
'items',
'nextUpdateTime'
]
);
}
Expand All @@ -679,7 +701,8 @@ public function toAPI2(bool $reduced = false): array
'ordering' => $this->getOrdering(),
'fullTextEnabled' => $this->getFullTextEnabled(),
'updateMode' => $this->getUpdateMode(),
'isPinned' => $this->getPinned()
'isPinned' => $this->getPinned(),
'nextUpdateTime' => $this->getNextUpdateTime(),
];

if (!is_null($this->getLastUpdateError()) || trim($this->getLastUpdateError()) !== '') {
Expand Down
2 changes: 2 additions & 0 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public function fetch(
$location
);

$feed->setNextUpdateTime($resource->getNextUpdate()?->getTimestamp());

if (!is_null($resource->getResponse()->getLastModified())) {
$feed->setHttpLastModified($resource->getResponse()->getLastModified()->format(DateTime::RSS));
} elseif (!is_null($lastModified)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version250000Date20240817095614.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
* allows the title of a news feed to be null
*/
class Version250000Date20240817095614 extends SimpleMigrationStep {

Expand Down
56 changes: 56 additions & 0 deletions lib/Migration/Version250200Date20241219085150.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\News\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Adds the next_update_time column to the feeds table
*/
class Version250200Date20241219085150 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

$table = $schema->getTable('news_feeds');
if (!$table->hasColumn('next_update_time')) {
$table->addColumn('next_update_time', 'bigint', [
'notnull' => false
]);
}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
7 changes: 5 additions & 2 deletions tests/Unit/Db/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function testToAPI()
'updateErrorCount' => 2,
'lastUpdateError' => 'hi',
'items' => [],
'nextUpdateTime' => ''
],
$feed->toAPI()
);
Expand All @@ -86,7 +87,8 @@ public function testToAPI2()
'error' => [
'code' => 1,
'message' => 'hi'
]
],
'nextUpdateTime' => '',
],
$feed->toAPI2()
);
Expand Down Expand Up @@ -121,7 +123,8 @@ public function testSerialize()
'updateErrorCount' => 2,
'lastUpdateError' => 'hi',
'basicAuthUser' => 'user',
'basicAuthPassword' => 'password'
'basicAuthPassword' => 'password',
'nextUpdateTime' => '',
],
$feed->jsonSerialize()
);
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Fetcher/FeedFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ private function createFeed($lang = 'de-DE', $url = null)
$feed->setLocation($this->location);
$feed->setUrl($url);
$feed->setAdded($this->time);
$feed->setNextUpdateTime(0);

$feed->setFaviconLink('http://anon.google.com');
$this->favicon->expects($this->exactly(1))
Expand Down
6 changes: 6 additions & 0 deletions tests/api/feeds.bats
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ teardown() {
done
}

@test "[$TESTSUITE] Create Feed and check for nextUpdateTime {
# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | jq '.feeds | .[0].nextUpdateTime')
assert_output '2071387335'
}
22 changes: 11 additions & 11 deletions tests/test_helper/feeds/Nextcloud.rss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<atom:link href="http://localhost:8090/Nextcloud.rss" rel="self" type="application/rss+xml" />
<link>https://nextcloud.com/</link>
<description></description>
<lastBuildDate>Tue, 16 Aug 2099 10:17:13 +0000</lastBuildDate>
<lastBuildDate>Tue, 16 Aug 2035 10:17:13 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>
hourly </sy:updatePeriod>
Expand All @@ -32,7 +32,7 @@
<link>https://nextcloud.com/blog/how-to-get-started-with-nextcloud-repeat/</link>

<dc:creator><![CDATA[Fabrice Mous]]></dc:creator>
<pubDate>Tue, 16 Aug 2099 09:44:01 +0000</pubDate>
<pubDate>Tue, 16 Aug 2035 09:44:01 +0000</pubDate>
<category><![CDATA[business]]></category>
<category><![CDATA[News]]></category>
<category><![CDATA[Webinar]]></category>
Expand Down Expand Up @@ -116,7 +116,7 @@
<link>https://nextcloud.com/blog/openproject-and-nextcloud-integrate-project-management-and-file-management/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Mon, 15 Aug 2099 12:44:53 +0000</pubDate>
<pubDate>Mon, 15 Aug 2035 12:44:53 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[business]]></category>
<category><![CDATA[partner]]></category>
Expand Down Expand Up @@ -160,7 +160,7 @@
<link>https://nextcloud.com/blog/5-more-things-to-keep-your-data-safe/</link>

<dc:creator><![CDATA[Mikaela Schneider]]></dc:creator>
<pubDate>Wed, 10 Aug 2099 09:06:12 +0000</pubDate>
<pubDate>Wed, 10 Aug 2035 09:06:12 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[Community]]></category>
<category><![CDATA[general]]></category>
Expand Down Expand Up @@ -360,7 +360,7 @@
<link>https://nextcloud.com/blog/digital-sovereignty-security-collabora-online-nextcloud/</link>

<dc:creator><![CDATA[Fabrice Mous]]></dc:creator>
<pubDate>Thu, 04 Aug 2099 13:07:21 +0000</pubDate>
<pubDate>Thu, 04 Aug 2035 13:07:21 +0000</pubDate>
<category><![CDATA[business]]></category>
<category><![CDATA[News]]></category>
<category><![CDATA[Webinar]]></category>
Expand Down Expand Up @@ -444,7 +444,7 @@
<link>https://nextcloud.com/blog/nextcloud-keeps-growth-up-with-75-more-revenue-and-10x-userbase/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Thu, 04 Aug 2099 09:40:29 +0000</pubDate>
<pubDate>Thu, 04 Aug 2035 09:40:29 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[business]]></category>
<category><![CDATA[general]]></category>
Expand Down Expand Up @@ -506,7 +506,7 @@
<link>https://nextcloud.com/blog/baden-wurttemberg-procurement-chamber-decides-us-cloud-services-are-not-gdpr-compliant/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Mon, 01 Aug 2099 09:00:00 +0000</pubDate>
<pubDate>Mon, 01 Aug 2035 09:00:00 +0000</pubDate>
<category><![CDATA[business]]></category>
<category><![CDATA[general]]></category>
<category><![CDATA[News]]></category>
Expand Down Expand Up @@ -553,7 +553,7 @@
<link>https://nextcloud.com/blog/interview-shadow-and-a-world-where-5-companies-own-all-data/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Mon, 01 Aug 2099 07:43:56 +0000</pubDate>
<pubDate>Mon, 01 Aug 2035 07:43:56 +0000</pubDate>
<category><![CDATA[general]]></category>
<category><![CDATA[News]]></category>
<category><![CDATA[partner]]></category>
Expand All @@ -579,7 +579,7 @@
<link>https://nextcloud.com/blog/all-app-developers-put-your-hands-up-best-nextcloud-app-contest-2/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Thu, 28 Jul 2099 09:00:00 +0000</pubDate>
<pubDate>Thu, 28 Jul 2035 09:00:00 +0000</pubDate>
<category><![CDATA[Apps]]></category>
<category><![CDATA[Community]]></category>
<category><![CDATA[conference]]></category>
Expand Down Expand Up @@ -715,7 +715,7 @@
<link>https://nextcloud.com/blog/5-unique-security-features-by-nextcloud/</link>

<dc:creator><![CDATA[Mikaela Schneider]]></dc:creator>
<pubDate>Wed, 27 Jul 2099 14:36:15 +0000</pubDate>
<pubDate>Wed, 27 Jul 2035 14:36:15 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[general]]></category>
<category><![CDATA[Privacy Wednesday]]></category>
Expand Down Expand Up @@ -879,7 +879,7 @@
<comments>https://nextcloud.com/blog/nextcloud-in-the-wall-street-journal-microsoft-and-cookies/#comments</comments>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Wed, 27 Jul 2099 09:12:45 +0000</pubDate>
<pubDate>Wed, 27 Jul 2035 09:12:45 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[business]]></category>
<category><![CDATA[general]]></category>
Expand Down
Loading

0 comments on commit 02ffadb

Please sign in to comment.