зеркало из https://github.com/nextcloud/news.git
added a way to prevent feed from being updated
This commit is contained in:
Родитель
67e00e798d
Коммит
76cc72393a
|
@ -111,6 +111,12 @@
|
|||
<type>integer</type>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
<field>
|
||||
<name>preventUpdate</name>
|
||||
<type>boolean</type>
|
||||
<default>false</default>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<index>
|
||||
<name>news_feeds_user_id_index</name>
|
||||
|
|
|
@ -1 +1 @@
|
|||
8.2
|
||||
8.3
|
|
@ -118,18 +118,21 @@ class FeedBusinessLayer extends BusinessLayer {
|
|||
public function update($feedId, $userId){
|
||||
try {
|
||||
$existingFeed = $this->mapper->find($feedId, $userId);
|
||||
try {
|
||||
list($feed, $items) = $this->feedFetcher->fetch($existingFeed->getUrl());
|
||||
|
||||
// insert items in reverse order because the first one is usually the
|
||||
// newest item
|
||||
if($existingFeed->getPreventUpdate() === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
list($feed, $items) = $this->feedFetcher->fetch(
|
||||
$existingFeed->getUrl());
|
||||
|
||||
// insert items in reverse order because the first one is usually
|
||||
// the newest item
|
||||
for($i=count($items)-1; $i>=0; $i--){
|
||||
$item = $items[$i];
|
||||
$item->setFeedId($existingFeed->getId());
|
||||
|
||||
// if a doesnotexist exception is being thrown the entry does not
|
||||
// exist and the item needs to be created, otherwise
|
||||
// update it
|
||||
try {
|
||||
$existing = $this->itemMapper->findByGuidHash(
|
||||
$item->getGuidHash(), $feedId, $userId);
|
||||
|
|
|
@ -39,12 +39,14 @@ class Feed extends Entity {
|
|||
public $folderId;
|
||||
public $unreadCount;
|
||||
public $link;
|
||||
public $preventUpdate;
|
||||
|
||||
public function __construct(){
|
||||
$this->addType('parentId', 'int');
|
||||
$this->addType('added', 'int');
|
||||
$this->addType('folderId', 'int');
|
||||
$this->addType('unreadCount', 'int');
|
||||
$this->addType('preventUpdate', 'bool');
|
||||
}
|
||||
|
||||
}
|
|
@ -480,6 +480,26 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
|
|||
}
|
||||
|
||||
|
||||
public function testUpdateDoesntUpdateIfFeedIsPrevented() {
|
||||
$feedId = 3;
|
||||
$folderId = 4;
|
||||
$feed = new Feed();
|
||||
$feed->setFolderId(16);
|
||||
$feed->setId($feedId);
|
||||
$feed->setPreventUpdate(true);
|
||||
|
||||
$this->mapper->expects($this->once())
|
||||
->method('find')
|
||||
->with($this->equalTo($feedId),
|
||||
$this->equalTo($this->user))
|
||||
->will($this->returnValue($feed));
|
||||
$this->fetcher->expects($this->never())
|
||||
->method('fetch');
|
||||
|
||||
$this->businessLayer->update($feedId, $this->user);
|
||||
}
|
||||
|
||||
|
||||
public function testMove(){
|
||||
$feedId = 3;
|
||||
$folderId = 4;
|
||||
|
|
Загрузка…
Ссылка в новой задаче