diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-09-29 13:54:17 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-09-29 14:56:07 +0200 |
commit | 35b53ecd404a74edea3c6866e451c4819bdc9ea8 (patch) | |
tree | dac46834d8fa7ec0122243f94604c3d2215b4d22 /lib | |
parent | d6d169be15913404f99b86c39a03bc71942c9f77 (diff) |
OPML export command and fixes
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib')
46 files changed, 414 insertions, 343 deletions
diff --git a/lib/Command/Config/OpmlExport.php b/lib/Command/Config/OpmlExport.php new file mode 100644 index 000000000..1642e8505 --- /dev/null +++ b/lib/Command/Config/OpmlExport.php @@ -0,0 +1,50 @@ +<?php + +namespace OCA\News\Command\Config; + +use OCA\News\Service\OpmlService; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class OpmlExport extends Command +{ + /** + * @var OpmlService service for the data. + */ + protected $opmlService; + + public function __construct(OpmlService $opmlService) + { + parent::__construct(null); + + $this->opmlService = $opmlService; + } + + /** + * Configure command + */ + protected function configure() + { + $this->setName('news:opml:export') + ->setDescription('Print OPML file') + ->addArgument('userID', InputArgument::REQUIRED, 'User data to export'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $user = $input->getArgument('userID'); + + $output->write($this->opmlService->export($user)); + return 0; + } +} diff --git a/lib/Command/ShowFeed.php b/lib/Command/ShowFeed.php index 1218279e6..8aace3528 100644 --- a/lib/Command/ShowFeed.php +++ b/lib/Command/ShowFeed.php @@ -50,6 +50,9 @@ class ShowFeed extends Command $this->feedFetcher = $feedFetcher; } + /** + * Configure the command + */ protected function configure() { $this->setName('news:show-feed') @@ -60,6 +63,14 @@ class ShowFeed extends Command ->addOption('full-text', 'f', InputOption::VALUE_NONE, 'Usa a scraper to get full text'); } + /** + * Execute the command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output): int { $url = $input->getArgument('feed'); diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php index 4966f5b40..3e75d854a 100644 --- a/lib/Config/FetcherConfig.php +++ b/lib/Config/FetcherConfig.php @@ -98,9 +98,9 @@ class FetcherConfig /** * Configure a guzzle client * - * @return ClientInterface Legacy client to guzzle. + * @return ClientInterface Client to guzzle. */ - public function getClient() + public function getClient(): ClientInterface { $config = [ 'timeout' => $this->client_timeout, diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index addc53591..e3551a2a1 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -67,12 +67,17 @@ class AdminController extends Controller * * @return TemplateResponse */ - public function index() + public function index(): TemplateResponse { return new TemplateResponse($this->appName, 'admin', $this->getData(), 'blank'); } - private function getData() + /** + * Get admin data. + * + * @return array + */ + private function getData(): array { $data = []; @@ -108,7 +113,7 @@ class AdminController extends Controller bool $useCronUpdates, string $exploreUrl, int $updateInterval - ) { + ): array { $this->config->setAppValue($this->appName, 'autoPurgeMinimumInterval', $autoPurgeMinimumInterval); $this->config->setAppValue($this->appName, 'autoPurgeCount', $autoPurgeCount); $this->config->setAppValue($this->appName, 'maxRedirects', $maxRedirects); diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 68caf9236..544b2c23b 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -16,6 +16,7 @@ namespace OCA\News\Controller; use \OCP\IRequest; +use OCP\IUser; use \OCP\IUserSession; use \OCP\AppFramework\ApiController as BaseApiController; diff --git a/lib/Controller/EntityApiSerializer.php b/lib/Controller/EntityApiSerializer.php index c7fdb84e5..daa0f20e5 100644 --- a/lib/Controller/EntityApiSerializer.php +++ b/lib/Controller/EntityApiSerializer.php @@ -57,7 +57,7 @@ class EntityApiSerializer } - private function convert($entities) + private function convert(array $entities) { $converted = []; diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php index 16bdfbd4e..78f200934 100644 --- a/lib/Controller/ExportController.php +++ b/lib/Controller/ExportController.php @@ -13,39 +13,37 @@ namespace OCA\News\Controller; +use OCA\News\Service\FeedServiceV2; +use OCA\News\Service\FolderServiceV2; +use OCA\News\Service\ItemServiceV2; +use OCA\News\Service\OpmlService; +use OCP\AppFramework\Http\DataDownloadResponse; use \OCP\IRequest; use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; use \OCP\AppFramework\Http\JSONResponse; -use \OCA\News\Http\TextDownloadResponse; -use \OCA\News\Service\FolderService; -use \OCA\News\Service\FeedService; -use \OCA\News\Service\ItemService; -use \OCA\News\Utility\OPMLExporter; - class ExportController extends Controller { - private $opmlExporter; + private $opmlService; private $folderService; private $feedService; private $itemService; private $userId; public function __construct( - $appName, + string $appName, IRequest $request, - FolderService $folderService, - FeedService $feedService, - ItemService $itemService, - OPMLExporter $opmlExporter, - $UserId + FolderServiceV2 $folderService, + FeedServiceV2 $feedService, + ItemServiceV2 $itemService, + OpmlService $opmlService, + string $UserId ) { parent::__construct($appName, $request); $this->feedService = $feedService; $this->folderService = $folderService; - $this->opmlExporter = $opmlExporter; + $this->opmlService = $opmlService; $this->itemService = $itemService; $this->userId = $UserId; } @@ -55,15 +53,15 @@ class ExportController extends Controller * @NoAdminRequired * @NoCSRFRequired */ - public function opml() + public function opml(): DataDownloadResponse { - $feeds = $this->feedService->findAll($this->userId); - $folders = $this->folderService->findAll($this->userId); - $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); $date = date('Y-m-d'); - $name = "subscriptions-" . $date . ".opml"; - $mimeType = 'text/xml'; - return new TextDownloadResponse($opml, $name, $mimeType); + + return new DataDownloadResponse( + $this->opmlService->export($this->userId), + "subscriptions-${date}.opml", + 'text/xml' + ); } @@ -71,10 +69,10 @@ class ExportController extends Controller * @NoAdminRequired * @NoCSRFRequired */ - public function articles() + public function articles(): JSONResponse { - $feeds = $this->feedService->findAll($this->userId); - $items = $this->itemService->getUnreadOrStarred($this->userId); + $feeds = $this->feedService->findAllForUser($this->userId); + $items = $this->itemService->findAllForUser($this->userId, ['unread' => true, 'starred' => true]); // build assoc array for fast access $feedsDict = []; diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index c0b4f1a56..cb3d5e645 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -18,6 +18,7 @@ namespace OCA\News\Controller; use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Utility\PsrLogger; +use OCP\AppFramework\Http\JSONResponse; use \OCP\IRequest; use \OCP\ILogger; use \OCP\IUserSession; @@ -52,7 +53,7 @@ class FeedApiController extends ApiController private $serializer; public function __construct( - $appName, + string $appName, IRequest $request, IUserSession $userSession, FeedService $feedService, @@ -72,7 +73,7 @@ class FeedApiController extends ApiController * @NoCSRFRequired * @CORS */ - public function index() + public function index(): array { $result = [ @@ -100,9 +101,10 @@ class FeedApiController extends ApiController * * @param string $url * @param int $folderId - * @return array|mixed|\OCP\AppFramework\Http\JSONResponse + * + * @return array|mixed|JSONResponse */ - public function create($url, $folderId = 0) + public function create(string $url, int $folderId = 0) { try { $this->feedService->purgeDeleted($this->getUserId(), false); @@ -133,9 +135,10 @@ class FeedApiController extends ApiController * @CORS * * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function delete($feedId) + public function delete(int $feedId) { try { $this->feedService->delete($feedId, $this->getUserId()); @@ -155,7 +158,7 @@ class FeedApiController extends ApiController * @param int $feedId * @param int $newestItemId */ - public function read($feedId, $newestItemId) + public function read(int $feedId, int $newestItemId): void { $this->itemService->readFeed($feedId, $newestItemId, $this->getUserId()); } @@ -168,9 +171,10 @@ class FeedApiController extends ApiController * * @param int $feedId * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function move($feedId, $folderId) + public function move(int $feedId, int $folderId) { try { $this->feedService->patch( @@ -193,9 +197,10 @@ class FeedApiController extends ApiController * * @param int $feedId * @param string $feedTitle - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function rename($feedId, $feedTitle) + public function rename(int $feedId, string $feedTitle) { try { $this->feedService->patch( @@ -215,7 +220,7 @@ class FeedApiController extends ApiController * @NoCSRFRequired * @CORS */ - public function fromAllUsers() + public function fromAllUsers(): array { $feeds = $this->feedService->findAllFromAllUsers(); $result = ['feeds' => []]; @@ -237,7 +242,7 @@ class FeedApiController extends ApiController * @param string $userId * @param int $feedId */ - public function update($userId, $feedId) + public function update(string $userId, int $feedId): void { try { $this->feedService->update($userId, $feedId); diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index d0c25d55b..c09096bd9 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -15,6 +15,7 @@ namespace OCA\News\Controller; use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceNotFoundException; +use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; use OCP\IConfig; use OCP\AppFramework\Controller; @@ -36,13 +37,13 @@ class FeedController extends Controller private $settings; public function __construct( - $appName, + string $appName, IRequest $request, FolderService $folderService, FeedService $feedService, ItemService $itemService, IConfig $settings, - $UserId + string $UserId ) { parent::__construct($appName, $request); $this->feedService = $feedService; @@ -56,7 +57,7 @@ class FeedController extends Controller /** * @NoAdminRequired */ - public function index() + public function index(): array { // this method is also used to update the interface @@ -83,7 +84,7 @@ class FeedController extends Controller /** * @NoAdminRequired */ - public function active() + public function active(): array { $feedId = (int) $this->settings->getUserValue( $this->userId, @@ -134,14 +135,15 @@ class FeedController extends Controller * @param string $title * @param string $user * @param string $password - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ public function create( - $url, - $parentFolderId, - $title = null, - $user = null, - $password = null + string $url, + int $parentFolderId, + ?string $title = null, + ?string $user = null, + ?string $password = null ) { try { // we need to purge deleted feeds if a feed is created to @@ -180,9 +182,10 @@ class FeedController extends Controller * @NoAdminRequired * * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function delete($feedId) + public function delete(int $feedId) { try { $this->feedService->markDeleted($feedId, $this->userId); @@ -198,9 +201,10 @@ class FeedController extends Controller * @NoAdminRequired * * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function update($feedId) + public function update(int $feedId) { try { $feed = $this->feedService->update($this->userId, $feedId); @@ -227,7 +231,7 @@ class FeedController extends Controller * @param array $json * @return array */ - public function import($json) + public function import(array $json): array { $feed = $this->feedService->importArticles($json, $this->userId); @@ -250,7 +254,7 @@ class FeedController extends Controller * @param int $highestItemId * @return array */ - public function read($feedId, $highestItemId) + public function read(int $feedId, int $highestItemId): array { $this->itemService->readFeed($feedId, $highestItemId, $this->userId); @@ -269,9 +273,10 @@ class FeedController extends Controller * @NoAdminRequired * * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function restore($feedId) + public function restore(int $feedId) { try { $this->feedService->unmarkDeleted($feedId, $this->userId); @@ -292,15 +297,17 @@ class FeedController extends Controller * @param int $ordering * @param int $folderId * @param string $title + * + * @return array|JSONResponse */ public function patch( - $feedId, - $pinned = null, - $fullTextEnabled = null, - $updateMode = null, - $ordering = null, - $title = null, - $folderId = null + int $feedId, + ?bool $pinned = null, + ?bool $fullTextEnabled = null, + ?int $updateMode = null, + ?int $ordering = null, + ?int $folderId = null, + ?string $title = null ) { $attributes = [ 'pinned' => $pinned, diff --git a/lib/Controller/FolderApiController.php b/lib/Controller/FolderApiController.php index ff61f3300..1f79d7cf9 100644 --- a/lib/Controller/FolderApiController.php +++ b/lib/Controller/FolderApiController.php @@ -15,6 +15,7 @@ namespace OCA\News\Controller; +use OCP\AppFramework\Http\JSONResponse; use \OCP\IRequest; use \OCP\IUserSession; use \OCP\AppFramework\Http; @@ -34,7 +35,7 @@ class FolderApiController extends ApiController private $serializer; public function __construct( - $appName, + string $appName, IRequest $request, IUserSession $userSession, FolderService $folderService, @@ -55,7 +56,7 @@ class FolderApiController extends ApiController public function index() { return $this->serializer->serialize( - $this->folderService->findAll($this->getUserId()) + $this->folderService->findAllForUser($this->getUserId()) ); |