Skip to content

Commit

Permalink
Move PostExporter to artisan
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Oct 29, 2017
1 parent 4cffa9a commit db1261e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 48 deletions.
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Kernel extends ConsoleKernel
\Ushahidi\Console\Command\UserCreate::class,
\Ushahidi\Console\Command\UserDelete::class,
\Ushahidi\Console\Command\Notification::class,
\Ushahidi\Console\Command\PostExporter::class,
\Ushahidi\Console\Command\SavedSearch::class,
\Ushahidi\Console\Command\Webhook::class
];
Expand Down
71 changes: 31 additions & 40 deletions src/Console/Command/PostExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Ushahidi\Console\Command;

use Ushahidi\Console\Command;
use Illuminate\Console\Command;

use Ushahidi\Core\Entity\PostExportRepository;
use Ushahidi\Factory\DataFactory;
use Ushahidi\Core\Traits\UserContext;
Expand All @@ -31,43 +32,40 @@ class PostExporter extends Command
private $data;
private $postExportRepository;

public function setDataFactory(DataFactory $data)
{
$this->data = $data;
}

public function setPostExportRepo(PostExportRepository $repo)
{
$this->postExportRepository = $repo;
}

protected function configure()
/**
* The console command name.
*
* @var string
*/
protected $name = 'export';

/**
* The console command signature.
*
* @var string
*/
protected $signature = 'export {--limit=100} {--offset=0}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Export posts';

public function __construct()
{
$this
->setName('exporter')
->setDescription('Export Posts')
->addArgument('action', InputArgument::OPTIONAL, 'list, export', 'list')
->addOption('limit', ['l'], InputOption::VALUE_OPTIONAL, 'limit')
->addOption('offset', ['o'], InputOption::VALUE_OPTIONAL, 'offset')
;
parent::__construct();
$this->data = service('factory.data');
$this->postExportRepository = service('repository.posts_export');
}

protected function executeList(InputInterface $input, OutputInterface $output)
public function fire()
{
return [
[
'Available actions' => 'export'
]
];
}

protected function executeExport(InputInterface $input, OutputInterface $output)
{

$data = $this->data->get('search');

$limit = $input->getOption('limit', 100);
$offset = $input->getOption('offset', 0);
$limit = $this->option('limit');
$offset = $this->option('offset');

$format = 'csv';

Expand Down Expand Up @@ -100,14 +98,7 @@ protected function executeExport(InputInterface $input, OutputInterface $output)
}

$res = service("formatter.entity.post.$format")->__invoke($posts);
$response = [
[
'Message' => sprintf('%d posts were found', $total)
]
];



$this->handleResponse($response, $output);
$this->info("{$total} posts were found");
}
}
8 changes: 0 additions & 8 deletions src/Console/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@
$di = service();

$di->set('authorizer.console', $di->lazyNew('Ushahidi\Console\Authorizer\ConsoleAuthorizer'));


// Post Exporter
$di->setter['Ushahidi\Console\Application']['injectCommands'][] =
$di->lazyNew('Ushahidi\Console\Command\PostExporter');
$di->setter['Ushahidi\Console\Command\PostExporter']['setPostExportRepo'] = $di->lazyGet('repository.posts_export');
$di->setter['Ushahidi\Console\Command\PostExporter']['setDataFactory'] = $di->lazyGet('factory.data');

0 comments on commit db1261e

Please sign in to comment.