2013-03-02 22:50:33 +04:00
|
|
|
<?php
|
2013-03-21 16:17:58 +04:00
|
|
|
/**
|
2014-04-19 20:16:55 +04:00
|
|
|
* ownCloud - News
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Alessandro Cosentino <cosenal@gmail.com>
|
|
|
|
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
|
|
|
* @copyright Alessandro Cosentino 2012
|
|
|
|
* @copyright Bernhard Posselt 2012, 2014
|
|
|
|
*/
|
2013-03-02 22:50:33 +04:00
|
|
|
|
2014-05-15 05:41:49 +04:00
|
|
|
namespace OCA\News\Service;
|
2014-05-13 22:14:00 +04:00
|
|
|
|
|
|
|
use \OCP\ILogger;
|
|
|
|
use \OCP\IL10N;
|
|
|
|
use \OCP\AppFramework\Db\DoesNotExistException;
|
|
|
|
|
2013-03-21 16:17:58 +04:00
|
|
|
use \OCA\News\Db\Feed;
|
2013-09-11 22:31:58 +04:00
|
|
|
use \OCA\News\Db\Item;
|
2013-03-21 20:07:57 +04:00
|
|
|
use \OCA\News\Db\FeedMapper;
|
2013-03-25 15:54:38 +04:00
|
|
|
use \OCA\News\Db\ItemMapper;
|
2013-09-27 22:03:00 +04:00
|
|
|
use \OCA\News\Fetcher\Fetcher;
|
|
|
|
use \OCA\News\Fetcher\FetcherException;
|
|
|
|
use \OCA\News\ArticleEnhancer\Enhancer;
|
2014-10-21 13:11:20 +04:00
|
|
|
use \OCA\News\Config\Config;
|
2014-04-09 18:10:48 +04:00
|
|
|
|
2013-08-28 19:26:38 +04:00
|
|
|
|
2014-05-15 05:41:49 +04:00
|
|
|
class FeedService extends Service {
|
2013-03-02 22:50:33 +04:00
|
|
|
|
2013-03-22 14:18:16 +04:00
|
|
|
private $feedFetcher;
|
2013-03-25 15:54:38 +04:00
|
|
|
private $itemMapper;
|
2014-05-13 01:48:31 +04:00
|
|
|
private $feedMapper;
|
2014-04-19 15:20:54 +04:00
|
|
|
private $logger;
|
|
|
|
private $l10n;
|
2013-04-19 16:42:48 +04:00
|
|
|
private $timeFactory;
|
2013-05-10 15:30:00 +04:00
|
|
|
private $autoPurgeMinimumInterval;
|
2013-08-28 19:26:38 +04:00
|
|
|
private $enhancer;
|
2014-02-11 19:05:37 +04:00
|
|
|
private $purifier;
|
2014-05-13 22:14:00 +04:00
|
|
|
private $loggerParams;
|
2013-03-22 14:18:16 +04:00
|
|
|
|
2014-05-23 03:25:55 +04:00
|
|
|
public function __construct(FeedMapper $feedMapper,
|
2014-04-19 15:20:54 +04:00
|
|
|
Fetcher $feedFetcher,
|
2014-05-23 03:25:55 +04:00
|
|
|
ItemMapper $itemMapper,
|
2014-05-13 22:14:00 +04:00
|
|
|
ILogger $logger,
|
|
|
|
IL10N $l10n,
|
2014-04-09 18:10:48 +04:00
|
|
|
$timeFactory,
|
|
|
|
Config $config,
|
2014-02-11 19:05:37 +04:00
|
|
|
Enhancer $enhancer,
|
2014-05-13 22:14:00 +04:00
|
|
|
$purifier,
|
|
|
|
$loggerParams){
|
2013-03-21 16:17:58 +04:00
|
|
|
parent::__construct($feedMapper);
|
2013-03-22 14:18:16 +04:00
|
|
|
$this->feedFetcher = $feedFetcher;
|
2013-03-25 15:54:38 +04:00
|
|
|
$this->itemMapper = $itemMapper;
|
2014-04-19 15:20:54 +04:00
|
|
|
$this->logger = $logger;
|
|
|
|
$this->l10n = $l10n;
|
2013-04-19 16:42:48 +04:00
|
|
|
$this->timeFactory = $timeFactory;
|
2014-04-09 18:10:48 +04:00
|
|
|
$this->autoPurgeMinimumInterval = $config->getAutoPurgeMinimumInterval();
|
2013-08-28 19:26:38 +04:00
|
|
|
$this->enhancer = $enhancer;
|
2014-02-11 19:05:37 +04:00
|
|
|
$this->purifier = $purifier;
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper = $feedMapper;
|
2014-05-13 22:14:00 +04:00
|
|
|
$this->loggerParams = $loggerParams;
|
2013-03-08 17:50:10 +04:00
|
|
|
}
|
|
|
|
|
2013-06-05 00:45:19 +04:00
|
|
|
/**
|
|
|
|
* Finds all feeds of a user
|
|
|
|
* @param string $userId the name of the user
|
2014-06-26 13:33:44 +04:00
|
|
|
* @return Feed[]
|
2013-06-05 00:45:19 +04:00
|
|
|
*/
|
2013-04-12 16:53:02 +04:00
|
|
|
public function findAll($userId){
|
2014-05-13 01:48:31 +04:00
|
|
|
return $this->feedMapper->findAllFromUser($userId);
|
2013-03-21 20:00:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-02 16:34:08 +04:00
|
|
|
/**
|
|
|
|
* Finds all feeds from all users
|
|
|
|
* @return array of feeds
|
|
|
|
*/
|
|
|
|
public function findAllFromAllUsers() {
|
2014-05-13 01:48:31 +04:00
|
|
|
return $this->feedMapper->findAll();
|
2013-08-02 16:34:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 21:40:10 +04:00
|
|
|
/**
|
2013-06-05 00:45:19 +04:00
|
|
|
* Creates a new feed
|
|
|
|
* @param string $feedUrl the url to the feed
|
|
|
|
* @param int $folderId the folder where it should be put into, 0 for root folder
|
|
|
|
* @param string $userId for which user the feed should be created
|
2014-05-23 03:25:55 +04:00
|
|
|
* @param string $title if given, this is used for the opml feed title
|
2014-05-15 05:41:49 +04:00
|
|
|
* @throws ServiceConflictException if the feed exists already
|
|
|
|
* @throws ServiceNotFoundException if the url points to an invalid feed
|
2013-06-05 00:45:19 +04:00
|
|
|
* @return Feed the newly created feed
|
2013-05-02 21:40:10 +04:00
|
|
|
*/
|
2014-05-23 03:25:55 +04:00
|
|
|
public function create($feedUrl, $folderId, $userId, $title=null){
|
2013-03-22 16:20:24 +04:00
|
|
|
// first try if the feed exists already
|
2013-03-22 15:35:30 +04:00
|
|
|
try {
|
|
|
|
list($feed, $items) = $this->feedFetcher->fetch($feedUrl);
|
2013-06-05 00:45:19 +04:00
|
|
|
|
2013-08-28 21:19:28 +04:00
|
|
|
// try again if feed exists depending on the reported link
|
|
|
|
try {
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->findByUrlHash($feed->getUrlHash(), $userId);
|
2014-05-15 05:41:49 +04:00
|
|
|
throw new ServiceConflictException(
|
2014-04-19 15:20:54 +04:00
|
|
|
$this->l10n->t('Can not add feed: Exists already'));
|
2014-05-13 00:48:25 +04:00
|
|
|
|
2014-06-26 13:33:44 +04:00
|
|
|
// If no matching feed was found everything was ok
|
2013-08-28 21:19:28 +04:00
|
|
|
} catch(DoesNotExistException $ex){}
|
|
|
|
|
2013-03-22 15:35:30 +04:00
|
|
|
// insert feed
|
|
|
|
$feed->setFolderId($folderId);
|
2013-03-26 02:23:56 +04:00
|
|
|
$feed->setUserId($userId);
|
2013-09-13 19:59:16 +04:00
|
|
|
$feed->setArticlesPerUpdate(count($items));
|
2014-05-23 03:25:55 +04:00
|
|
|
|
|
|
|
if ($title) {
|
|
|
|
$feed->setTitle($title);
|
|
|
|
}
|
|
|
|
|
2014-05-13 01:48:31 +04:00
|
|
|
$feed = $this->feedMapper->insert($feed);
|
2013-03-22 15:35:30 +04:00
|
|
|
|
2013-03-27 15:26:04 +04:00
|
|
|
// insert items in reverse order because the first one is usually the
|
|
|
|
// newest item
|
2013-04-17 01:52:23 +04:00
|
|
|
$unreadCount = 0;
|
2013-03-27 15:26:04 +04:00
|
|
|
for($i=count($items)-1; $i>=0; $i--){
|
|
|
|
$item = $items[$i];
|
2013-03-22 15:35:30 +04:00
|
|
|
$item->setFeedId($feed->getId());
|
2013-04-17 01:52:23 +04:00
|
|
|
|
|
|
|
// check if item exists (guidhash is the same)
|
|
|
|
// and ignore it if it does
|
|
|
|
try {
|
|
|
|
$this->itemMapper->findByGuidHash(
|
|
|
|
$item->getGuidHash(), $item->getFeedId(), $userId);
|
|
|
|
continue;
|
|
|
|
} catch(DoesNotExistException $ex){
|
|
|
|
$unreadCount += 1;
|
2013-08-28 21:19:28 +04:00
|
|
|
$item = $this->enhancer->enhance($item, $feed->getLink());
|
2014-02-11 19:05:37 +04:00
|
|
|
$item->setBody($this->purifier->purify($item->getBody()));
|
2013-04-17 01:52:23 +04:00
|
|
|
$this->itemMapper->insert($item);
|
|
|
|
}
|
2013-03-22 15:35:30 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 21:21:00 +04:00
|
|
|
// set unread count
|
2013-04-17 01:52:23 +04:00
|
|
|
$feed->setUnreadCount($unreadCount);
|
2013-06-05 00:45:19 +04:00
|
|
|
|
2013-03-22 15:35:30 +04:00
|
|
|
return $feed;
|
|
|
|
} catch(FetcherException $ex){
|
2014-09-29 16:08:27 +04:00
|
|
|
$this->logger->debug($ex->getMessage(), $this->loggerParams);
|
2014-05-15 05:41:49 +04:00
|
|
|
throw new ServiceNotFoundException(
|
2014-04-19 15:20:54 +04:00
|
|
|
$this->l10n->t(
|
2014-05-03 23:19:50 +04:00
|
|
|
'Can not add feed: URL does not exist, SSL Certificate can not be validated ' .
|
|
|
|
'or feed has invalid xml'));
|
2013-03-22 15:35:30 +04:00
|
|
|
}
|
2013-03-21 20:00:19 +04:00
|
|
|
}
|
|
|
|
|
2013-03-25 15:54:38 +04:00
|
|
|
|
2013-06-05 00:45:19 +04:00
|
|
|
/**
|
|
|
|
* Runs all the feed updates
|
|
|
|
*/
|
2013-03-25 14:48:15 +04:00
|
|
|
public function updateAll(){
|
2013-06-05 00:45:19 +04:00
|
|
|
// TODO: this method is not covered by any tests
|
2014-05-13 01:48:31 +04:00
|
|
|
$feeds = $this->feedMapper->findAll();
|
2013-03-25 14:48:15 +04:00
|
|
|
foreach($feeds as $feed){
|
2013-03-25 15:54:38 +04:00
|
|
|
try {
|
2013-03-26 02:23:56 +04:00
|
|
|
$this->update($feed->getId(), $feed->getUserId());
|
2014-09-24 01:17:53 +04:00
|
|
|
} catch(\Exception $ex){
|
2014-09-29 16:08:27 +04:00
|
|
|
$this->logger->debug('Could not update feed ' . $ex->getMessage(),
|
2014-05-13 22:14:00 +04:00
|
|
|
$this->loggerParams);
|
2013-03-25 15:54:38 +04:00
|
|
|
}
|
2013-03-25 14:48:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 20:00:19 +04:00
|
|
|
|
2013-05-02 21:40:10 +04:00
|
|
|
/**
|
2013-06-05 00:45:19 +04:00
|
|
|
* Updates a single feed
|
|
|
|
* @param int $feedId the id of the feed that should be updated
|
|
|
|
* @param string $userId the id of the user
|
2014-05-15 05:41:49 +04:00
|
|
|
* @throws ServiceNotFoundException if the feed does not exist
|
2013-06-05 00:45:19 +04:00
|
|
|
* @return Feed the updated feed entity
|
2013-05-02 21:40:10 +04:00
|
|
|
*/
|
2013-03-21 23:38:09 +04:00
|
|
|
public function update($feedId, $userId){
|
2013-03-25 15:54:38 +04:00
|
|
|
try {
|
2014-05-13 01:48:31 +04:00
|
|
|
$existingFeed = $this->feedMapper->find($feedId, $userId);
|
2013-04-19 15:01:44 +04:00
|
|
|
|
|
|
|
if($existingFeed->getPreventUpdate() === true) {
|
2014-06-25 13:22:08 +04:00
|
|
|
return $existingFeed;
|
2013-04-19 15:01:44 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 18:02:32 +04:00
|
|
|
try {
|
2014-05-13 00:57:53 +04:00
|
|
|
list(, $items) = $this->feedFetcher->fetch(
|
2013-06-09 03:08:12 +04:00
|
|
|
$existingFeed->getUrl(), false);
|
|
|
|
|
2013-09-13 19:59:16 +04:00
|
|
|
// update number of articles on every feed update
|
|
|
|
if($existingFeed->getArticlesPerUpdate() !== count($items)) {
|
|
|
|
$existingFeed->setArticlesPerUpdate(count($items));
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->update($existingFeed);
|
2013-09-13 19:59:16 +04:00
|
|
|
}
|
2013-04-15 18:02:32 +04:00
|
|
|
|
2013-06-05 00:45:19 +04:00
|
|
|
// insert items in reverse order because the first one is usually
|
2013-04-19 15:01:44 +04:00
|
|
|
// the newest item
|
2013-04-15 18:02:32 +04:00
|
|
|
for($i=count($items)-1; $i>=0; $i--){
|
|
|
|
$item = $items[$i];
|
|
|
|
$item->setFeedId($existingFeed->getId());
|
|
|
|
|
|
|
|
try {
|
2013-06-22 17:02:33 +04:00
|
|
|
$this->itemMapper->findByGuidHash($item->getGuidHash(), $feedId, $userId);
|
2013-04-15 18:02:32 +04:00
|
|
|
} catch(DoesNotExistException $ex){
|
2014-05-23 03:25:55 +04:00
|
|
|
$item = $this->enhancer->enhance($item,
|
2013-08-28 21:19:28 +04:00
|
|
|
$existingFeed->getLink());
|
2014-02-11 19:05:37 +04:00
|
|
|
$item->setBody($this->purifier->purify($item->getBody()));
|
2013-03-27 16:02:18 +04:00
|
|
|
$this->itemMapper->insert($item);
|
2013-03-27 15:26:04 +04:00
|
|
|
}
|
2013-03-25 15:54:38 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 18:02:32 +04:00
|
|
|
} catch(FetcherException $ex){
|
|
|
|
// failed updating is not really a problem, so only log it
|
2014-05-13 22:14:00 +04:00
|
|
|
|
2014-09-29 16:08:27 +04:00
|
|
|
$this->logger->debug('Can not update feed with url ' . $existingFeed->getUrl() .
|
2014-05-13 22:14:00 +04:00
|
|
|
': Not found or bad source', $this->loggerParams);
|
2014-09-29 16:08:27 +04:00
|
|
|
$this->logger->debug($ex->getMessage(), $this->loggerParams);
|
2013-04-15 18:02:32 +04:00
|
|
|
}
|
2013-06-05 00:45:19 +04:00
|
|
|
|
2014-05-13 01:48:31 +04:00
|
|
|
return $this->feedMapper->find($feedId, $userId);
|
2013-06-05 00:45:19 +04:00
|
|
|
|
2013-04-15 18:02:32 +04:00
|
|
|
} catch (DoesNotExistException $ex){
|
2014-05-15 05:41:49 +04:00
|
|
|
throw new ServiceNotFoundException('Feed does not exist');
|
2013-04-15 18:02:32 +04:00
|
|
|
}
|
2014-06-25 13:22:08 +04:00
|
|
|
|
2013-03-21 20:00:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 21:40:10 +04:00
|
|
|
/**
|
2013-06-05 00:45:19 +04:00
|
|
|
* Moves a feed into a different folder
|
|
|
|
* @param int $feedId the id of the feed that should be moved
|
|
|
|
* @param int $folderId the id of the folder where the feed should be moved to
|
|
|
|
* @param string $userId the name of the user whose feed should be moved
|
2014-05-15 05:41:49 +04:00
|
|
|
* @throws ServiceNotFoundException if the feed does not exist
|
2013-05-02 21:40:10 +04:00
|
|
|
*/
|
2013-03-21 23:38:09 +04:00
|
|
|
public function move($feedId, $folderId, $userId){
|
|
|
|
$feed = $this->find($feedId, $userId);
|
|
|
|
$feed->setFolderId($folderId);
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->update($feed);
|
2013-03-21 20:00:19 +04:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:12:07 +04:00
|
|
|
|
2013-11-12 13:46:31 +04:00
|
|
|
/**
|
|
|
|
* Rename a feed
|
|
|
|
* @param int $feedId the id of the feed that should be moved
|
|
|
|
* @param string $feedTitle the new title of the feed
|
|
|
|
* @param string $userId the name of the user whose feed should be renamed
|
2014-05-15 05:41:49 +04:00
|
|
|
* @throws ServiceNotFoundException if the feed does not exist
|
2013-11-12 13:46:31 +04:00
|
|
|
*/
|
|
|
|
public function rename($feedId, $feedTitle, $userId) {
|
|
|
|
$feed = $this->find($feedId, $userId);
|
|
|
|
$feed->setTitle($feedTitle);
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->update($feed);
|
2013-11-12 13:46:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-19 13:42:27 +04:00
|
|
|
/**
|
2013-09-11 22:31:58 +04:00
|
|
|
* Import articles
|
2013-04-19 13:42:27 +04:00
|
|
|
* @param array $json the array with json
|
2014-06-26 13:33:44 +04:00
|
|
|
* @param string $userId the username
|
2013-09-11 22:31:58 +04:00
|
|
|
* @return Feed if one had to be created for nonexistent feeds
|
2013-04-19 13:42:27 +04:00
|
|
|
*/
|
2013-09-11 22:31:58 +04:00
|
|
|
public function importArticles($json, $userId) {
|
|
|
|
$url = 'http://owncloud/nofeed';
|
2013-04-22 20:24:31 +04:00
|
|
|
$urlHash = md5($url);
|
|
|
|
|
2013-09-11 22:31:58 +04:00
|
|
|
// build assoc array for fast access
|
|
|
|
$feeds = $this->findAll($userId);
|
2014-05-14 19:32:49 +04:00
|
|
|
$feedsDict = [];
|
2013-09-11 22:31:58 +04:00
|
|
|
foreach($feeds as $feed) {
|
|
|
|
$feedsDict[$feed->getLink()] = $feed;
|
2013-04-22 20:24:31 +04:00
|
|
|
}
|
|
|
|
|
2013-09-12 02:59:39 +04:00
|
|
|
$createdFeed = false;
|
|
|
|
|
2013-09-11 22:31:58 +04:00
|
|
|
// loop over all items and get the corresponding feed
|
2014-06-26 13:33:44 +04:00
|
|
|
// if the feed does not exist, create a separate feed for them
|
2013-09-11 22:31:58 +04:00
|
|
|
foreach ($json as $entry) {
|
|
|
|
$item = Item::fromImport($entry);
|
|
|
|
$item->setLastModified($this->timeFactory->getTime());
|
|
|
|
$feedLink = $entry['feedLink']; // this is not set on the item yet
|
|
|
|
|
|
|
|
if(array_key_exists($feedLink, $feedsDict)) {
|
|
|
|
$feed = $feedsDict[$feedLink];
|
|
|
|
$item->setFeedId($feed->getId());
|
|
|
|
} elseif(array_key_exists($url, $feedsDict)) {
|
|
|
|
$feed = $feedsDict[$url];
|
2014-05-23 03:25:55 +04:00
|
|
|
$item->setFeedId($feed->getId());
|
2013-09-11 22:31:58 +04:00
|
|
|
} else {
|
2013-09-12 02:59:39 +04:00
|
|
|
$createdFeed = true;
|
2013-09-11 22:31:58 +04:00
|
|
|
$feed = new Feed();
|
|
|
|
$feed->setUserId($userId);
|
|
|
|
$feed->setLink($url);
|
|
|
|
$feed->setUrl($url);
|
2014-04-19 15:20:54 +04:00
|
|
|
$feed->setTitle($this->l10n->t('Articles without feed'));
|
2013-09-11 22:31:58 +04:00
|
|
|
$feed->setAdded($this->timeFactory->getTime());
|
|
|
|
$feed->setFolderId(0);
|
2014-05-23 03:25:55 +04:00
|
|
|
$feed->setPreventUpdate(true);
|
2014-05-13 01:48:31 +04:00
|
|
|
$feed = $this->feedMapper->insert($feed);
|
2013-09-11 22:31:58 +04:00
|
|
|
|
|
|
|
$item->setFeedId($feed->getId());
|
|
|
|
$feedsDict[$feed->getLink()] = $feed;
|
|
|
|
}
|
|
|
|
|
2013-04-22 20:24:31 +04:00
|
|
|
try {
|
2013-09-12 02:59:39 +04:00
|
|
|
// if item exists, copy the status
|
|
|
|
$existingItem = $this->itemMapper->findByGuidHash(
|
|
|
|
$item->getGuidHash(), $feed->getId(), $userId);
|
|
|
|
$existingItem->setStatus($item->getStatus());
|
|
|
|
$this->itemMapper->update($existingItem);
|
2013-09-11 22:31:58 +04:00
|
|
|
} catch(DoesNotExistException $ex){
|
2014-02-11 19:05:37 +04:00
|
|
|
$item->setBody($this->purifier->purify($item->getBody()));
|
2013-04-22 20:24:31 +04:00
|
|
|
$this->itemMapper->insert($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 02:59:39 +04:00
|
|
|
if($createdFeed) {
|
2014-05-13 01:48:31 +04:00
|
|
|
return $this->feedMapper->findByUrlHash($urlHash, $userId);
|
2013-09-11 22:31:58 +04:00
|
|
|
}
|
2014-06-25 13:22:08 +04:00
|
|
|
|
|
|
|
return null;
|
2013-04-19 13:42:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-10 15:30:00 +04:00
|
|
|
/**
|
2014-06-26 13:33:44 +04:00
|
|
|
* Use this to mark a feed as deleted. That way it can be un-deleted
|
2013-06-05 00:45:19 +04:00
|
|
|
* @param int $feedId the id of the feed that should be deleted
|
|
|
|
* @param string $userId the name of the user for security reasons
|
2014-05-15 05:41:49 +04:00
|
|
|
* @throws ServiceNotFoundException when feed does not exist
|
2013-05-10 15:30:00 +04:00
|
|
|
*/
|
|
|
|
public function markDeleted($feedId, $userId) {
|
|
|
|
$feed = $this->find($feedId, $userId);
|
|
|
|
$feed->setDeletedAt($this->timeFactory->getTime());
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->update($feed);
|
2013-05-10 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this to undo a feed deletion
|
2013-06-05 00:45:19 +04:00
|
|
|
* @param int $feedId the id of the feed that should be restored
|
|
|
|
* @param string $userId the name of the user for security reasons
|
2014-05-15 05:41:49 +04:00
|
|
|
* @throws ServiceNotFoundException when feed does not exist
|
2013-05-10 15:30:00 +04:00
|
|
|
*/
|
|
|
|
public function unmarkDeleted($feedId, $userId) {
|
|
|
|
$feed = $this->find($feedId, $userId);
|
|
|
|
$feed->setDeletedAt(0);
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->update($feed);
|
2013-05-10 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 23:10:45 +04:00
|
|
|
/**
|
|
|
|
* Deletes all deleted feeds
|
|
|
|
* @param string $userId if given it purges only feeds of that user
|
|
|
|
* @param boolean $useInterval defaults to true, if true it only purges
|
2013-06-05 00:45:19 +04:00
|
|
|
* entries in a given interval to give the user a chance to undo the
|
2013-05-21 23:10:45 +04:00
|
|
|
* deletion
|
|
|
|
*/
|
|
|
|
public function purgeDeleted($userId=null, $useInterval=true) {
|
|
|
|
$deleteOlderThan = null;
|
|
|
|
|
|
|
|
if ($useInterval) {
|
|
|
|
$now = $this->timeFactory->getTime();
|
|
|
|
$deleteOlderThan = $now - $this->autoPurgeMinimumInterval;
|
|
|
|
}
|
|
|
|
|
2014-05-13 01:48:31 +04:00
|
|
|
$toDelete = $this->feedMapper->getToDelete($deleteOlderThan, $userId);
|
2013-05-10 15:30:00 +04:00
|
|
|
|
|
|
|
foreach ($toDelete as $feed) {
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->delete($feed);
|
2013-05-10 15:30:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-04 05:09:17 +04:00
|
|
|
/**
|
|
|
|
* Deletes all feeds of a user, delete items first since the user_id
|
|
|
|
* is not defined in there
|
|
|
|
* @param string $userId the name of the user
|
|
|
|
*/
|
|
|
|
public function deleteUser($userId) {
|
2014-05-13 01:48:31 +04:00
|
|
|
$this->feedMapper->deleteUser($userId);
|
2014-04-04 05:09:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-02 22:50:33 +04:00
|
|
|
}
|