create controller to launch import command

This commit is contained in:
Nicolas Lœuillet
2015-09-30 15:10:46 +02:00
committed by Jeremy Benoist
parent a1bb1b3c2a
commit 8c3c77c1bd
3 changed files with 52 additions and 8 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace Wallabag\CoreBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\HttpFoundation\Request;
use Wallabag\CoreBundle\Command\ImportCommand;
class ImportController extends Controller
{
/**
* @param Request $request
*
* @Route("/import", name="import")
*/
public function importAction(Request $request)
{
$command = new ImportCommand();
$command->setContainer($this->container);
$input = new ArrayInput(array('userId' => $this->getUser()->getId()));
$return = $command->run($input, new NullOutput());
if ($return == 0) {
$this->get('session')->getFlashBag()->add(
'notice',
'Import successful'
);
} else {
$this->get('session')->getFlashBag()->add(
'warning',
'Import failed'
);
}
return $this->redirect('/');
}
}