summaryrefslogtreecommitdiffstats
path: root/backgroundjob
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-21 16:32:36 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-21 16:32:36 +0100
commitac84b27965f5a1aec859e389f099fb844e33de46 (patch)
treec98d7aace90fcb442208349918a3e71cd9a7691a /backgroundjob
parentf475d882d0a76908400e9857f7e8a4ae8ad8a752 (diff)
reorganize folder
Diffstat (limited to 'backgroundjob')
-rw-r--r--backgroundjob/backgroundjob.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/backgroundjob/backgroundjob.php b/backgroundjob/backgroundjob.php
new file mode 100644
index 000000000..098ff8393
--- /dev/null
+++ b/backgroundjob/backgroundjob.php
@@ -0,0 +1,91 @@
+<?php
+/**
+* ownCloud - News app
+*
+* @author Jakob Sack
+* @copyright 2012 Jakob Sack owncloud@jakobsack.de
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News;
+
+/**
+ * This class maps a feed to an entry in the feeds table of the database.
+ */
+class Backgroundjob {
+ 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();
+ }
+ }
+
+ static private function cliStep() {
+ $feedmapper = new FeedMapper();
+
+ // Iterate over all feeds
+ $feeds = $feedmapper->findAll();
+ foreach( $feeds as $feed ) {
+ self::updateFeed( $feedmapper, $feed );
+ }
+ }
+
+ 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() );
+ }
+ }
+}