summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/app.php4
-rw-r--r--backgroundjob/task.php75
-rw-r--r--bl/feedbl.php15
-rw-r--r--controller/itemcontroller.php2
-rw-r--r--tests/bl/FeedBlTest.php10
-rw-r--r--tests/controller/ItemControllerTest.php42
-rw-r--r--utility/feedfetcher.php1
7 files changed, 45 insertions, 104 deletions
diff --git a/appinfo/app.php b/appinfo/app.php
index 09d0e3da8..49732cb88 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -51,8 +51,10 @@ $api->addNavigationEntry(array(
));
+
+\OCP\Backgroundjob::addRegularTask( 'OCA\News\Backgroundjob\Task', 'run');
+
/* TODO: fix this classes and uncomment these lines afterwards
\OC_Search::registerProvider('OCA\News\Search\Provider');
-\OCP\Backgroundjob::addRegularTask( 'OCA\News\Backgroundjob\Task', 'run');
*/
diff --git a/backgroundjob/task.php b/backgroundjob/task.php
index e0b4d04f8..3e9aadfd4 100644
--- a/backgroundjob/task.php
+++ b/backgroundjob/task.php
@@ -1,9 +1,12 @@
<?php
+
/**
-* ownCloud - News app
+* ownCloud - News
*
-* @author Jakob Sack
-* @copyright 2012 Jakob Sack owncloud@jakobsack.de
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -20,73 +23,19 @@
*
*/
+
namespace OCA\News\Backgroundjob;
+use \OCA\News\DependencyInjection\DIContainer;
-/**
- * This class maps a feed to an entry in the feeds table of the database.
- */
-class Task {
- static public function sortFeeds( $a, $b ) {
- if( $a->getId() == $b->getId() ) {
- return 0;
- }
- elseif( $a->getId() < $b->getId() ) {
- return -1;
- }
- else{
- return 1;
- }
- }
- static public function run() {
- if( \OC::$CLI ) {
- self::cliStep();
- }
- else{
- self::webStep();
- }
- }
+class Task {
- static private function cliStep() {
- $feedmapper = new FeedMapper();
- // Iterate over all feeds
- $feeds = $feedmapper->findAll();
- foreach( $feeds as $feed ) {
- self::updateFeed( $feedmapper, $feed );
- }
+ static public function run() {
+ $container = new DIContainer();
+ $container['FeedBl']->updateAll();
}
- static private function webStep() {
- // Iterate over all users
- $lastid = \OCP\Config::getAppValue('news', 'backgroundjob_lastid',0);
-
- $feedmapper = new FeedMapper();
- $feeds = $feedmapper->findAll();
- usort( $feeds, array( 'OCA\News\Backgroundjob', 'sortFeeds' ));
-
- $done = false;
- foreach( $feeds as $feed ) {
- if( $feed->getId() > $lastid ) {
- // set lastid BEFORE updating feed!
- \OCP\Config::setAppValue('news', 'backgroundjob_lastid',$feed->getId());
- $done = true;
- self::updateFeed( $feedmapper, $feed );
- }
- }
- if( !$done ) {
- \OCP\Config::setAppValue('news', 'backgroundjob_lastid',0);
- }
- }
-
- static private function updateFeed( $feedmapper, $feed ) {
- $newfeed = null;
- $newfeed = Utils::fetch( $feed->getUrl() );
- if( $newfeed !== null ) {
- $feedmapper = new FeedMapper();
- $newfeedid = $feedmapper->save($newfeed, $feed->getFolderId() );
- }
- }
}
diff --git a/bl/feedbl.php b/bl/feedbl.php
index 8df399788..1340de632 100644
--- a/bl/feedbl.php
+++ b/bl/feedbl.php
@@ -44,13 +44,6 @@ class FeedBl extends Bl {
}
- // README: only call this for the cronjob because it does not
- // check that the feeds belong to the right user
- public function findAll(){
- return $this->mapper->findAll();
- }
-
-
public function findAllFromUser($userId){
return $this->mapper->findAllFromUser($userId);
}
@@ -82,6 +75,14 @@ class FeedBl extends Bl {
}
}
+ public function updateAll(){
+ // TODO: needs test
+ $feeds = $this->mapper->findAll();
+ foreach($feeds as $feed){
+ $this->update($feed->getId(), $feed->getUser());
+ }
+ }
+
public function update($feedId, $userId){
// TODO: update given feed
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php
index e3540cbab..ce76f3cab 100644
--- a/controller/itemcontroller.php
+++ b/controller/itemcontroller.php
@@ -95,7 +95,7 @@ class ItemController extends Controller {
private function setStarred($isStarred){
$userId = $this->api->getUserId();
- $itemId = $this->params('itemId');
+ $itemId = (int) $this->params('itemId');
$this->itemBl->star($itemId, $isStarred, $userId);
}
diff --git a/tests/bl/FeedBlTest.php b/tests/bl/FeedBlTest.php
index 3cf528722..15414a721 100644
--- a/tests/bl/FeedBlTest.php
+++ b/tests/bl/FeedBlTest.php
@@ -61,16 +61,6 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
}
- public function testFindAll(){
- $this->mapper->expects($this->once())
- ->method('findAll')
- ->will($this->returnValue($this->response));
-
- $result = $this->bl->findAll();
- $this->assertEquals($this->response, $result);
- }
-
-
public function testFindAllFromUser(){
$this->mapper->expects($this->once())
->method('findAllFromUser')
diff --git a/tests/controller/ItemControllerTest.php b/tests/controller/ItemControllerTest.php
index fd1666812..0c9899d4f 100644
--- a/tests/controller/ItemControllerTest.php
+++ b/tests/controller/ItemControllerTest.php
@@ -213,18 +213,7 @@ class ItemControllerTest extends ControllerTestUtility {
- public function testItems(){
- $result = array(
- 'items' => array(new Item())
- );
- $post = array(
- 'limit' => 3,
- 'type' => FeedType::FEED,
- 'id' => 2,
- 'offset' => 0
- );
- $this->controller = $this->getPostController($post);
-
+ private function itemsApiExpects($id, $type){
$this->api->expects($this->once())
->method('getUserValue')
->with($this->equalTo($this->user),
@@ -237,13 +226,28 @@ class ItemControllerTest extends ControllerTestUtility {
->method('setUserValue')
->with($this->equalTo($this->user),
$this->equalTo('lastViewedFeedId'),
- $this->equalTo($post['id']));
+ $this->equalTo($id));
$this->api->expects($this->at(3))
->method('setUserValue')
->with($this->equalTo($this->user),
$this->equalTo('lastViewedFeedType'),
- $this->equalTo($post['type']));
+ $this->equalTo($type));
+ }
+
+
+ public function testItems(){
+ $result = array(
+ 'items' => array(new Item())
+ );
+ $post = array(
+ 'limit' => 3,
+ 'type' => FeedType::FEED,
+ 'id' => 2,
+ 'offset' => 0
+ );
+ $this->controller = $this->getPostController($post);
+ $this->itemsApiExpects($post['id'], $post['type']);
$this->bl->expects($this->once())
->method('findAll')
@@ -268,14 +272,8 @@ class ItemControllerTest extends ControllerTestUtility {
);
$this->controller = $this->getPostController($post);
- $this->api->expects($this->once())
- ->method('getUserValue')
- ->with($this->equalTo($this->user),
- $this->equalTo('showAll'))
- ->will($this->returnValue('true'));
- $this->api->expects($this->once())
- ->method('getUserId')
- ->will($this->returnValue($this->user));
+ $this->itemsApiExpects($post['id'], $post['type']);
+
$this->bl->expects($this->once())
->method('findAllNew')
->with($post['id'], $post['type'], $post['updatedSince'],
diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php
index e6ebba5e8..50f58aa97 100644
--- a/utility/feedfetcher.php
+++ b/utility/feedfetcher.php
@@ -56,6 +56,7 @@ class FeedFetcher {
$item->setUrl( $feedItem->get_permalink() );
$item->setTitle( $feedItem->get_title() );
$item->setGuid( $feedItem->get_id() );
+ $item->setGuidHash( md5($feedItem->get_id()) );
$item->setBody( $feedItem->get_content() );
$item->setDate( $feedItem->get_date('U') );