summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-09-12 00:59:39 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-09-12 01:00:32 +0200
commit2391e6bf62e0a3624685a2a7c72bdb7de499bef2 (patch)
treebd8bbc00f9894a082f5628efd3ad79916da16e4d
parent00c6e040deec9c3998ab679dcb84fc46ae72d2ac (diff)
fix #342
-rw-r--r--CHANGELOG5
-rw-r--r--businesslayer/feedbusinesslayer.php14
-rw-r--r--css/settings.css7
-rw-r--r--js/app/controllers/settingscontroller.coffee8
-rw-r--r--js/app/services/businesslayer/feedbusinesslayer.coffee20
-rw-r--r--js/app/services/persistence.coffee8
-rw-r--r--js/public/app.js44
-rw-r--r--js/tests/controllers/settingscontrollerSpec.coffee21
-rw-r--r--js/tests/services/businesslayer/feedbusinesslayerSpec.coffee49
-rw-r--r--js/tests/services/persistenceSpec.coffee8
-rw-r--r--templates/part.settings.php6
-rw-r--r--tests/unit/businesslayer/FeedBusinessLayerTest.php100
12 files changed, 145 insertions, 145 deletions
diff --git a/CHANGELOG b/CHANGELOG
index aa7015dc6..e1471bb7a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php
index cc7324251..fca4a0c74 100644
--- a/businesslayer/feedbusinesslayer.php
+++ b/businesslayer/feedbusinesslayer.php
@@ -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);
}
}
diff --git a/css/settings.css b/css/settings.css
index 7cba9dde0..fd83419b2 100644
--- a/css/settings.css
+++ b/css/settings.css
@@ -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;
} \ No newline at end of file
diff --git a/js/app/controllers/settingscontroller.coffee b/js/app/controllers/settingscontroller.coffee
index b7cea8d21..120dfed49 100644
--- a/js/app/controllers/settingscontroller.coffee
+++ b/js/app/controllers/settingscontroller.coffee
@@ -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
] \ No newline at end of file
diff --git a/js/app/services/businesslayer/feedbusinesslayer.coffee b/js/app/services/businesslayer/feedbusinesslayer.coffee
index cff714ac0..9b5f08a1c 100644
--- a/js/app/services/businesslayer/feedbusinesslayer.coffee
+++ b/js/app/services/businesslayer/feedbusinesslayer.coffee
@@ -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,
diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee
index e1562fc46..559601f69 100644
--- a/js/app/services/persistence.coffee
+++ b/js/app/services/persistence.coffee
@@ -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
###
diff --git a/js/public/app.js b/js/public/app.js
index 7f0b6c8f4..cd822b6a4 100644
--- a/js/public/app.js
+++ b/js/public/app.js
@@ -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);
};
/*
diff --git a/js/tests/controllers/settingscontrollerSpec.coffee b/js/tests/controllers/settingscontrollerSpec.coffee
index 4f028975f..beb404261 100644
--- a/js/tests/controllers/settingscontrollerSpec.coffee
+++ b/js/tests/controllers/settingscontrollerSpec.coffee
@@ -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)
)
diff --git a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee
index 92bbe4b2d..26e5a2973 100644
--- a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee
+++ b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee
@@ -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()
diff --git a/js/tests/services/persistenceSpec.coffee b/js/tests/services/persistenceSpec.coffee
index 3a8a79050..e9f12f669 100644
--- a/js/tests/services/persistenceSpec.coffee
+++ b/js/tests/services/persistenceSpec.coffee
@@ -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)
diff --git a/templates/part.settings.php b/templates/part.settings.php
index 0e622b778..479d8cebd 100644
--- a/templates/part.settings.php
+++ b/templates/part.settings.php
@@ -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>
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php
index 23bb98c55..17222c57b 100644
--- a/tests/unit/businesslayer/FeedBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php
@@ -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())
+ $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($insertFeed))
+ ->will($this->returnValue($insertFeed));
+
+
+ $this->itemMapper->expects($this->at(0))
->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())
+ ->will($this->throwException(new DoesNotExistException('yo')));
+ $this->itemMapper->expects($this->at(1))
->method('insert')
- ->with($this->equalTo($savedItem));
+ ->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));
- $result = $this->feedBusinessLayer->importGoogleReaderJSON($in, $this->user);
+ $this->feedMapper->expects($this->once())
+ ->method('findByUrlHash')
+ ->will($this->returnValue($feed));
+
+ $result = $this->feedBusinessLayer->importArticles($items, $this->user);
$this->assertEquals($feed, $result);
}