Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix item lists in CLI #1180

Merged
merged 2 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/api-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,18 @@ jobs:
working-directory: ../server
run: |
./occ news:feed:add 'admin' "https://nextcloud.com/blog/feed/"
./occ news:feed:add 'admin' "https://github.com/nextcloud/news/releases.atom"
./occ news:feed:list 'admin' | grep 'nextcloud\.com'
./occ news:feed:list 'admin' | grep -F '"faviconLink": "https:\/\/nextcloud.com\/media\/screenshot-150x150.png"'

- name: Functional tests items
working-directory: ../server
run: |
TAG=$(curl --silent "https://api.github.com/repos/nextcloud/news/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep "$TAG"
./occ news:item:list-folder "admin" --limit 200 | grep "$TAG"
./occ news:item:list "admin" --limit 200 | grep "$TAG"

- name: Functional tests opml
working-directory: ../server
run: ./occ news:opml:export 'admin' | grep 'nextcloud\.com'
Expand All @@ -138,6 +147,7 @@ jobs:
run: |
./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]*')
./occ news:feed:delete 'admin' $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*')

- name: Prep PHP tests
working-directory: ../server/apps/news
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1
- Stop returning all feeds after marking folder as read.
- Always fetch favicon (#1164)
- Use feed logo instead of favicon if it exists and is square
- Add CI for item lists

### Fixed
- Item list throwing error for folder and "all items"

## [15.3.2] - 2021-02-10
No changes compared to RC2
Expand Down
3 changes: 3 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Before you update to a new version, [check the changelog](https://github.com/nex
<command>OCA\News\Command\Config\FeedDelete</command>
<command>OCA\News\Command\Config\FeedDelete</command>
<command>OCA\News\Command\Config\OpmlExport</command>
<command>OCA\News\Command\Debug\ItemList</command>
<command>OCA\News\Command\Debug\FolderItemList</command>
<command>OCA\News\Command\Debug\FeedItemList</command>
</commands>

<settings>
Expand Down
99 changes: 99 additions & 0 deletions lib/Command/Debug/FeedItemList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);

namespace OCA\News\Command\Debug;

use OCA\News\Controller\ApiPayloadTrait;
use OCA\News\Service\ItemServiceV2;
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 ItemList
*
* @package OCA\News\Command
*/
class FeedItemList extends Command
{
use ApiPayloadTrait;

/**
* @var ItemServiceV2 service for the items.
*/
protected $itemService;

public function __construct(ItemServiceV2 $itemService)
{
parent::__construct(null);

$this->itemService = $itemService;
}

/**
* Configure command
*
* @return void
*/
protected function configure()
{
$this->setName('news:item:list-feed')
->setDescription('List all items in a feed')
->addArgument('user-id', InputArgument::REQUIRED, 'User to list the items for')
->addArgument('feed', InputArgument::REQUIRED, 'Feed to list the items for')
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit for item amount', 40)
->addOption('offset', 'o', InputOption::VALUE_REQUIRED, 'Item list offset', 0)
->addOption('reverse-sort', null, InputOption::VALUE_NONE, 'Item list sorting')
->addOption('hide-read', null, InputOption::VALUE_NONE, 'Hide read items');
}

/**
* Execute command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user-id');

$feed = $input->getArgument('feed');
if (!is_numeric($feed)) {
$output->writeln('Invalid Type!');
return 255;
}

$limit = $input->getOption('limit');
if (!is_numeric($limit)) {
$output->writeln('Invalid limit!');
return 255;
}

$offset = $input->getOption('offset');
if (!is_numeric($offset)) {
$output->writeln('Invalid offset!');
return 255;
}

$reverseSort = $input->getOption('reverse-sort');
$hideRead = $input->getOption('hide-read');

$items = $this->itemService->findAllInFeedWithFilters(
$user,
intval($feed),
intval($limit),
intval($offset),
$hideRead,
$reverseSort,
[]
);

$output->writeln(json_encode($this->serialize($items), JSON_PRETTY_PRINT));

return 0;
}
}
100 changes: 100 additions & 0 deletions lib/Command/Debug/FolderItemList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
declare(strict_types=1);

namespace OCA\News\Command\Debug;

use OCA\News\Controller\ApiPayloadTrait;
use OCA\News\Service\ItemServiceV2;
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 ItemList
*
* @package OCA\News\Command
*/
class FolderItemList extends Command
{
use ApiPayloadTrait;

/**
* @var ItemServiceV2 service for the items.
*/
protected $itemService;

public function __construct(ItemServiceV2 $itemService)
{
parent::__construct(null);

$this->itemService = $itemService;
}

/**
* Configure command
*
* @return void
*/
protected function configure()
{
$this->setName('news:item:list-folder')
->setDescription('List all items in a folder')
->addArgument('user-id', InputArgument::REQUIRED, 'User to list the items for')
->addArgument('folder', InputArgument::OPTIONAL, 'Folder to list the items for')
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit for item amount', 40)
->addOption('offset', 'o', InputOption::VALUE_REQUIRED, 'Item list offset', 0)
->addOption('reverse-sort', null, InputOption::VALUE_NONE, 'Item list sorting')
->addOption('hide-read', null, InputOption::VALUE_NONE, 'Hide read items');
}

/**
* Execute command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user-id');

$folder = $input->getArgument('folder');
if (!is_null($folder) && !is_numeric($folder)) {
$output->writeln('Invalid folder ID!');
return 255;
}

$limit = $input->getOption('limit');
if (!is_numeric($limit)) {
$output->writeln('Invalid limit!');
return 255;
}

$offset = $input->getOption('offset');
if (!is_numeric($offset)) {
$output->writeln('Invalid offset!');
return 255;
}

$folder = is_null($folder) ? $folder : intval($folder);
$reverseSort = $input->getOption('reverse-sort');
$hideRead = $input->getOption('hide-read');

$items = $this->itemService->findAllInFolderWithFilters(
$user,
$folder,
intval($limit),
intval($offset),
$hideRead,
$reverseSort,
[]
);

$output->writeln(json_encode($this->serialize($items), JSON_PRETTY_PRINT));

return 0;
}
}
94 changes: 94 additions & 0 deletions lib/Command/Debug/ItemList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);

namespace OCA\News\Command\Debug;

use OCA\News\Controller\ApiPayloadTrait;
use OCA\News\Db\ListType;
use OCA\News\Service\ItemServiceV2;
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 ItemList
*
* @package OCA\News\Command
*/
class ItemList extends Command
{
use ApiPayloadTrait;

/**
* @var ItemServiceV2 service for the items.
*/
protected $itemService;

public function __construct(ItemServiceV2 $itemService)
{
parent::__construct(null);

$this->itemService = $itemService;
}

/**
* Configure command
*
* @return void
*/
protected function configure()
{
$this->setName('news:item:list')
->setDescription('List all items')
->addArgument('user-id', InputArgument::REQUIRED, 'User to list the items for')
->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Item type', ListType::ALL_ITEMS)
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit for item amount', 40)
->addOption('offset', 'o', InputOption::VALUE_REQUIRED, 'Item list offset', 0)
->addOption('reverse-sort', 'r', InputOption::VALUE_NONE, 'Item list sorting');
}

/**
* Execute command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user-id');

$type = $input->getOption('type');
if (!is_numeric($type)) {
$output->writeln('Invalid Type!');
return 255;
}
$limit = $input->getOption('limit');
if (!is_numeric($limit)) {
$output->writeln('Invalid limit!');
return 255;
}
$offset = $input->getOption('offset');
if (!is_numeric($offset)) {
$output->writeln('Invalid offset!');
return 255;
}
$reverseSort = $input->getOption('reverse-sort');

$items = $this->itemService->findAllWithFilters(
$user,
intval($type),
intval($limit),
intval($offset),
$reverseSort,
[]
);

$output->writeln(json_encode($this->serialize($items), JSON_PRETTY_PRINT));

return 0;
}
}
8 changes: 4 additions & 4 deletions lib/Controller/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use OCP\IConfig;
use OCP\AppFramework\Http;

use OCA\News\Db\FeedType;
use OCA\News\Db\ListType;
use OCP\IUserSession;

class FeedController extends Controller
Expand Down Expand Up @@ -122,18 +122,18 @@ public function active(): array

$feedType = intval($feedType);
switch ($feedType) {
case FeedType::FOLDER:
case ListType::FOLDER:
$this->folderService->find($this->getUserId(), $feedId);
break;
case FeedType::FEED:
case ListType::FEED:
$this->feedService->find($this->getUserId(), $feedId);
break;
default:
break;
}
} catch (ServiceNotFoundException $ex) {
$feedId = 0;
$feedType = FeedType::SUBSCRIPTIONS;
$feedType = ListType::ALL_ITEMS;
}

return [
Expand Down
Loading