Skip to content

Commit 73401b0

Browse files
committed
Add new field nextUpdateTime to feed
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
1 parent 78800f4 commit 73401b0

4 files changed

Lines changed: 85 additions & 4 deletions

File tree

lib/Db/Feed.php

Lines changed: 26 additions & 3 deletions
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 string|null */
87+
protected $nextUpdateTime = '';
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', 'string');
113116
}
114117

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

302+
/**
303+
* @return string
304+
*/
305+
public function getNextUpdateTime(): string
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 string $nextUpdateTime
665+
*/
666+
public function setNextUpdateTime(string $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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 56 additions & 0 deletions
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', 'string', [
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+
}

0 commit comments

Comments
 (0)