diff options
62 files changed, 4418 insertions, 825 deletions
@@ -1,2 +1,9 @@ +Authors: + Alessandro Cosentino <cosenal@gmail.com> Bernhard Posselt <nukeawhale@gmail.com> + +Contributors: + +Raghu Nayyar <me@iraghu.com> +Jan-Christoph Borchardt (http://jancborchardt.net)
\ No newline at end of file diff --git a/appinfo/routes.php b/appinfo/routes.php index 40cf23149..9acce6661 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -193,6 +193,11 @@ $this->create('news_usersettings_read_hide', '/usersettings/read/hide')->post()- } ); +$this->create('news_usersettings_language', '/usersettings/language')->get()->action( + function($params){ + App::main('UserSettingsController', 'getLanguage', $params, new DIContainer()); + } +); diff --git a/backgroundjob/task.php b/backgroundjob/task.php index 2274f7b99..820d36cc7 100644 --- a/backgroundjob/task.php +++ b/backgroundjob/task.php @@ -34,8 +34,8 @@ class Task { static public function run() { $container = new DIContainer(); - $container['FeedBl']->updateAll(); - $container['ItemBl']->autoPurgeOld(); + $container['FeedBusinessLayer']->updateAll(); + $container['ItemBusinessLayer']->autoPurgeOld(); } diff --git a/bl/bl.php b/businesslayer/businesslayer.php index ee4ace588..4ce6f1625 100644 --- a/bl/bl.php +++ b/businesslayer/businesslayer.php @@ -23,7 +23,7 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; @@ -31,7 +31,7 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\IMapper; -abstract class Bl { +abstract class BusinessLayer { protected $mapper; @@ -50,9 +50,9 @@ abstract class Bl { try { return $this->mapper->find($id, $userId); } catch(DoesNotExistException $ex){ - throw new BLException($ex->getMessage()); + throw new BusinessLayerException($ex->getMessage()); } catch(MultipleObjectsReturnedException $ex){ - throw new BLException($ex->getMessage()); + throw new BusinessLayerException($ex->getMessage()); } } diff --git a/bl/blexception.php b/businesslayer/businesslayerexception.php index fca362ea7..03219a20f 100644 --- a/bl/blexception.php +++ b/businesslayer/businesslayerexception.php @@ -23,10 +23,10 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; -class BLException extends \Exception { +class BusinessLayerException extends \Exception { /** * Constructor diff --git a/bl/feedbl.php b/businesslayer/feedbusinesslayer.php index 97deaeff0..f7666fc1c 100644 --- a/bl/feedbl.php +++ b/businesslayer/feedbusinesslayer.php @@ -23,7 +23,7 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Core\API; @@ -34,7 +34,7 @@ use \OCA\News\Db\ItemMapper; use \OCA\News\Utility\Fetcher; use \OCA\News\Utility\FetcherException; -class FeedBl extends Bl { +class FeedBusinessLayer extends BusinessLayer { private $feedFetcher; private $itemMapper; @@ -58,7 +58,7 @@ class FeedBl extends Bl { // first try if the feed exists already try { $this->mapper->findByUrlHash(md5($feedUrl), $userId); - throw new BLException( + throw new BusinessLayerException( $this->api->getTrans()->t('Can not add feed: Exists already')); } catch(DoesNotExistException $ex){} @@ -84,7 +84,7 @@ class FeedBl extends Bl { return $feed; } catch(FetcherException $ex){ $this->api->log($ex->getMessage()); - throw new BLException( + throw new BusinessLayerException( $this->api->getTrans()->t( 'Can not add feed: URL does not exist or has invalid xml')); } @@ -97,7 +97,7 @@ class FeedBl extends Bl { foreach($feeds as $feed){ try { $this->update($feed->getId(), $feed->getUserId()); - } catch(BLException $ex){ + } catch(BusinessLayerException $ex){ continue; } } @@ -105,50 +105,55 @@ class FeedBl extends Bl { public function update($feedId, $userId){ - $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 - 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); - - // in case of an update the existing item has to be deleted - // if the pub_date changed because we sort by id on the - // client side since this is the only reliable way to do it - // to not get weird behaviour - if($existing->getPubDate() !== $item->getPubDate()){ - - // because the item is being replaced we need to keep - // status flags but we want the new entry to be unread - $item->setStatus($existing->getStatus()); - $item->setUnread(); - - $this->itemMapper->delete($existing); + $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 + 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); + + // in case of an update the existing item has to be deleted + // if the pub_date changed because we sort by id on the + // client side since this is the only reliable way to do it + // to not get weird behaviour + if($existing->getPubDate() !== $item->getPubDate()){ + + // because the item is being replaced we need to keep + // status flags but we want the new entry to be unread + $item->setStatus($existing->getStatus()); + $item->setUnread(); + + $this->itemMapper->delete($existing); + $this->itemMapper->insert($item); + } + + } catch(DoesNotExistException $ex){ $this->itemMapper->insert($item); } - - } catch(DoesNotExistException $ex){ - $this->itemMapper->insert($item); } - } - } catch(FetcherException $ex){ - // failed updating is not really a problem, so only log it - $this->api->log('Can not update feed with url' . $existingFeed->getUrl() . - ': Not found or bad source'); - } + } catch(FetcherException $ex){ + // failed updating is not really a problem, so only log it + $this->api->log('Can not update feed with url' . $existingFeed->getUrl() . + ': Not found or bad source'); + } + + return $this->mapper->find($feedId, $userId); - return $this->mapper->find($feedId, $userId); + } catch (DoesNotExistException $ex){ + throw new BusinessLayerException('Feed does not exist'); + } } diff --git a/bl/folderbl.php b/businesslayer/folderbusinesslayer.php index 59fdddf16..916476896 100644 --- a/bl/folderbl.php +++ b/businesslayer/folderbusinesslayer.php @@ -23,7 +23,7 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; use \OCA\AppFramework\Core\API; @@ -31,7 +31,7 @@ use \OCA\News\Db\Folder; use \OCA\News\Db\FolderMapper; -class FolderBl extends Bl { +class FolderBusinessLayer extends BusinessLayer { private $api; @@ -51,13 +51,13 @@ class FolderBl extends Bl { $existingFolders = $this->mapper->findByName($folderName, $userId); if(count($existingFolders) > 0){ - throw new BLException( + throw new BusinessLayerException( $this->api->getTrans()->t('Can not add folder: Exists already')); } } /** - * @throws BLException if name exists already + * @throws BusinessLayerException if name exists already */ public function create($folderName, $userId, $parentId=0) { $this->allowNoNameTwice($folderName, $userId); @@ -79,7 +79,7 @@ class FolderBl extends Bl { /** - * @throws BLException if name exists already + * @throws BusinessLayerException if name exists already */ public function rename($folderId, $folderName, $userId){ $this->allowNoNameTwice($folderName, $userId); diff --git a/bl/itembl.php b/businesslayer/itembusinesslayer.php index 504e48016..fd01506a6 100644 --- a/bl/itembl.php +++ b/businesslayer/itembusinesslayer.php @@ -23,7 +23,7 @@ * */ -namespace OCA\News\Bl; +namespace OCA\News\BusinessLayer; use \OCA\News\Db\Item; use \OCA\News\Db\ItemMapper; @@ -31,7 +31,7 @@ use \OCA\News\Db\StatusFlag; use \OCA\News\Db\FeedType; -class ItemBl extends Bl { +class ItemBusinessLayer extends BusinessLayer { private $statusFlag; private $autoPurgeCount; diff --git a/controller/exportcontroller.php b/controller/exportcontroller.php index 960748d3e..023a4d39d 100644 --- a/controller/exportcontroller.php +++ b/controller/exportcontroller.php @@ -30,21 +30,23 @@ use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; use \OCA\AppFramework\Http\TextDownloadResponse; -use \OCA\News\Bl\FeedBl; -use \OCA\News\Bl\FolderBl; +use \OCA\News\BusinessLayer\FeedBusinessLayer; +use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\Utility\OPMLExporter; class ExportController extends Controller { private $opmlExporter; - private $folderBl; - private $feedBl; + private $folderBusinessLayer; + private $feedBusinessLayer; - public function __construct(API $api, Request $request, FeedBl $feedBl, - FolderBl $folderBl, OPMLExporter $opmlExporter){ + public function __construct(API $api, Request $request, + FeedBusinessLayer $feedBusinessLayer, + FolderBusinessLayer $folderBusinessLayer, + OPMLExporter $opmlExporter){ parent::__construct($api, $request); - $this->feedBl = $feedBl; - $this->folderBl = $folderBl; + $this->feedBusinessLayer = $feedBusinessLayer; + $this->folderBusinessLayer = $folderBusinessLayer; $this->opmlExporter = $opmlExporter; } @@ -56,8 +58,8 @@ class ExportController extends Controller { */ public function opml(){ $user = $this->api->getUserId(); - $feeds = $this->feedBl->findAll($user); - $folders = $this->folderBl->findAll($user); + $feeds = $this->feedBusinessLayer->findAll($user); + $folders = $this->folderBusinessLayer->findAll($user); $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); return new TextDownloadResponse($opml, 'subscriptions.opml', 'text/xml'); } diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index 5e2a91f24..53257d73c 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -29,22 +29,23 @@ use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; -use \OCA\News\Bl\FeedBl; -use \OCA\News\Bl\FolderBl; -use \OCA\News\Bl\BLException; +use \OCA\News\BusinessLayer\FeedBusinessLayer; +use \OCA\News\BusinessLayer\FolderBusinessLayer; +use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\Db\FeedType; class FeedController extends Controller { - private $feedBl; - private $folderBl; + private $feedBusinessLayer; + private $folderBusinessLayer; - public function __construct(API $api, Request $request, FeedBl $feedBl, - FolderBl $folderBl){ + public function __construct(API $api, Request $request, + FeedBusinessLayer $feedBusinessLayer, + FolderBusinessLayer $folderBusinessLayer){ parent::__construct($api, $request); - $this->feedBl = $feedBl; - $this->folderBl = $folderBl; + $this->feedBusinessLayer = $feedBusinessLayer; + $this->folderBusines |