From 10e8c28feaf6d858948285a291231f651ef74728 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 4 Oct 2020 20:45:33 +0200 Subject: Add migration with foreign keys Closes #829 Signed-off-by: Sean Molenaar --- lib/Service/FeedService.php | 26 ++++++++++++++---------- lib/Service/FeedServiceV2.php | 8 ++++---- lib/Service/FolderService.php | 18 ++++++++++------- lib/Service/FolderServiceV2.php | 2 +- lib/Service/ItemService.php | 44 +++++++++++++++++++++-------------------- 5 files changed, 55 insertions(+), 43 deletions(-) (limited to 'lib/Service') diff --git a/lib/Service/FeedService.php b/lib/Service/FeedService.php index ab9c18219..c671a035c 100644 --- a/lib/Service/FeedService.php +++ b/lib/Service/FeedService.php @@ -103,21 +103,27 @@ class FeedService extends Service /** * 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 + * @param string $feedUrl the url to the feed + * @param int|null $folderId the folder where it should be put into, null for root * folder - * @param string $userId for which user the feed should be created - * @param string $title if given, this is used for the opml feed title - * @param string $user if given, basic auth is set for this feed - * @param string $password if given, basic auth is set for this + * @param string $userId for which user the feed should be created + * @param string|null $title if given, this is used for the opml feed title + * @param string|null $user if given, basic auth is set for this feed + * @param string|null $password if given, basic auth is set for this * feed. Ignored if user is null or an empty string * + * @return Feed the newly created feed * @throws ServiceConflictException if the feed exists already * @throws ServiceNotFoundException if the url points to an invalid feed - * @return Feed the newly created feed */ - public function create($feedUrl, $folderId, $userId, $title = null, $user = null, $password = null) - { + public function create( + string $feedUrl, + ?int $folderId, + string $userId, + string $title = null, + string $user = null, + string $password = null + ) { // first try if the feed exists already try { /** @@ -369,7 +375,7 @@ class FeedService extends Service $feed->setUrl($url); $feed->setTitle($this->l10n->t('Articles without feed')); $feed->setAdded($this->timeFactory->getTime()); - $feed->setFolderId(0); + $feed->setFolderId(null); $feed->setPreventUpdate(true); /** @var Feed $feed */ $feed = $this->feedMapper->insert($feed); diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php index 2304c3286..4be96ebf8 100644 --- a/lib/Service/FeedServiceV2.php +++ b/lib/Service/FeedServiceV2.php @@ -121,11 +121,11 @@ class FeedServiceV2 extends Service } /** - * @param int $id + * @param int|null $id * * @return Feed[] */ - public function findAllFromFolder(int $id): array + public function findAllFromFolder(?int $id): array { return $this->mapper->findAllFromFolder($id); } @@ -182,7 +182,7 @@ class FeedServiceV2 extends Service * * @param string $userId Feed owner * @param string $feedUrl Feed URL - * @param int $folderId Target folder, defaults to root + * @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 @@ -196,7 +196,7 @@ class FeedServiceV2 extends Service public function create( string $userId, string $feedUrl, - int $folderId = 0, + ?int $folderId = null, bool $full_text = false, ?string $title = null, ?string $user = null, diff --git a/lib/Service/FolderService.php b/lib/Service/FolderService.php index cd8b4b852..db060b050 100644 --- a/lib/Service/FolderService.php +++ b/lib/Service/FolderService.php @@ -101,24 +101,28 @@ class FolderService extends Service * @throws ServiceValidationException if the folder has invalid parameters * @throws ServiceConflictException if name exists already */ - public function create(string $folderName, string $userId, int $parentId = 0) + public function create(string $folderName, string $userId, ?int $parentId = null) { $this->validateFolder($folderName, $userId); $folder = new Folder(); - $folder->setName($folderName); - $folder->setUserId($userId); - $folder->setParentId($parentId); - $folder->setOpened(true); + $folder->setName($folderName) + ->setUserId($userId) + ->setParentId($parentId) + ->setOpened(true); return $this->folderMapper->insert($folder); } /** - * @throws ServiceException if the folder does not exist + * @param int|null $folderId + * @param bool $opened + * @param string $userId + * + * @throws ServiceNotFoundException */ - public function open(int $folderId, bool $opened, string $userId) + public function open(?int $folderId, bool $opened, string $userId) { $folder = $this->find($userId, $folderId); $folder->setOpened($opened); diff --git a/lib/Service/FolderServiceV2.php b/lib/Service/FolderServiceV2.php index cf599456b..784d82f8c 100644 --- a/lib/Service/FolderServiceV2.php +++ b/lib/Service/FolderServiceV2.php @@ -80,7 +80,7 @@ class FolderServiceV2 extends Service return $this->mapper->findAll(); } - public function create(string $userId, string $name, int $parent = 0): Entity + public function create(string $userId, string $name, ?int $parent = null): Entity { $folder = new Folder(); $folder->setUserId($userId) diff --git a/lib/Service/ItemService.php b/lib/Service/ItemService.php index 5f85e0b84..ab5536137 100644 --- a/lib/Service/ItemService.php +++ b/lib/Service/ItemService.php @@ -54,16 +54,17 @@ class ItemService extends Service /** * Returns all new items * - * @param int $id the id of the feed, 0 for starred or all items - * @param int $type the type of the feed - * @param int $updatedSince a timestamp with the last modification date + * @param int|null $id the id of the feed, 0 for starred or all items + * @param int $type the type of the feed + * @param int $updatedSince a timestamp with the last modification date * returns only items with a >= modified * timestamp - * @param boolean $showAll if unread items should also be returned - * @param string $userId the name of the user + * @param boolean $showAll if unread items should also be returned + * @param string $userId the name of the user + * * @return array of items */ - public function findAllNew($id, $type, $updatedSince, $showAll, $userId) + public function findAllNew(?int $id, $type, $updatedSince, $showAll, $userId) { switch ($type) { case FeedType::FEED: @@ -94,20 +95,21 @@ class ItemService extends Service /** * Returns all items * - * @param int $id the id of the feed, 0 for starred or all items - * @param int $type the type of the feed - * @param int $limit how many items should be returned - * @param int $offset the offset - * @param boolean $showAll if unread items should also be returned - * @param boolean $oldestFirst if it should be ordered by oldest first - * @param string $userId the name of the user - * @param string[] $search an array of keywords that the result should + * @param int|null $id the id of the feed, 0 for starred or all items + * @param int $type the type of the feed + * @param int $limit how many items should be returned + * @param int $offset the offset + * @param boolean $showAll if unread items should also be returned + * @param boolean $oldestFirst if it should be ordered by oldest first + * @param string $userId the name of the user + * @param string[] $search an array of keywords that the result should * contain in either the author, title, link * or body + * * @return array of items */ public function findAllItems( - $id, + ?int $id, $type, $limit, $offset, @@ -225,13 +227,13 @@ class ItemService extends Service /** * Set a folder read * - * @param int $folderId the id of the folder that should be marked read - * @param int $highestItemId all items below that are marked read. This is - * used to prevent marking items as read that - * the users hasn't seen yet - * @param string $userId the name of the user + * @param int|null $folderId the id of the folder that should be marked read + * @param int $highestItemId all items below that are marked read. This is + * used to prevent marking items as read that + * the users hasn't seen yet + * @param string $userId the name of the user */ - public function readFolder($folderId, $highestItemId, $userId) + public function readFolder(?int $folderId, $highestItemId, $userId) { $time = $this->timeFactory->getMicroTime(); $this->itemMapper->readFolder( -- cgit v1.2.3