Skip to content

Commit

Permalink
Create V2 mapper, Service and management commands
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Molenaar <[email protected]>
  • Loading branch information
SMillerDev authored and Grotax committed Sep 27, 2020
1 parent 5687bac commit d00d1ab
Show file tree
Hide file tree
Showing 79 changed files with 2,434 additions and 561 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ jobs:
run: |
cd ../server
./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:feed:delete 'admin' $(./occ news:feed:list 'admin' | grep 'nextcloud\.com' -1 | head -1 | grep -oE '[0-9]*')
- name: Prep PHP tests
run: cd ../server/apps/news && make php-test-dependencies
- name: Integration tests
run: cd ../server/apps/news && make integration-test


1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 7 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ Before you update to a new version, [check the changelog](https://github.com/nex
<command>OCA\News\Command\Updater\UpdateFeed</command>
<command>OCA\News\Command\Updater\BeforeUpdate</command>
<command>OCA\News\Command\Updater\AfterUpdate</command>
<command>OCA\News\Command\Config\FolderList</command>
<command>OCA\News\Command\Config\FolderAdd</command>
<command>OCA\News\Command\Config\FolderDelete</command>
<command>OCA\News\Command\Config\FeedList</command>
<command>OCA\News\Command\Config\FeedAdd</command>
<command>OCA\News\Command\Config\FeedDelete</command>
<command>OCA\News\Command\Config\FeedDelete</command>
</commands>

<settings>
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"ext-json": "*",
"ext-simplexml": "*",
"ext-libxml": "*",
"andreskrey/readability.php": "^2.1"
"andreskrey/readability.php": "^2.1",
"ext-dom": "*"
},
"require-dev": {
"phpunit/phpunit": "9.2.6",
Expand Down
15 changes: 8 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions lib/Command/Config/FeedAdd.php
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;
}
}
56 changes: 56 additions & 0 deletions lib/Command/Config/FeedDelete.php
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;
}
}
61 changes: 61 additions & 0 deletions lib/Command/Config/FeedList.php
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));
}
}
58 changes: 58 additions & 0 deletions lib/Command/Config/FolderAdd.php
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;
}
}
Loading

0 comments on commit d00d1ab

Please sign in to comment.