Skip to content

Commit ed9fef2

Browse files
GrotaxSMillerDev
andcommitted
Add new field nextUpdateTime to feed
Co-authored-by: Sean Molenaar <[email protected]> Signed-off-by: Benjamin Brahmer <[email protected]>
1 parent dbdf8d1 commit ed9fef2

14 files changed

+428
-329
lines changed

.github/workflows/api-integration-tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ jobs:
107107
app: 'news'
108108
check-code: false
109109
force: ${{ matrix.experimental }}
110+
111+
- name: DEBUG print jq version and build configuration
112+
run: jq -V && jq --build-configuration
110113

111114
- name: Run API tests
112115
working-directory: ../server

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
77
# Unreleased
88
## [25.x.x]
99
### Changed
10+
- API add new field to Feed that indicates when the next update will be done "nextUpdateTime" (#2993)
1011

1112
### Fixed
1213

docs/api/api-v1-2.md

+2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ The following attributes are **not sanitized** meaning: including them in your w
294294
"added": 1367063790,
295295
"folderId": 4,
296296
"unreadCount": 9,
297+
"nextUpdateTime": 2071387335,
297298
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
298299
"link": "http://theoatmeal.com/",
299300
"pinned": true // if a feed should be sorted before other feeds, added in 6.0.3,
@@ -341,6 +342,7 @@ Creates a new feed and returns the feed
341342
"title": "The Oatmeal - Comics, Quizzes, & Stories",
342343
"faviconLink": "http://theoatmeal.com/favicon.ico",
343344
"added": 1367063790,
345+
"nextUpdateTime": 2071387335,
344346
"folderId": 4,
345347
"unreadCount": 9,
346348
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0

docs/api/api-v1-3.md

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ The following attributes are **not sanitized** meaning: including them in your w
292292
"title": "The Oatmeal - Comics, Quizzes, & Stories",
293293
"faviconLink": "http://theoatmeal.com/favicon.ico",
294294
"added": 1367063790,
295+
"nextUpdateTime": 2071387335,
295296
"folderId": 4,
296297
"unreadCount": 9,
297298
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
@@ -341,6 +342,7 @@ Creates a new feed and returns the feed
341342
"title": "The Oatmeal - Comics, Quizzes, & Stories",
342343
"faviconLink": "http://theoatmeal.com/favicon.ico",
343344
"added": 1367063790,
345+
"nextUpdateTime": 2071387335,
344346
"folderId": 4,
345347
"unreadCount": 9,
346348
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0

lib/Db/Feed.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class Feed extends Entity implements IAPI, \JsonSerializable
8383
protected $basicAuthUser = '';
8484
/** @var string|null */
8585
protected $basicAuthPassword = '';
86+
/** @var int|null */
87+
protected ?int $nextUpdateTime = null;
8688
/** @var Item[] */
8789
public $items = [];
8890

@@ -110,6 +112,7 @@ public function __construct()
110112
$this->addType('lastUpdateError', 'string');
111113
$this->addType('basicAuthUser', 'string');
112114
$this->addType('basicAuthPassword', 'string');
115+
$this->addType('nextUpdateTime', 'int');
113116
}
114117

115118
/**
@@ -296,6 +299,14 @@ public function getUserId(): string
296299
return $this->userId;
297300
}
298301

302+
/**
303+
* @return int|null
304+
*/
305+
public function getNextUpdateTime(): ?int
306+
{
307+
return $this->nextUpdateTime;
308+
}
309+
299310
/**
300311
* Turns entity attributes into an array
301312
*/
@@ -323,7 +334,8 @@ public function jsonSerialize(): array
323334
'updateErrorCount',
324335
'lastUpdateError',
325336
'basicAuthUser',
326-
'basicAuthPassword'
337+
'basicAuthPassword',
338+
'nextUpdateTime'
327339
]);
328340

329341
if (is_null($this->link)) {
@@ -648,6 +660,15 @@ public function setUserId(string $userId): Feed
648660
return $this;
649661
}
650662

663+
/**
664+
* @param int $nextUpdateTime
665+
*/
666+
public function setNextUpdateTime(int $nextUpdateTime): void
667+
{
668+
$this->nextUpdateTime = $nextUpdateTime;
669+
$this->markFieldUpdated('nextUpdateTime');
670+
}
671+
651672
public function toAPI(): array
652673
{
653674
return $this->serializeFields(
@@ -664,7 +685,8 @@ public function toAPI(): array
664685
'pinned',
665686
'updateErrorCount',
666687
'lastUpdateError',
667-
'items'
688+
'items',
689+
'nextUpdateTime'
668690
]
669691
);
670692
}
@@ -679,7 +701,8 @@ public function toAPI2(bool $reduced = false): array
679701
'ordering' => $this->getOrdering(),
680702
'fullTextEnabled' => $this->getFullTextEnabled(),
681703
'updateMode' => $this->getUpdateMode(),
682-
'isPinned' => $this->getPinned()
704+
'isPinned' => $this->getPinned(),
705+
'nextUpdateTime' => $this->getNextUpdateTime(),
683706
];
684707

685708
if (!is_null($this->getLastUpdateError()) || trim($this->getLastUpdateError()) !== '') {

lib/Fetcher/FeedFetcher.php

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public function fetch(
145145
$location
146146
);
147147

148+
$feed->setNextUpdateTime($resource->getNextUpdate()?->getTimestamp());
149+
148150
if (!is_null($resource->getResponse()->getLastModified())) {
149151
$feed->setHttpLastModified($resource->getResponse()->getLastModified()->format(DateTime::RSS));
150152
} elseif (!is_null($lastModified)) {

lib/Migration/Version250000Date20240817095614.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
use OCP\Migration\SimpleMigrationStep;
3333

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\News\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
/**
18+
* Adds the next_update_time column to the feeds table
19+
*/
20+
class Version250200Date20241219085150 extends SimpleMigrationStep {
21+
22+
/**
23+
* @param IOutput $output
24+
* @param Closure(): ISchemaWrapper $schemaClosure
25+
* @param array $options
26+
*/
27+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
28+
}
29+
30+
/**
31+
* @param IOutput $output
32+
* @param Closure(): ISchemaWrapper $schemaClosure
33+
* @param array $options
34+
* @return null|ISchemaWrapper
35+
*/
36+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
37+
$schema = $schemaClosure();
38+
39+
$table = $schema->getTable('news_feeds');
40+
if (!$table->hasColumn('next_update_time')) {
41+
$table->addColumn('next_update_time', 'bigint', [
42+
'notnull' => false
43+
]);
44+
}
45+
46+
return $schema;
47+
}
48+
49+
/**
50+
* @param IOutput $output
51+
* @param Closure(): ISchemaWrapper $schemaClosure
52+
* @param array $options
53+
*/
54+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
55+
}
56+
}

tests/Unit/Db/FeedTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function testToAPI()
6363
'updateErrorCount' => 2,
6464
'lastUpdateError' => 'hi',
6565
'items' => [],
66+
'nextUpdateTime' => ''
6667
],
6768
$feed->toAPI()
6869
);
@@ -86,7 +87,8 @@ public function testToAPI2()
8687
'error' => [
8788
'code' => 1,
8889
'message' => 'hi'
89-
]
90+
],
91+
'nextUpdateTime' => '',
9092
],
9193
$feed->toAPI2()
9294
);
@@ -121,7 +123,8 @@ public function testSerialize()
121123
'updateErrorCount' => 2,
122124
'lastUpdateError' => 'hi',
123125
'basicAuthUser' => 'user',
124-
'basicAuthPassword' => 'password'
126+
'basicAuthPassword' => 'password',
127+
'nextUpdateTime' => '',
125128
],
126129
$feed->jsonSerialize()
127130
);

tests/Unit/Fetcher/FeedFetcherTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ private function createFeed($lang = 'de-DE', $url = null)
711711
$feed->setLocation($this->location);
712712
$feed->setUrl($url);
713713
$feed->setAdded($this->time);
714+
$feed->setNextUpdateTime(0);
714715

715716
$feed->setFaviconLink('http://anon.google.com');
716717
$this->favicon->expects($this->exactly(1))

tests/api/feeds.bats

+6
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ teardown() {
143143
done
144144
}
145145

146+
@test "[$TESTSUITE] Create Feed and check for nextUpdateTime {
147+
# run is not working here.
148+
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | jq '.feeds | .[0].nextUpdateTime')
149+
150+
assert_output '2071387335'
151+
}

tests/test_helper/feeds/Nextcloud.rss

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<atom:link href="http://localhost:8090/Nextcloud.rss" rel="self" type="application/rss+xml" />
1313
<link>https://nextcloud.com/</link>
1414
<description></description>
15-
<lastBuildDate>Tue, 16 Aug 2099 10:17:13 +0000</lastBuildDate>
15+
<lastBuildDate>Tue, 16 Aug 2035 10:17:13 +0000</lastBuildDate>
1616
<language>en-US</language>
1717
<sy:updatePeriod>
1818
hourly </sy:updatePeriod>
@@ -32,7 +32,7 @@
3232
<link>https://nextcloud.com/blog/how-to-get-started-with-nextcloud-repeat/</link>
3333

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

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

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

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

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

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

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

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

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

881881
<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
882-
<pubDate>Wed, 27 Jul 2099 09:12:45 +0000</pubDate>
882+
<pubDate>Wed, 27 Jul 2035 09:12:45 +0000</pubDate>
883883
<category><![CDATA[blog]]></category>
884884
<category><![CDATA[business]]></category>
885885
<category><![CDATA[general]]></category>

0 commit comments

Comments
 (0)