forked from nextcloud/news
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <[email protected]>
- Loading branch information
1 parent
5687bac
commit d00d1ab
Showing
79 changed files
with
2,434 additions
and
561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,7 @@ | |
* [blackcrack](mailto:[email protected]) | ||
* [comradekingu](mailto:[email protected]) | ||
* [e-alfred](mailto:[email protected]) | ||
* [fran-penedo](mailto:[email protected]) | ||
* [joeplus](mailto:[email protected]_W_723V_1_32_000) | ||
* [kesselb](mailto:[email protected]) | ||
* [kondou](mailto:[email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace OCA\News\Command\Config; | ||
|
||
use OCA\News\Service\FeedServiceV2; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class FeedAdd extends Command | ||
{ | ||
/** | ||
* @var FeedServiceV2 service for the feeds. | ||
*/ | ||
protected $feedService; | ||
|
||
/** | ||
* FeedAdd constructor. | ||
* | ||
* @param FeedServiceV2 $feedService | ||
*/ | ||
public function __construct(FeedServiceV2 $feedService) | ||
{ | ||
parent::__construct(null); | ||
|
||
$this->feedService = $feedService; | ||
} | ||
|
||
/** | ||
* Configure command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('news:feed:add') | ||
->setDescription('Add a feed') | ||
->addArgument('userID', InputArgument::REQUIRED, 'User to add the feed for') | ||
->addArgument('feed', InputArgument::REQUIRED, 'Feed to parse') | ||
->addOption('folder', null, InputOption::VALUE_OPTIONAL, 'Folder ID') | ||
->addOption('title', null, InputOption::VALUE_OPTIONAL, 'Feed title') | ||
->addOption('full-text', null, InputOption::VALUE_OPTIONAL, 'Scrape item URLs', false) | ||
->addOption('username', null, InputOption::VALUE_OPTIONAL, 'Basic auth username') | ||
->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Basic auth password'); | ||
} | ||
|
||
/** | ||
* Execute command | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$url = $input->getArgument('feed'); | ||
$user = $input->getArgument('userID'); | ||
$folder = (int) $input->getOption('folder') ?? 0; | ||
$title = $input->getOption('title'); | ||
$username = $input->getOption('username'); | ||
$full_text = $input->getOption('full-text'); | ||
$password = $input->getOption('password'); | ||
|
||
$feed = $this->feedService->create($user, $url, $folder, $full_text, $title, $username, $password); | ||
$this->feedService->fetch($feed, true); | ||
|
||
$output->writeln(json_encode($feed->toAPI(), JSON_PRETTY_PRINT)); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace OCA\News\Command\Config; | ||
|
||
use OCA\News\Db\Feed; | ||
use OCA\News\Service\FeedServiceV2; | ||
use OCA\News\Service\FolderServiceV2; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class FeedDelete extends Command | ||
{ | ||
/** | ||
* @var FeedServiceV2 service for the feeds. | ||
*/ | ||
protected $feedService; | ||
|
||
public function __construct(FeedServiceV2 $feedService) | ||
{ | ||
parent::__construct(null); | ||
|
||
$this->feedService = $feedService; | ||
} | ||
|
||
/** | ||
* Configure command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('news:feed:delete') | ||
->setDescription('Remove a feed') | ||
->addArgument('userID', InputArgument::REQUIRED, 'User to remove the feed from') | ||
->addArgument('id', InputArgument::REQUIRED, 'Feed ID', null); | ||
} | ||
|
||
/** | ||
* Execute command | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$user = $input->getArgument('userID'); | ||
$id = $input->getArgument('id'); | ||
|
||
$this->feedService->delete($user, $id); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace OCA\News\Command\Config; | ||
|
||
use OCA\News\Controller\ApiPayloadTrait; | ||
use OCA\News\Service\FeedServiceV2; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class FeedList extends Command | ||
{ | ||
use ApiPayloadTrait; | ||
|
||
/** | ||
* @var FeedServiceV2 service for the feeds. | ||
*/ | ||
protected $feedService; | ||
|
||
public function __construct(FeedServiceV2 $feedService) | ||
{ | ||
parent::__construct(null); | ||
|
||
$this->feedService = $feedService; | ||
} | ||
|
||
/** | ||
* Configure command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('news:feed:list') | ||
->setDescription('List all feeds') | ||
->addArgument('userID', InputArgument::REQUIRED, 'User to list the feeds for') | ||
->addOption('recursive', null, InputOption::VALUE_NONE, 'Fetch the feed recursively'); | ||
} | ||
|
||
/** | ||
* Execute command | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int|void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$user = $input->getArgument('userID'); | ||
$recursive = $input->getOption('recursive'); | ||
|
||
if ($recursive !== false) { | ||
$feeds = $this->feedService->findAllForUserRecursive($user); | ||
} else { | ||
$feeds = $this->feedService->findAllForUser($user); | ||
} | ||
|
||
$output->writeln(json_encode($this->serialize($feeds), JSON_PRETTY_PRINT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace OCA\News\Command\Config; | ||
|
||
use OCA\News\Db\Feed; | ||
use OCA\News\Service\FeedServiceV2; | ||
use OCA\News\Service\FolderServiceV2; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class FolderAdd extends Command | ||
{ | ||
/** | ||
* @var FolderServiceV2 service for the folders. | ||
*/ | ||
protected $folderService; | ||
|
||
public function __construct(FolderServiceV2 $folderService) | ||
{ | ||
parent::__construct(null); | ||
|
||
$this->folderService = $folderService; | ||
} | ||
|
||
/** | ||
* Configure command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('news:folder:add') | ||
->setDescription('Add a folder') | ||
->addArgument('userID', InputArgument::REQUIRED, 'User to add the folder for') | ||
->addArgument('name', InputArgument::REQUIRED, 'Folder name', null) | ||
->addOption('parent', null, InputOption::VALUE_OPTIONAL, 'Parent folder'); | ||
} | ||
|
||
/** | ||
* Execute command | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$user = $input->getArgument('userID'); | ||
$name = $input->getArgument('name'); | ||
$parent = $input->getOption('parent') ?? 0; | ||
|
||
$this->folderService->create($user, $name, $parent); | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.