1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2025-04-09 10:15:44 +02:00
This commit is contained in:
Bernhard Posselt 2013-09-12 00:59:39 +02:00
parent 00c6e040de
commit 2391e6bf62
12 changed files with 146 additions and 146 deletions

View File

@ -1,3 +1,8 @@
owncloud-news (1.601)
* Remove Google Reader import
* Replace Google Reader import with export and import of unread and starred articles
* Set default autoPurgeLimit to 5000. People who update will have to adjust this if they want to
owncloud-news (1.404)
* Fix bug on postgres databases that would not delete old articles

View File

@ -239,6 +239,8 @@ class FeedBusinessLayer extends BusinessLayer {
$feedsDict[$feed->getLink()] = $feed;
}
$createdFeed = false;
// loop over all items and get the corresponding feed
// if the feed does not exist, create a seperate feed for them
foreach ($json as $entry) {
@ -253,6 +255,7 @@ class FeedBusinessLayer extends BusinessLayer {
$feed = $feedsDict[$url];
$item->setFeedId($feed->getId());
} else {
$createdFeed = true;
$feed = new Feed();
$feed->setUserId($userId);
$feed->setLink($url);
@ -261,21 +264,24 @@ class FeedBusinessLayer extends BusinessLayer {
$feed->setAdded($this->timeFactory->getTime());
$feed->setFolderId(0);
$feed->setPreventUpdate(true);
$feed = $this->mapper->insert($item);
$feed = $this->mapper->insert($feed);
$item->setFeedId($feed->getId());
$feedsDict[$feed->getLink()] = $feed;
}
try {
$this->itemMapper->findByGuidHash($item->getGuidHash(),
$feed->getId(), $userId);
// if item exists, copy the status
$existingItem = $this->itemMapper->findByGuidHash(
$item->getGuidHash(), $feed->getId(), $userId);
$existingItem->setStatus($item->getStatus());
$this->itemMapper->update($existingItem);
} catch(DoesNotExistException $ex){
$this->itemMapper->insert($item);
}
}
if($feed) {
if($createdFeed) {
return $this->mapper->findByUrlHash($urlHash, $userId);
}
}

View File

@ -50,4 +50,11 @@
.download-icon {
background-image: url('%appswebroot%/news/img/download.svg');
}
#app-settings .importing {
background-image: url('%webroot%/core/img/loading.gif');
background-repeat: no-repeat;
background-position: 5px center;
background-size: 16px;
}

View File

@ -37,14 +37,16 @@ angular.module('News').controller 'SettingsController',
$scope.error = true
$scope.importGoogleReader = (fileContent) =>
$scope.importArticles = (fileContent) =>
$scope.jsonError = false
ShowAll.setShowAll(true)
$scope.loading = true
try
parsedJSON = JSON.parse(fileContent)
FeedBusinessLayer.importGoogleReader(parsedJSON)
FeedBusinessLayer.importArticles parsedJSON, ->
$scope.loading = false
catch error
$scope.jsonError = true
$scope.loading = false
]

View File

@ -174,25 +174,11 @@ FeedModel, NewLoading, _ExistsError, Utils, $rootScope, NewestItem)->
@_feedModel.removeByUrl(url)
importGoogleReader: (json) ->
url = 'http://owncloud/googlereader' # hardcoded
if angular.isUndefined(@_feedModel.getByUrl(url))
feed =
title: 'Google Reader'
url: url
folderId: 0
unreadCount: 0
faviconLink: 'url(' +
@_utils.imagePath('core', 'loading.gif') + ')'
@_feedModel.add(feed)
importArticles: (json, callback) ->
onSuccess = (response) =>
id = response.data.feeds[0].id
@load(id)
callback()
@_persistence.importGoogleReader(json, onSuccess)
@_persistence.importArticles(json, onSuccess)
return new FeedBusinessLayer(ShowAll, FeedModel, Persistence, ActiveFeed,

View File

@ -254,13 +254,15 @@ $rootScope, $q) ->
@_request.post 'news_feeds_update', params
importGoogleReader: (json, onSuccess) ->
importArticles: (json, onSuccess) ->
params =
data:
json: json
onSuccess: onSuccess
onSuccess: =>
@getAllFeeds()
onSuccess()
@_request.post 'news_feeds_import_googlereader', params
@_request.post 'news_feeds_import_articles', params
###

View File

@ -796,16 +796,19 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return $scope.error = true;
}
};
return $scope.importGoogleReader = function(fileContent) {
return $scope.importArticles = function(fileContent) {
var error, parsedJSON;
$scope.jsonError = false;
ShowAll.setShowAll(true);
$scope.loading = true;
try {
parsedJSON = JSON.parse(fileContent);
return FeedBusinessLayer.importGoogleReader(parsedJSON);
return FeedBusinessLayer.importArticles(parsedJSON, function() {
return $scope.loading = false;
});
} catch (_error) {
error = _error;
return $scope.jsonError = true;
$scope.jsonError = true;
return $scope.loading = false;
}
};
}
@ -1128,26 +1131,13 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return this._feedModel.removeByUrl(url);
};
FeedBusinessLayer.prototype.importGoogleReader = function(json) {
var feed, onSuccess, url,
FeedBusinessLayer.prototype.importArticles = function(json, callback) {
var onSuccess,
_this = this;
url = 'http://owncloud/googlereader';
if (angular.isUndefined(this._feedModel.getByUrl(url))) {
feed = {
title: 'Google Reader',
url: url,
folderId: 0,
unreadCount: 0,
faviconLink: 'url(' + this._utils.imagePath('core', 'loading.gif') + ')'
};
this._feedModel.add(feed);
}
onSuccess = function(response) {
var id;
id = response.data.feeds[0].id;
return _this.load(id);
return callback();
};
return this._persistence.importGoogleReader(json, onSuccess);
return this._persistence.importArticles(json, onSuccess);
};
return FeedBusinessLayer;
@ -2802,15 +2792,19 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return this._request.post('news_feeds_update', params);
};
Persistence.prototype.importGoogleReader = function(json, onSuccess) {
var params;
Persistence.prototype.importArticles = function(json, onSuccess) {
var params,
_this = this;
params = {
data: {
json: json
},
onSuccess: onSuccess
onSuccess: function() {
_this.getAllFeeds();
return onSuccess();
}
};
return this._request.post('news_feeds_import_googlereader', params);
return this._request.post('news_feeds_import_articles', params);
};
/*

View File

@ -30,13 +30,14 @@ describe 'SettingsController', ->
$provide.value 'Persistence', @persistence
return
beforeEach inject ($controller, @FeedBusinessLayer, @FolderBusinessLayer,
@ShowAll) =>
beforeEach inject ($controller, @ShowAll) =>
@scope = {}
@replace =
'$scope': @scope
'FolderBusinessLayer':
import: jasmine.createSpy('import')
'FeedBusinessLayer':
importArticles: jasmine.createSpy('import')
@controller = $controller('SettingsController', @replace)
@ -63,29 +64,27 @@ describe 'SettingsController', ->
expect(@ShowAll.getShowAll()).toBe(true)
it 'should set showall to true if importing json', =>
it 'should set loading to true if importing json', =>
json = "[\"test\"]"
@scope.importGoogleReader(json)
expect(@ShowAll.getShowAll()).toBe(true)
@scope.importArticles(json)
expect(@scope.loading).toBe(true)
it 'should show an error if the json import failed', =>
json = 'test'
@scope.importGoogleReader(json)
@scope.importArticles(json)
expect(@scope.jsonError).toBe(true)
it 'should import json', =>
@FeedBusinessLayer.importGoogleReader = jasmine.createSpy('googlereader')
json = "{\"test\": \"abc\"}"
@scope.importGoogleReader(json)
@scope.importArticles(json)
expected = JSON.parse(json)
expect(@FeedBusinessLayer.importGoogleReader).toHaveBeenCalledWith(
expected
expect(@replace.FeedBusinessLayer.importArticles).toHaveBeenCalledWith(
expected, jasmine.any(Function)
)

View File

@ -332,49 +332,16 @@ describe 'FeedBusinessLayer', ->
expect(@FeedModel.getByUrl('john')).toBe(undefined)
it 'should not import google reader json', =>
@persistence.importGoogleReader = jasmine.createSpy('importGoogleReader')
it 'should create an import article request', =>
callback = jasmine.createSpy('called')
@persistence.importArticles = jasmine.createSpy('importArticles')
@persistence.importArticles.andCallFake (data, onSuccess) =>
onSuccess()
json = {"test": "hi"}
@FeedBusinessLayer.importGoogleReader(json)
@FeedBusinessLayer.importArticles(json, callback)
imported = @FeedModel.getByUrl('http://owncloud/googlereader')
expect(imported.title).toBe('Google Reader')
expect(imported.folderId).toBe(0)
expect(imported.unreadCount).toBe(0)
it 'should not create a google reader feed if it already exists', =>
@persistence.importGoogleReader = jasmine.createSpy('importGoogleReader')
@FeedModel.add({id: 3, url: 'http://owncloud/googlereader'})
json = {"test": "hi"}
@FeedBusinessLayer.importGoogleReader(json)
imported = @FeedModel.getByUrl('http://owncloud/googlereader')
expect(imported.folderId).not.toBeDefined()
it 'should create an import google reader request', =>
returned =
data:
feeds: [
{id: 3, url: 'hi'}
]
@persistence.getItems = jasmine.createSpy('importGoogleReader')
@persistence.importGoogleReader = jasmine.createSpy('importGoogleReader')
@persistence.importGoogleReader.andCallFake (data, onSuccess) =>
@FeedModel.handle(returned.data.feeds)
onSuccess(returned)
json = {"test": "hi"}
@FeedBusinessLayer.importGoogleReader(json)
expect(@persistence.importGoogleReader).toHaveBeenCalledWith(json,
expect(@persistence.importArticles).toHaveBeenCalledWith(json,
jasmine.any(Function))
expect(@persistence.getItems).toHaveBeenCalledWith(
@FeedType.Feed, returned.data.feeds[0].id, 0
)
expect(@ActiveFeed.getId()).toBe(returned.data.feeds[0].id)
expect(@ActiveFeed.getType()).toBe(@FeedType.Feed)
expect(callback).toHaveBeenCalled()

View File

@ -233,16 +233,16 @@ describe 'Persistence', ->
expect(@req.post).toHaveBeenCalledWith('news_feeds_create', params)
it 'should do a proper import google reader request', =>
it 'should do a proper import articles request', =>
params =
data:
json: {"some": "json"}
onSuccess: ->
onSuccess: jasmine.any(Function)
@Persistence.importGoogleReader(params.data.json, params.onSuccess)
@Persistence.importArticles(params.data.json, ->)
expect(@req.post).toHaveBeenCalledWith('news_feeds_import_googlereader',
expect(@req.post).toHaveBeenCalledWith('news_feeds_import_articles',
params)

View File

@ -8,7 +8,7 @@
}"></button>
</div>
<div id="app-settings-content">
<div id="app-settings-content" style="display:block">
<fieldset class="personalblock">
<legend><strong><?php p($l->t('Subscriptions')); ?></strong></legend>
@ -44,9 +44,11 @@
<legend><strong><?php p($l->t('Unread/Starred Articles')); ?></strong></legend>
<input type="file" id="google-upload" name="importgoogle"
accept="application/json"
oc-read-file="importGoogleReader($fileContent)"/>
oc-read-file="importArticles($fileContent)"/>
<button title="<?php p($l->t('Import')); ?>"
class="upload-icon svg"
ng-class="{loading: importing}"
ng-disabled="importing"
oc-forward-click="{selector:'#google-upload'}">
<?php p($l->t('Import')); ?>
</button>

View File

@ -470,55 +470,85 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
}
public function atestImportGoogleReaderJSONFeedExists(){
$url = 'http://owncloud/googlereader';
$urlHash = md5($url);
public function testImportArticlesCreatesOwnFeedWhenNotFound(){
$url = 'http://owncloud/args';
$feed = new Feed();
$feed->setId(3);
$feed->setUserId($this->user);
$feed->setUrlHash($urlHash);
$feed->setUrl($url);
$feed->setTitle('Google Reader');
$feed->setLink($url);
$feed->setTitle('Articles without feed');
$feed->setAdded($this->time);
$feed->setFolderId(0);
$feed->setPreventUpdate(true);
$feed->setId(3);
$feeds = array($feed);
$item = new Item();
$item->setGuidHash('hi');
$items = array($item);
$savedItem = new Item();
$savedItem->setFeedId($feed->getId());
$savedItem->setGuidHash('hi');
$item->setFeedId(3);
$item->setAuthor('john');
$item->setGuid('s');
$item->setTitle('hey');
$item->setPubDate(333);
$item->setBody('come over');
$item->setEnclosureMime('mime');
$item->setEnclosureLink('lin');
$item->setUnread();
$item->setUnstarred();
$item->setLastModified($this->time);
$in = array();
$json = $item->toExport(array('feed3' => $feed));
$json2 = $json;
$json2['feedLink'] = 'http://test.com'; // believe it or not this copies stuff :D
$this->feedMapper->expects($this->at(0))
->method('findByUrlHash')
->with($this->equalTo($urlHash),
$this->equalTo($this->user))
->will($this->returnValue($feed));
$this->feedMapper->expects($this->at(1))
->method('findByUrlHash')
->with($this->equalTo($urlHash),
$this->equalTo($this->user))
->will($this->returnValue($feed));
$this->importParser->expects($this->once())
->method('parse')
->with($this->equalTo($in))
->will($this->returnValue($items));
$this->itemMapper->expects($this->once())
->method('findByGuidHash')
->with($this->equalTo($savedItem->getGuidHash()),
$this->equalTo($savedItem->getFeedId()),
$this->equalTo($this->user))
->will($this->throwException(new DoesNotExistException('ho')));
$this->itemMapper->expects($this->once())
$items = array($json, $json2);
$insertFeed = new Feed();
$insertFeed->setLink('http://owncloud/nofeed');
$insertFeed->setUrl('http://owncloud/nofeed');
$insertFeed->setUserId($this->user);
$insertFeed->setTitle('Articles without feed');
$insertFeed->setAdded($this->time);
$insertFeed->setPreventUpdate(true);
$insertFeed->setFolderId(0);
$trans = $this->getMock('trans', array('t'));
$trans->expects($this->once())
->method('t')
->will($this->returnValue('Articles without feed'));
$this->feedMapper->expects($this->once())
->method('findAllFromUser')
->with($this->equalTo($this->user))
->will($this->returnValue($feeds));
$this->api->expects($this->once())
->method('getTrans')
->will($this->returnValue($trans));
$this->feedMapper->expects($this->once())
->method('insert')
->with($this->equalTo($savedItem));
->with($this->equalTo($insertFeed))
->will($this->returnValue($insertFeed));
$result = $this->feedBusinessLayer->importGoogleReaderJSON($in, $this->user);
$this->itemMapper->expects($this->at(0))
->method('findByGuidHash')
->will($this->throwException(new DoesNotExistException('yo')));
$this->itemMapper->expects($this->at(1))
->method('insert')
->with($this->equalTo($item));
$this->itemMapper->expects($this->at(2))
->method('findByGuidHash')
->will($this->returnValue($item));
$this->itemMapper->expects($this->at(3))
->method('update')
->with($this->equalTo($item));
$this->feedMapper->expects($this->once())
->method('findByUrlHash')
->will($this->returnValue($feed));
$result = $this->feedBusinessLayer->importArticles($items, $this->user);
$this->assertEquals($feed, $result);
}