From 35b53ecd404a74edea3c6866e451c4819bdc9ea8 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 29 Sep 2020 13:54:17 +0200 Subject: OPML export command and fixes Signed-off-by: Sean Molenaar --- .github/workflows/integration-tests.yml | 3 +- CHANGELOG.md | 21 +++++- appinfo/info.xml | 5 +- composer.json | 3 +- composer.lock | 5 +- lib/Command/Config/OpmlExport.php | 50 +++++++++++++ lib/Command/ShowFeed.php | 11 +++ lib/Config/FetcherConfig.php | 4 +- lib/Controller/AdminController.php | 11 ++- lib/Controller/ApiController.php | 1 + lib/Controller/EntityApiSerializer.php | 2 +- lib/Controller/ExportController.php | 48 ++++++------- lib/Controller/FeedApiController.php | 31 ++++---- lib/Controller/FeedController.php | 57 ++++++++------- lib/Controller/FolderApiController.php | 23 +++--- lib/Controller/FolderController.php | 37 ++++++---- lib/Controller/ItemApiController.php | 47 ++++++------ lib/Controller/ItemController.php | 22 +++--- lib/Controller/JSONHttpErrorTrait.php | 2 +- lib/Controller/PageController.php | 6 +- lib/Controller/UserApiController.php | 5 +- lib/Controller/UtilityApiController.php | 2 +- lib/Db/EntityJSONSerializer.php | 10 ++- lib/Db/Feed.php | 38 +++++----- lib/Db/FeedMapperV2.php | 2 +- lib/Db/Folder.php | 20 +++--- lib/Db/FolderMapperV2.php | 2 +- lib/Db/Item.php | 84 +++++++++++----------- lib/Db/ItemMapperV2.php | 10 ++- lib/Db/NewsMapperV2.php | 3 +- lib/Explore/RecommendedSites.php | 2 +- lib/Fetcher/Fetcher.php | 4 +- lib/Fetcher/FetcherException.php | 2 +- lib/Fetcher/YoutubeFetcher.php | 2 +- lib/Http/TextDownloadResponse.php | 51 ------------- lib/Http/TextResponse.php | 49 ------------- .../Exceptions/ServiceConflictException.php | 2 +- lib/Service/Exceptions/ServiceException.php | 2 +- .../Exceptions/ServiceNotFoundException.php | 2 +- .../Exceptions/ServiceValidationException.php | 2 +- lib/Service/FeedService.php | 2 +- lib/Service/FeedServiceV2.php | 2 +- lib/Service/FolderService.php | 2 +- lib/Service/FolderServiceV2.php | 2 +- lib/Service/ItemService.php | 2 +- lib/Service/ItemServiceV2.php | 10 +-- lib/Service/OpmlService.php | 69 ++++++++++++++++++ lib/Service/Service.php | 7 +- lib/Service/UpdaterService.php | 8 --- lib/Settings/AdminSection.php | 39 ++++++++++ lib/Settings/Section.php | 39 ---------- lib/Utility/OPMLExporter.php | 5 +- tests/Unit/Controller/ExportControllerTest.php | 71 ++++++++++-------- tests/Unit/Controller/FolderApiControllerTest.php | 2 +- tests/Unit/Controller/FolderControllerTest.php | 4 +- tests/Unit/Controller/ItemApiControllerTest.php | 4 +- tests/Unit/Controller/ItemControllerTest.php | 16 ++--- tests/Unit/Controller/JSONHttpErrorTest.php | 14 ++-- tests/Unit/Controller/PageControllerTest.php | 2 +- tests/Unit/Http/TextDownloadResponseTest.php | 38 ---------- tests/Unit/Http/TextResponseTest.php | 51 ------------- tests/Unit/Service/ServiceTest.php | 2 +- 62 files changed, 544 insertions(+), 530 deletions(-) create mode 100644 lib/Command/Config/OpmlExport.php delete mode 100644 lib/Http/TextDownloadResponse.php delete mode 100644 lib/Http/TextResponse.php create mode 100644 lib/Service/OpmlService.php create mode 100644 lib/Settings/AdminSection.php delete mode 100644 lib/Settings/Section.php delete mode 100644 tests/Unit/Http/TextDownloadResponseTest.php delete mode 100644 tests/Unit/Http/TextResponseTest.php diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 77d35d2a1..171c6d43b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -104,9 +104,10 @@ jobs: ./occ news:generate-explore --votes 100 "https://nextcloud.com/blog/feed/" ./occ news:folder:add 'admin' 'Something' ./occ news:folder:list 'admin' | grep 'Something' - ./occ news:folder:delete 'admin' $(./occ news:folder:list 'admin' | grep 'Something' -1 | head -1 | grep -oE '[0-9]*') ./occ news:feed:add 'admin' "https://nextcloud.com/blog/feed/" ./occ news:feed:list 'admin' | grep 'nextcloud\.com' + ./occ news:opml:export 'admin' | grep 'nextcloud\.com' + ./occ news:folder:delete 'admin' $(./occ news:folder:list 'admin' | grep 'Something' -1 | head -1 | grep -oE '[0-9]*') ./occ news:feed:delete 'admin' $(./occ news:feed:list 'admin' | grep 'nextcloud\.com' -1 | head -1 | grep -oE '[0-9]*') - name: Prep PHP tests diff --git a/CHANGELOG.md b/CHANGELOG.md index ee244d80b..f48f0c469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,21 @@ All notable changes to this project will be documented in this file. ## Unreleased +- Drop support before nextcloud 20 +- Move to modern SQL syntax +- Add management commands +```shell script +./occ news:opml:export + +./occ news:folder:add +./occ news:folder:list +./occ news:folder:delete + +./occ news:feed:add +./occ news:feed:list +./occ news:feed:delete +``` + ## 14.2.2 ### Changed @@ -99,7 +114,7 @@ All notable changes to this project will be documented in this file. ## 14.1.2 ## Changed -- Updated js packages +- Updated js packages ### Fixed - Signature was missing @@ -163,7 +178,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Fixed some feeds with a empty body #474 - Restored full text by default for some feeds #479 -- Some smaller adjustments for the design #463 #464 +- Some smaller adjustments for the design #463 #464 ## 13.1.4 @@ -187,7 +202,7 @@ All notable changes to this project will be documented in this file. - Highlight in compact mode #109 - Prevent raw angluar templates from flashing on page load #429 - HTML elements where not rendered #428 -- Provide UserAgent to prevent HTTP 403 errors #428 +- Provide UserAgent to prevent HTTP 403 errors #428 ## 13.1.1 diff --git a/appinfo/info.xml b/appinfo/info.xml index 86c848d65..9297fa5e8 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -65,11 +65,12 @@ Before you update to a new version, [check the changelog](https://github.com/nex OCA\News\Command\Config\FeedAdd OCA\News\Command\Config\FeedDelete OCA\News\Command\Config\FeedDelete + OCA\News\Command\Config\OpmlExport - OCA\News\Settings\Admin - OCA\News\Settings\Section + OCA\News\Settings\AdminSettings + OCA\News\Settings\AdminSection diff --git a/composer.json b/composer.json index a5cbc622e..a5a00775f 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,8 @@ "ext-json": "*", "ext-simplexml": "*", "ext-libxml": "*", - "ext-dom": "*" + "ext-dom": "*", + "ext-curl": "*" }, "require-dev": { "phpunit/phpunit": "9.2.*", diff --git a/composer.lock b/composer.lock index f305f3294..5078effa1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e553641d7a0ca7ff73af7bdbc2c47617", + "content-hash": "63f7665291caac91a887b6eb20a03db7", "packages": [ { "name": "andreskrey/readability.php", @@ -2298,7 +2298,8 @@ "ext-json": "*", "ext-simplexml": "*", "ext-libxml": "*", - "ext-dom": "*" + "ext-dom": "*", + "ext-curl": "*" }, "platform-dev": [], "plugin-api-version": "1.1.0" 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 @@ +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()) ); } @@ -66,9 +67,10 @@ class FolderApiController extends ApiController * @CORS * * @param string $name - * @return array|mixed|\OCP\AppFramework\Http\JSONResponse + * + * @return array|mixed|JSONResponse */ - public function create($name) + public function create(string $name) { try { $this->folderService->purgeDeleted($this->getUserId(), false); @@ -89,9 +91,10 @@ class FolderApiController extends ApiController * @CORS * * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function delete($folderId) + public function delete(int $folderId) { try { $this->folderService->delete($folderId, $this->getUserId()); @@ -107,11 +110,13 @@ class FolderApiController extends ApiController * @NoAdminRequired * @NoCSRFRequired * @CORS + * * @param int $folderId * @param string $name - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function update($folderId, $name) + public function update(int $folderId, string $name) { try { $this->folderService->rename($folderId, $name, $this->getUserId()); @@ -135,7 +140,7 @@ class FolderApiController extends ApiController * @param int $folderId * @param int $newestItemId */ - public function read($folderId, $newestItemId) + public function read(int $folderId, int $newestItemId): void { $this->itemService->readFolder($folderId, $newestItemId, $this->getUserId()); } diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index 38c580ff0..d19726963 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -13,6 +13,8 @@ namespace OCA\News\Controller; +use OCA\News\Service\Exceptions\ServiceException; +use OCP\AppFramework\Http\JSONResponse; use \OCP\IRequest; use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http; @@ -34,7 +36,7 @@ class FolderController extends Controller private $userId; public function __construct( - $appName, + string $appName, IRequest $request, FolderService $folderService, FeedService $feedService, @@ -54,7 +56,7 @@ class FolderController extends Controller */ public function index() { - $folders = $this->folderService->findAll($this->userId); + $folders = $this->folderService->findAllForUser($this->userId); return ['folders' => $folders]; } @@ -64,13 +66,14 @@ class FolderController extends Controller * * @param int $folderId * @param bool $open - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function open($folderId, $open) + public function open(int $folderId, bool $open) { try { $this->folderService->open($folderId, $open, $this->userId); - } catch (ServiceNotFoundException $ex) { + } catch (ServiceException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -82,9 +85,10 @@ class FolderController extends Controller * @NoAdminRequired * * @param string $folderName - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function create($folderName) + public function create(string $folderName) { try { // we need to purge deleted folders if a folder is created to @@ -105,9 +109,10 @@ class FolderController extends Controller * @NoAdminRequired * * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function delete($folderId) + public function delete(int $folderId) { try { $this->folderService->markDeleted($folderId, $this->userId); @@ -124,9 +129,10 @@ class FolderController extends Controller * * @param string $folderName * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function rename($folderName, $folderId) + public function rename(string $folderName, int $folderId) { try { $folder = $this->folderService->rename( @@ -152,7 +158,7 @@ class FolderController extends Controller * @param int $highestItemId * @return array */ - public function read($folderId, $highestItemId) + public function read(int $folderId, int $highestItemId): array { $this->itemService->readFolder( $folderId, @@ -160,7 +166,7 @@ class FolderController extends Controller $this->userId ); - return ['feeds' => $this->feedService->findAll($this->userId)]; + return ['feeds' => $this->feedService->findAllForUser($this->userId)]; } @@ -168,9 +174,10 @@ class FolderController extends Controller * @NoAdminRequired * * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function restore($folderId) + public function restore(int $folderId) { try { $this->folderService->unmarkDeleted($folderId, $this->userId); diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php index dac2b0a5f..0ac0a890a 100644 --- a/lib/Controller/ItemApiController.php +++ b/lib/Controller/ItemApiController.php @@ -15,6 +15,7 @@ namespace OCA\News\Controller; +use OCP\AppFramework\Http\JSONResponse; use \OCP\IRequest; use \OCP\IUserSession; use \OCP\AppFramework\Http; @@ -30,7 +31,7 @@ class ItemApiController extends ApiController private $serializer; public function __construct( - $appName, + string $appName, IRequest $request, IUserSession $userSession, ItemService $itemService @@ -55,15 +56,15 @@ class ItemApiController extends ApiController * @return array|mixed */ public function index( - $type = 3, - $id = 0, - $getRead = true, - $batchSize = -1, - $offset = 0, - $oldestFirst = false + int $type = 3, + int $id = 0, + bool $getRead = true, + int $batchSize = -1, + int $offset = 0, + bool $oldestFirst = false ) { return $this->serializer->serialize( - $this->itemService->findAll( + $this->itemService->findAllItems( $id, $type, $batchSize, @@ -124,9 +125,10 @@ class ItemApiController extends ApiController * @CORS * * @param int $itemId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function read($itemId) + public function read(int $itemId) { return $this->setRead(true, $itemId); } @@ -138,9 +140,10 @@ class ItemApiController extends ApiController * @CORS * * @param int $itemId - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function unread($itemId) + public function unread(int $itemId) { return $this->setRead(false, $itemId); } @@ -170,9 +173,10 @@ class ItemApiController extends ApiController * * @param int $feedId * @param string $guidHash - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function star($feedId, $guidHash) + public function star(int $feedId, string $guidHash) { return $this->setStarred(true, $feedId, $guidHash); } @@ -185,9 +189,10 @@ class ItemApiController extends ApiController * * @param int $feedId * @param string $guidHash - * @return array|\OCP\AppFramework\Http\JSONResponse + * + * @return array|JSONResponse */ - public function unstar($feedId, $guidHash) + public function unstar(int $feedId, string $guidHash) { return $this->setStarred(false, $feedId, $guidHash); } @@ -200,7 +205,7 @@ class ItemApiController extends ApiController * * @param int $newestItemId */ - public function readAll($newestItemId) + public function readAll(int $newestItemId) { $this->itemService->readAll($newestItemId, $this->getUserId()); } @@ -225,7 +230,7 @@ class ItemApiController extends ApiController * * @param int[] $items item ids */ - public function readMultiple($items) + public function readMultiple(array $items) { $this->setMultipleRead(true, $items); } @@ -238,7 +243,7 @@ class ItemApiController extends ApiController * * @param int[] $items item ids */ - public function unreadMultiple($items) + public function unreadMultiple(array $items) { $this->setMultipleRead(false, $items); } @@ -268,7 +273,7 @@ class ItemApiController extends ApiController * * @param int[] $items item ids */ - public function starMultiple($items) + public function starMultiple(array $items) { $this->setMultipleStarred(true, $items); } @@ -281,7 +286,7 @@ class ItemApiController extends ApiController * * @param int[] $items item ids */ - public function unstarMultiple($items) + public function unstarMultiple(array $items) { $this->setMultipleStarred(false, $items); } diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php index 95a13ee21..37d34e8ca 100644 --- a/lib/Controller/ItemController.php +++ b/lib/Controller/ItemController.php @@ -61,13 +61,13 @@ class ItemController extends Controller * @return array */ public function index( - $type = 3, - $id = 0, - $limit = 50, - $offset = 0, - $showAll = null, - $oldestFirst = null, - $search = '' + int $type = 3, + int $id = 0, + int $limit = 50, + int $offset = 0, + ?bool $showAll = null, + ?bool $oldestFirst = null, + string $search = '' ) { // in case this is called directly and not from the website use the @@ -119,12 +119,12 @@ class ItemController extends Controller if ($offset === 0) { $params['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - $params['feeds'] = $this->feedService->findAll($this->userId); + $params['feeds'] = $this->feedService->findAllForUser($this->userId); $params['starred'] = $this->itemService->starredCount($this->userId); } - $params['items'] = $this->itemService->findAll( + $params['items'] = $this->itemService->findAllItems( $id, $type, $limit, @@ -165,7 +165,7 @@ class ItemController extends Controller try { $params['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - $params['feeds'] = $this->feedService->findAll($this->userId); + $params['feeds'] = $this->feedService->findAllForUser($this->userId); $params['starred'] = $this->itemService->starredCount($this->userId); $params['items'] = $this->itemService->findAllNew( @@ -238,7 +238,7 @@ class ItemController extends Controller public function readAll($highestItemId) { $this->itemService->readAll($highestItemId, $this->userId); - return ['feeds' => $this->feedService->findAll($this->userId)]; + return ['feeds' => $this->feedService->findAllForUser($this->userId)]; } diff --git a/lib/Controller/JSONHttpErrorTrait.php b/lib/Controller/JSONHttpErrorTrait.php index 785f3f02a..e3e343f16 100644 --- a/lib/Controller/JSONHttpErrorTrait.php +++ b/lib/Controller/JSONHttpErrorTrait.php @@ -20,7 +20,7 @@ trait JSONHttpErrorTrait * @param int $code The http error code * @return JSONResponse */ - public function error(\Exception $exception, $code) + public function error(\Exception $exception, int $code) { return new JSONResponse(['message' => $exception->getMessage()], $code); } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index ffcf2e62d..2b20d4695 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -87,7 +87,7 @@ class PageController extends Controller * @NoAdminRequired * @NoCSRFRequired */ - public function index() + public function index(): TemplateResponse { $status = $this->statusService->getStatus(); $response = new TemplateResponse( @@ -118,7 +118,7 @@ class PageController extends Controller /** * @NoAdminRequired */ - public function settings() + public function settings(): array { $settings = [ 'showAll', @@ -173,7 +173,7 @@ class PageController extends Controller bool $preventReadOnScroll, bool $oldestFirst, bool $compactExpand - ) { + ): void { $settings = [ 'showAll' => $showAll, 'compact' => $compact, diff --git a/lib/Controller/UserApiController.php b/lib/Controller/UserApiController.php index 1a5f34f70..b644ba1f0 100644 --- a/lib/Controller/UserApiController.php +++ b/lib/Controller/UserApiController.php @@ -24,11 +24,10 @@ use \OCP\AppFramework\Http; class UserApiController extends ApiController { - private $userSession; private $rootFolder; public function __construct( - $appName, + string $appName, IRequest $request, IUserSession $userSession, IRootFolder $rootFolder @@ -42,7 +41,7 @@ class UserApiController extends ApiController * @NoCSRFRequired * @CORS */ - public function index() + public function index(): array { $user = $this->getUser(); diff --git a/lib/Controller/UtilityApiController.php b/lib/Controller/UtilityApiController.php index 23956f149..a2e5ae910 100644 --- a/lib/Controller/UtilityApiController.php +++ b/lib/Controller/UtilityApiController.php @@ -30,7 +30,7 @@ class UtilityApiController extends ApiController private $statusService; public function __construct( - $appName, + string $appName, IRequest $request, IUserSession $userSession, UpdaterService $updater, diff --git a/lib/Db/EntityJSONSerializer.php b/lib/Db/EntityJSONSerializer.php index 3afc18202..2646ed97a 100644 --- a/lib/Db/EntityJSONSerializer.php +++ b/lib/Db/EntityJSONSerializer.php @@ -16,8 +16,14 @@ namespace OCA\News\Db; trait EntityJSONSerializer { - - public function serializeFields($properties) + /** + * Serialize object properties. + * + * @param array $properties Serializable properties + * + * @return array + */ + public function serializeFields(array $properties): array { $result = []; foreach ($properties as $property) { diff --git a/lib/Db/Feed.php b/lib/Db/Feed.php index ae01c3d6c..9af2f7dc2 100644 --- a/lib/Db/Feed.php +++ b/lib/Db/Feed.php @@ -95,7 +95,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getBasicAuthPassword() + public function getBasicAuthPassword(): ?string { return $this->basicAuthPassword; } @@ -103,7 +103,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getBasicAuthUser() + public function getBasicAuthUser(): ?string { return $this->basicAuthUser; } @@ -111,7 +111,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getDeletedAt() + public function getDeletedAt(): ?int { return $this->deletedAt; } @@ -119,7 +119,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getFaviconLink() + public function getFaviconLink(): ?string { return $this->faviconLink; } @@ -167,7 +167,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastModified() + public function getLastModified(): ?string { return $this->lastModified; } @@ -175,7 +175,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastUpdateError() + public function getLastUpdateError(): ?string { return $this->lastUpdateError; } @@ -183,7 +183,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLink() + public function getLink(): ?string { return $this->link; } @@ -191,7 +191,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLocation() + public function getLocation(): ?string { return $this->location; } @@ -321,7 +321,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param int|null $added */ - public function setAdded(int $added = null): Feed + public function setAdded(?int $added = null): Feed { if ($this->added !== $added) { $this->added = $added; @@ -347,7 +347,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $basicAuthPassword */ - public function setBasicAuthPassword(string $basicAuthPassword = null): Feed + public function setBasicAuthPassword(?string $basicAuthPassword = null): Feed { if ($this->basicAuthPassword !== $basicAuthPassword) { $this->basicAuthPassword = $basicAuthPassword; @@ -360,7 +360,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $basicAuthUser */ - public function setBasicAuthUser(string $basicAuthUser = null): Feed + public function setBasicAuthUser(?string $basicAuthUser = null): Feed { if ($this->basicAuthUser !== $basicAuthUser) { $this->basicAuthUser = $basicAuthUser; @@ -373,7 +373,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param int|null $deletedAt */ - public function setDeletedAt(int $deletedAt = null): Feed + public function setDeletedAt(?int $deletedAt = null): Feed { if ($this->deletedAt !== $deletedAt) { $this->deletedAt = $deletedAt; @@ -386,7 +386,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $faviconLink */ - public function setFaviconLink(string $faviconLink = null): Feed + public function setFaviconLink(?string $faviconLink = null): Feed { if ($this->faviconLink !== $faviconLink) { $this->faviconLink = $faviconLink; @@ -425,7 +425,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $httpEtag */ - public function setHttpEtag(string $httpEtag = null): Feed + public function setHttpEtag(?string $httpEtag = null): Feed { if ($this->httpEtag !== $httpEtag) { $this->httpEtag = $httpEtag; @@ -438,7 +438,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $httpLastModified */ - public function setHttpLastModified(string $httpLastModified = null): Feed + public function setHttpLastModified(?string $httpLastModified = null): Feed { if ($this->httpLastModified !== $httpLastModified) { $this->httpLastModified = $httpLastModified; @@ -464,7 +464,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $lastModified */ - public function setLastModified(string $lastModified = null): Feed + public function setLastModified(?string $lastModified = null): Feed { if ($this->lastModified !== $lastModified) { $this->lastModified = $lastModified; @@ -477,7 +477,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $lastUpdateError */ - public function setLastUpdateError(string $lastUpdateError = null): Feed + public function setLastUpdateError(?string $lastUpdateError = null): Feed { if ($this->lastUpdateError !== $lastUpdateError) { $this->lastUpdateError = $lastUpdateError; @@ -490,7 +490,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $link */ - public function setLink(string $link = null): Feed + public function setLink(?string $link = null): Feed { $link = trim($link); if (strpos($link, 'http') === 0 && $this->link !== $link) { @@ -504,7 +504,7 @@ class Feed extends Entity implements IAPI, \JsonSerializable /** * @param string|null $location */ - public function setLocation(string $location = null): Feed + public function setLocation(?string $location = null): Feed { if ($this->location !== $location) { $this->location = $location; diff --git a/lib/Db/FeedMapperV2.php b/lib/Db/FeedMapperV2.php index 2b4ff8f10..a7edecd88 100644 --- a/lib/Db/FeedMapperV2.php +++ b/lib/Db/FeedMapperV2.php @@ -46,7 +46,7 @@ class FeedMapperV2 extends NewsMapperV2 * * @return Entity[] */ - public function findAllFromUser(string $userId): array + public function findAllFromUser(string $userId, array $params = []): array { $builder = $this->db->getQueryBuilder(); $builder->addSelect('*') diff --git a/lib/Db/Folder.php b/lib/Db/Folder.php index 674c9fabc..eb3389546 100644 --- a/lib/Db/Folder.php +++ b/lib/Db/Folder.php @@ -37,7 +37,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getDeletedAt() + public function getDeletedAt(): ?int { return $this->deletedAt; } @@ -50,7 +50,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastModified() + public function getLastModified(): ?string { return $this->lastModified; } @@ -68,7 +68,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getParentId() + public function getParentId(): ?int { return $this->parentId; } @@ -95,7 +95,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable ); } - public function setDeletedAt(int $deletedAt = null) + public function setDeletedAt(?int $deletedAt = null): void { if ($this->deletedAt !== $deletedAt) { $this->deletedAt = $deletedAt; @@ -103,7 +103,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setId(int $id) + public function setId(int $id): void { if ($this->id !== $id) { $this->id = $id; @@ -111,7 +111,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setLastModified(string $lastModified = null) + public function setLastModified(?string $lastModified = null): void { if ($this->lastModified !== $lastModified) { @@ -120,7 +120,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setName(string $name) + public function setName(string $name): void { if ($this->name !== $name) { $this->name = $name; @@ -128,7 +128,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setOpened(bool $opened) + public function setOpened(bool $opened): void { if ($this->opened !== $opened) { $this->opened = $opened; @@ -136,7 +136,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setParentId(int $parentId = 0) + public function setParentId(int $parentId = 0): void { if ($this->parentId !== $parentId) { $this->parentId = $parentId; @@ -144,7 +144,7 @@ class Folder extends Entity implements IAPI, \JsonSerializable } } - public function setUserId(string $userId) + public function setUserId(string $userId): void { if ($this->userId !== $userId) { $this->userId = $userId; diff --git a/lib/Db/FolderMapperV2.php b/lib/Db/FolderMapperV2.php index d684e5af2..7d0536607 100644 --- a/lib/Db/FolderMapperV2.php +++ b/lib/Db/FolderMapperV2.php @@ -44,7 +44,7 @@ class FolderMapperV2 extends NewsMapperV2 * * @return Entity[] */ - public function findAllFromUser($userId): array + public function findAllFromUser(string $userId, array $params = []): array { $builder = $this->db->getQueryBuilder(); $builder->select('*') diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 7d3924597..322d12fed 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -103,7 +103,7 @@ class Item extends Entity implements IAPI, \JsonSerializable return $item; } - public function generateSearchIndex() + public function generateSearchIndex(): void { $this->setSearchIndex( mb_strtolower( @@ -121,7 +121,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getAuthor() + public function getAuthor(): ?string { return $this->author; } @@ -129,7 +129,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getBody() + public function getBody(): ?string { return $this->body; } @@ -137,7 +137,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getContentHash() + public function getContentHash(): ?string { return $this->contentHash; } @@ -145,7 +145,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getEnclosureLink() + public function getEnclosureLink(): ?string { return $this->enclosureLink; } @@ -153,7 +153,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getMediaThumbnail() + public function getMediaThumbnail(): ?string { return $this->mediaThumbnail; } @@ -161,7 +161,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getMediaDescription() + public function getMediaDescription(): ?string { return $this->mediaDescription; } @@ -169,12 +169,12 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getEnclosureMime() + public function getEnclosureMime(): ?string { return $this->enclosureMime; } - public function getFeedId() + public function getFeedId(): string { return $this->feedId; } @@ -182,7 +182,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getFingerprint() + public function getFingerprint(): ?string { return $this->fingerprint; } @@ -197,12 +197,12 @@ class Item extends Entity implements IAPI, \JsonSerializable return $this->guidHash; } - public function getId() + public function getId(): string { return $this->id; } - public function getIntro() + public function getIntro(): string { return strip_tags($this->getBody()); } @@ -210,7 +210,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return string|null */ - public function getLastModified() + public function getLastModified(): ?string { return $this->lastModified; } @@ -218,7 +218,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getPubDate() + public function getPubDate(): ?int { return $this->pubDate; } @@ -231,7 +231,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getSearchIndex() + public function getSearchIndex(): ?string { return $this->searchIndex; } @@ -239,7 +239,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getTitle() + public function getTitle(): ?string { return $this->title; } @@ -247,7 +247,7 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return int|null */ - public function getUpdatedDate() + public function getUpdatedDate(): ?int { return $this->updatedDate; } @@ -255,17 +255,17 @@ class Item extends Entity implements IAPI, \JsonSerializable /** * @return null|string */ - public function getUrl() + public function getUrl(): ?string { return $this->url; } - public function isStarred() + public function isStarred(): bool { return $this->starred; } - public function isUnread() + public function isUnread(): bool { return $this->unread; } @@ -299,7 +299,7 @@ class Item extends Entity implements IAPI, \JsonSerializable ]; } - public function setAuthor(string $author = null) + public function setAuthor(string $author = null): void { $author = strip_tags($author); @@ -309,7 +309,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setBody(string $body = null) + public function setBody(string $body = null): void { // FIXME: this should not happen if the target="_blank" is already // on the link @@ -321,7 +321,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setContentHash(string $contentHash = null) + public function setContentHash(string $contentHash = null): void { if ($this->contentHash !== $contentHash) { $this->contentHash = $contentHash; @@ -329,7 +329,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setEnclosureLink(string $enclosureLink = null) + public function setEnclosureLink(string $enclosureLink = null): void { if ($this->enclosureLink !== $enclosureLink) { $this->enclosureLink = $enclosureLink; @@ -337,7 +337,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setEnclosureMime(string $enclosureMime = null) + public function setEnclosureMime(string $enclosureMime = null): void { if ($this->enclosureMime !== $enclosureMime) { $this->enclosureMime = $enclosureMime; @@ -345,7 +345,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setMediaThumbnail(string $mediaThumbnail = null) + public function setMediaThumbnail(string $mediaThumbnail = null): void { if ($this->mediaThumbnail !== $mediaThumbnail) { $this->mediaThumbnail = $mediaThumbnail; @@ -353,7 +353,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setMediaDescription(string $mediaDescription = null) + public function setMediaDescription(string $mediaDescription = null): void { if ($this->mediaDescription !== $mediaDescription) { $this->mediaDescription = $mediaDescription; @@ -361,7 +361,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setFeedId(int $feedId) + public function setFeedId(int $feedId): void { if ($this->feedId !== $feedId) { $this->feedId = $feedId; @@ -369,7 +369,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setFingerprint(string $fingerprint = null) + public function setFingerprint(string $fingerprint = null): void { if ($this->fingerprint !== $fingerprint) { $this->fingerprint = $fingerprint; @@ -377,7 +377,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setGuid(string $guid) + public function setGuid(string $guid): void { if ($this->guid !== $guid) { $this->guid = $guid; @@ -385,7 +385,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setGuidHash(string $guidHash) + public function setGuidHash(string $guidHash): void { if ($this->guidHash !== $guidHash) { $this->guidHash = $guidHash; @@ -393,7 +393,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setId(int $id) + public function setId(int $id): void { if ($this->id !== $id) { $this->id = $id; @@ -401,7 +401,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setLastModified(string $lastModified = null) + public function setLastModified(string $lastModified = null): void { if ($this->lastModified !== $lastModified) { $this->lastModified = $lastModified; @@ -409,7 +409,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setPubDate(int $pubDate = null) + public function setPubDate(int $pubDate = null): void { if ($this->pubDate !== $pubDate) { $this->pubDate = $pubDate; @@ -417,7 +417,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setRtl(bool $rtl) + public function setRtl(bool $rtl): void { if ($this->rtl !== $rtl) { $this->rtl = $rtl; @@ -425,7 +425,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setSearchIndex(string $searchIndex = null) + public function setSearchIndex(string $searchIndex = null): void { if ($this->searchIndex !== $searchIndex) { $this->searchIndex = $searchIndex; @@ -433,7 +433,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setStarred(bool $starred) + public function setStarred(bool $starred): void { if ($this->starred !== $starred) { $this->starred = $starred; @@ -441,7 +441,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setTitle(string $title = null) + public function setTitle(string $title = null): void { $title = strip_tags($title); @@ -451,7 +451,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setUnread(bool $unread) + public function setUnread(bool $unread): void { if ($this->unread !== $unread) { $this->unread = $unread; @@ -459,7 +459,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setUpdatedDate(int $updatedDate = null) + public function setUpdatedDate(int $updatedDate = null): void { if ($this->updatedDate !== $updatedDate) { $this->updatedDate = $updatedDate; @@ -467,7 +467,7 @@ class Item extends Entity implements IAPI, \JsonSerializable } } - public function setUrl(string $url = null) + public function setUrl(string $url = null): void { $url = trim($url); if ((strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0) @@ -549,7 +549,7 @@ class Item extends Entity implements IAPI, \JsonSerializable * * @return boolean */ - public function isSupportedMime($mime) + public function isSupportedMime(string $mime): bool { return ( stripos($mime, 'audio/') !== false || diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php index ba840fda7..edb8ba55f 100644 --- a/lib/Db/ItemMapperV2.php +++ b/lib/Db/ItemMapperV2.php @@ -43,10 +43,11 @@ class ItemMapperV2 extends NewsMapperV2 * Find all feeds for a user. * * @param string $userId The user identifier + * @param array $params Filter parameters * * @return Entity[] */ - public function findAllFromUser($userId): array + public function findAllFromUser(string $userId, array $params = []): array { $builder = $this->db->getQueryBuilder(); $builder->select('items.*') @@ -56,6 +57,11 @@ class ItemMapperV2 extends NewsMapperV2 ->andWhere('deleted_at = 0') ->setParameter(':user_id', $userId, IQueryBuilder::PARAM_STR); + foreach ($params as $key => $value) { + $builder->andWhere("${key} = :${key}") + ->setParameter(":${key}", $value); + } + return $this->findEntities($builder); } @@ -110,7 +116,7 @@ class ItemMapperV2 extends NewsMapperV2 * * @param int $threshold Deletion threshold */ - public function deleteOverThreshold($threshold) + public function deleteOverThreshold(int $threshold) { $builder = $this->db->getQueryBuilder(); diff --git a/lib/Db/NewsMapperV2.php b/lib/Db/NewsMapperV2.php index be5695598..2896d9052 100644 --- a/lib/Db/NewsMapperV2.php +++ b/lib/Db/NewsMapperV2.php @@ -88,10 +88,11