diff options
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/FeedServiceV2.php | 57 | ||||
-rw-r--r-- | lib/Service/StatusService.php | 27 |
2 files changed, 63 insertions, 21 deletions
diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php index 3e02b3971..16ca9a60a 100644 --- a/lib/Service/FeedServiceV2.php +++ b/lib/Service/FeedServiceV2.php @@ -13,6 +13,7 @@ namespace OCA\News\Service; +use DateTime; use FeedIo\Explorer; use FeedIo\Reader\ReadErrorException; use HTMLPurifier; @@ -37,6 +38,7 @@ class FeedServiceV2 extends Service { /** * Class to fetch feeds. + * * @var FeedFetcher */ protected $feedFetcher; @@ -48,11 +50,13 @@ class FeedServiceV2 extends Service protected $itemService; /** * HTML Purifier + * * @var HTMLPurifier */ protected $purifier; /** * Feed Explorer + * * @var Explorer */ protected $explorer; @@ -109,7 +113,7 @@ class FeedServiceV2 extends Service /** * Finds all feeds of a user and all items in it * - * @param string $userId the name of the user + * @param string $userId the name of the user * * @return Feed[] */ @@ -169,13 +173,14 @@ class FeedServiceV2 extends Service /** * Creates a new feed * - * @param string $userId Feed owner - * @param string $feedUrl Feed URL - * @param int|null $folderId Target folder, defaults to root - * @param bool $full_text Scrape the feed for full text - * @param string|null $title The feed title - * @param string|null $user Basic auth username, if set - * @param string|null $password Basic auth password if username is set + * @param string $userId Feed owner + * @param string $feedUrl Feed URL + * @param int|null $folderId Target folder, defaults to root + * @param bool $full_text Scrape the feed for full text + * @param string|null $title The feed title + * @param string|null $user Basic auth username, if set + * @param string|null $password Basic auth password if username is set + * @param string|null $httpLastModified timestamp send when fetching the feed * * @return Feed|Entity * @@ -190,14 +195,16 @@ class FeedServiceV2 extends Service ?string $title = null, ?string $user = null, ?string $password = null, - bool $full_discover = true + bool $full_discover = true, + ?string $httpLastModified = null ): Entity { + $httpLastModified ??= (new DateTime("-1 year"))->format(DateTime::RSS); try { /** * @var Feed $feed * @var Item[] $items */ - list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password); + list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password, $httpLastModified); } catch (ReadErrorException $ex) { $this->logger->debug($ex->getMessage()); if ($full_discover === false) { @@ -209,7 +216,13 @@ class FeedServiceV2 extends Service $feedUrl = array_shift($feeds); } try { - list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password); + list($feed, $items) = $this->feedFetcher->fetch( + $feedUrl, + $full_text, + $user, + $password, + $httpLastModified + ); } catch (ReadErrorException $ex) { throw new ServiceNotFoundException($ex->getMessage()); } @@ -234,7 +247,7 @@ class FeedServiceV2 extends Service if (!is_null($user)) { $feed->setBasicAuthUser($user) - ->setBasicAuthPassword($password); + ->setBasicAuthPassword($password); } return $this->mapper->insert($feed); @@ -267,7 +280,8 @@ class FeedServiceV2 extends Service $location, $feed->getFullTextEnabled(), $feed->getBasicAuthUser(), - $feed->getBasicAuthPassword() + $feed->getBasicAuthPassword(), + $feed->getHttpLastModified() ); } catch (ReadErrorException $ex) { $feed->setUpdateErrorCount($feed->getUpdateErrorCount() + 1); @@ -294,11 +308,11 @@ class FeedServiceV2 extends Service } $feed->setHttpLastModified($fetchedFeed->getHttpLastModified()) - ->setLocation($fetchedFeed->getLocation()); + ->setLocation($fetchedFeed->getLocation()); foreach (array_reverse($items) as &$item) { $item->setFeedId($feed->getId()) - ->setBody($this->purifier->purify($item->getBody())); + ->setBody($this->purifier->purify($item->getBody())); // update modes: 0 nothing, 1 set unread if ($feed->getUpdateMode() === Feed::UPDATE_MODE_NORMAL) { @@ -314,11 +328,14 @@ class FeedServiceV2 extends Service $feed->setLastUpdateError(null); $unreadCount = 0; - array_map(function (Item $item) use (&$unreadCount): void { - if ($item->isUnread()) { - $unreadCount++; - } - }, $items); + array_map( + function (Item $item) use (&$unreadCount): void { + if ($item->isUnread()) { + $unreadCount++; + } + }, + $items + ); return $this->mapper->update($feed)->setUnreadCount($unreadCount); } diff --git a/lib/Service/StatusService.php b/lib/Service/StatusService.php index a15f30c76..69a621e3c 100644 --- a/lib/Service/StatusService.php +++ b/lib/Service/StatusService.php @@ -16,6 +16,9 @@ namespace OCA\News\Service; use OCA\News\AppInfo\Application; use OCP\IConfig; use OCP\IDBConnection; +use OCP\BackgroundJob\IJobList; +use OCP\Util; +use OCA\News\Cron\UpdaterJob; class StatusService { @@ -25,14 +28,18 @@ class StatusService private $appName; /** @var IDBConnection */ private $connection; + /** @var IJobList */ + private $jobList; public function __construct( IConfig $settings, - IDBConnection $connection + IDBConnection $connection, + IJobList $jobList ) { $this->settings = $settings; $this->connection = $connection; $this->appName = Application::NAME; + $this->jobList = $jobList; } /** @@ -76,4 +83,22 @@ class StatusService ] ]; } + + /** + * Get last update time + */ + public function getUpdateTime(): int + { + + $time = 0; + + [$major, $minor, $micro] = Util::getVersion(); + + if ($major >= 26) { + $myJobList = $this->jobList->getJobsIterator(UpdaterJob::class, 1, 0); + $time = $myJobList->current()->getLastRun(); + } + + return $time; + } } |