summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-09-29 13:54:17 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-09-29 14:56:07 +0200
commit35b53ecd404a74edea3c6866e451c4819bdc9ea8 (patch)
treedac46834d8fa7ec0122243f94604c3d2215b4d22 /lib/Service
parentd6d169be15913404f99b86c39a03bc71942c9f77 (diff)
OPML export command and fixes
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/Exceptions/ServiceConflictException.php2
-rw-r--r--lib/Service/Exceptions/ServiceException.php2
-rw-r--r--lib/Service/Exceptions/ServiceNotFoundException.php2
-rw-r--r--lib/Service/Exceptions/ServiceValidationException.php2
-rw-r--r--lib/Service/FeedService.php2
-rw-r--r--lib/Service/FeedServiceV2.php2
-rw-r--r--lib/Service/FolderService.php2
-rw-r--r--lib/Service/FolderServiceV2.php2
-rw-r--r--lib/Service/ItemService.php2
-rw-r--r--lib/Service/ItemServiceV2.php10
-rw-r--r--lib/Service/OpmlService.php69
-rw-r--r--lib/Service/Service.php7
-rw-r--r--lib/Service/UpdaterService.php8
13 files changed, 88 insertions, 24 deletions
diff --git a/lib/Service/Exceptions/ServiceConflictException.php b/lib/Service/Exceptions/ServiceConflictException.php
index 4a1a80801..dd6ba03c9 100644
--- a/lib/Service/Exceptions/ServiceConflictException.php
+++ b/lib/Service/Exceptions/ServiceConflictException.php
@@ -21,7 +21,7 @@ class ServiceConflictException extends ServiceException
*
* @param string $msg the error message
*/
- public function __construct($msg)
+ public function __construct(string $msg)
{
parent::__construct($msg);
}
diff --git a/lib/Service/Exceptions/ServiceException.php b/lib/Service/Exceptions/ServiceException.php
index 7ee53bef9..c5ddddbd9 100644
--- a/lib/Service/Exceptions/ServiceException.php
+++ b/lib/Service/Exceptions/ServiceException.php
@@ -21,7 +21,7 @@ class ServiceException extends \Exception
*
* @param string $msg the error message
*/
- public function __construct($msg)
+ public function __construct(string $msg)
{
parent::__construct($msg);
}
diff --git a/lib/Service/Exceptions/ServiceNotFoundException.php b/lib/Service/Exceptions/ServiceNotFoundException.php
index 6a9bae192..6c68ea6b2 100644
--- a/lib/Service/Exceptions/ServiceNotFoundException.php
+++ b/lib/Service/Exceptions/ServiceNotFoundException.php
@@ -21,7 +21,7 @@ class ServiceNotFoundException extends ServiceException
*
* @param string $msg the error message
*/
- public function __construct($msg)
+ public function __construct(string $msg)
{
parent::__construct($msg);
}
diff --git a/lib/Service/Exceptions/ServiceValidationException.php b/lib/Service/Exceptions/ServiceValidationException.php
index 8d1bf09c8..8e9dc9fee 100644
--- a/lib/Service/Exceptions/ServiceValidationException.php
+++ b/lib/Service/Exceptions/ServiceValidationException.php
@@ -21,7 +21,7 @@ class ServiceValidationException extends ServiceException
*
* @param string $msg the error message
*/
- public function __construct($msg)
+ public function __construct(string $msg)
{
parent::__construct($msg);
}
diff --git a/lib/Service/FeedService.php b/lib/Service/FeedService.php
index 55807b45a..ab9c18219 100644
--- a/lib/Service/FeedService.php
+++ b/lib/Service/FeedService.php
@@ -83,7 +83,7 @@ class FeedService extends Service
*
* @return Feed[]
*/
- public function findAllForUser($userId): array
+ public function findAllForUser($userId, array $params = []): array
{
return $this->feedMapper->findAllFromUser($userId);
}
diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php
index 58217a1ce..55137c357 100644
--- a/lib/Service/FeedServiceV2.php
+++ b/lib/Service/FeedServiceV2.php
@@ -89,7 +89,7 @@ class FeedServiceV2 extends Service
*
* @return Feed[]
*/
- public function findAllForUser(string $userId): array
+ public function findAllForUser(string $userId, array $params = []): array
{
return $this->mapper->findAllFromUser($userId);
}
diff --git a/lib/Service/FolderService.php b/lib/Service/FolderService.php
index ed95f81f4..cd8b4b852 100644
--- a/lib/Service/FolderService.php
+++ b/lib/Service/FolderService.php
@@ -65,7 +65,7 @@ class FolderService extends Service
*
* @return Folder[]
*/
- public function findAllForUser(string $userId): array
+ public function findAllForUser(string $userId, array $params = []): array
{
return $this->folderMapper->findAllFromUser($userId);
}
diff --git a/lib/Service/FolderServiceV2.php b/lib/Service/FolderServiceV2.php
index 0e15ddde5..b1290eca2 100644
--- a/lib/Service/FolderServiceV2.php
+++ b/lib/Service/FolderServiceV2.php
@@ -47,7 +47,7 @@ class FolderServiceV2 extends Service
*
* @return Folder[]
*/
- public function findAllForUser(string $userId): array
+ public function findAllForUser(string $userId, array $params = []): array
{
return $this->mapper->findAllFromUser($userId);
}
diff --git a/lib/Service/ItemService.php b/lib/Service/ItemService.php
index 3a0270658..5f85e0b84 100644
--- a/lib/Service/ItemService.php
+++ b/lib/Service/ItemService.php
@@ -150,7 +150,7 @@ class ItemService extends Service
}
}
- public function findAllForUser(string $userId): array
+ public function findAllForUser(string $userId, array $params = []): array
{
return $this->itemMapper->findAllFromUser($userId);
}
diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php
index 879b2908f..1e4fe1eac 100644
--- a/lib/Service/ItemServiceV2.php
+++ b/lib/Service/ItemServiceV2.php
@@ -51,13 +51,15 @@ class ItemServiceV2 extends Service
/**
* Finds all items of a user
*
- * @param string $userId the name of the user
+ * @param string $userId The ID/name of the user
+ * @param array $params Filter parameters
+ *
*
* @return Item[]
*/
- public function findAllForUser($userId): array
+ public function findAllForUser(string $userId, array $params = []): array
{
- return $this->mapper->findAllFromUser($userId);
+ return $this->mapper->findAllFromUser($userId, $params);
}
/**
@@ -86,7 +88,7 @@ class ItemServiceV2 extends Service
return $this->mapper->findAllForFeed($feedId);
}
- public function purgeOverThreshold($threshold = null)
+ public function purgeOverThreshold(int $threshold = null)
{
$threshold = (int) $threshold ?? $this->config->getAppValue(
diff --git a/lib/Service/OpmlService.php b/lib/Service/OpmlService.php
new file mode 100644
index 000000000..ea570cf68
--- /dev/null
+++ b/lib/Service/OpmlService.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Nextcloud - 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 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
+ */
+
+
+namespace OCA\News\Service;
+
+use OCA\News\Utility\OPMLExporter;
+
+class OpmlService
+{
+
+ /**
+ * @var FolderService
+ */
+ private $folderService;
+
+ /**
+ * @var FeedService
+ */
+ private $feedService;
+
+ /**
+ * @var ItemService
+ */
+ private $itemService;
+
+ /**
+ * @var OPMLExporter
+ */
+ private $exporter;
+
+ public function __construct(
+ FolderServiceV2 $folderService,
+ FeedServiceV2 $feedService,
+ ItemServiceV2 $itemService,
+ OPMLExporter $exporter
+ ) {
+ $this->folderService = $folderService;
+ $this->feedService = $feedService;
+ $this->itemService = $itemService;
+ $this->exporter = $exporter;
+ }
+
+ /**
+ * Export all feeds for a user.
+ *
+ * @param string $userId User ID
+ *
+ * @return string Exported OPML data
+ */
+ public function export(string $userId): string
+ {
+ $feeds = $this->feedService->findAllForUser($userId);
+ $folders = $this->folderService->findAllForUser($userId);
+
+ return $this->exporter->build($folders, $feeds)
+ ->saveXML();
+ }
+}
diff --git a/lib/Service/Service.php b/lib/Service/Service.php
index 33397bc0f..04965af4b 100644
--- a/lib/Service/Service.php
+++ b/lib/Service/Service.php
@@ -52,11 +52,12 @@ abstract class Service
/**
* Finds all items of a user
*
- * @param string $userId the name of the user
+ * @param string $userId The ID/name of the user
+ * @param array $params Filter parameters
*
* @return Entity[]
*/
- abstract public function findAllForUser(string $userId): array;
+ abstract public function findAllForUser(string $userId, array $params = []): array;
/**
* Finds all items
@@ -89,7 +90,7 @@ abstract class Service
* @param int $id the id of the entity
* @param string $userId the name of the user for security reasons
*
- * @return \OCP\AppFramework\Db\Entity the entity
+ * @return Entity the entity
* @throws ServiceNotFoundException if the entity does not exist, or there
* are more than one of it
*/
diff --git a/lib/Service/UpdaterService.php b/lib/Service/UpdaterService.php
index dadd667f5..c18eed8d7 100644
--- a/lib/Service/UpdaterService.php
+++ b/lib/Service/UpdaterService.php
@@ -14,14 +14,6 @@
namespace OCA\News\Service;
-use OCA\News\Db\ItemMapperV2;
-use OCA\News\Service\FeedServiceV2;
-use OCA\News\Service\FolderServiceV2;
-use OCA\News\Service\ItemServiceV2;
-use \OCA\News\Service\LegacyFolderService;
-use \OCA\News\Service\FeedService;
-use \OCA\News\Service\ItemService;
-
class UpdaterService
{