]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Controller/ImportController.php
create controller to launch import command
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ImportController.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Controller;
4
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7 use Symfony\Component\Console\Input\ArrayInput;
8 use Symfony\Component\Console\Output\NullOutput;
9 use Symfony\Component\HttpFoundation\Request;
10 use Wallabag\CoreBundle\Command\ImportCommand;
11
12 class ImportController extends Controller
13 {
14 /**
15 * @param Request $request
16 *
17 * @Route("/import", name="import")
18 */
19 public function importAction(Request $request)
20 {
21 $command = new ImportCommand();
22 $command->setContainer($this->container);
23 $input = new ArrayInput(array('userId' => $this->getUser()->getId()));
24 $return = $command->run($input, new NullOutput());
25
26 if ($return == 0) {
27 $this->get('session')->getFlashBag()->add(
28 'notice',
29 'Import successful'
30 );
31 } else {
32 $this->get('session')->getFlashBag()->add(
33 'warning',
34 'Import failed'
35 );
36 }
37
38 return $this->redirect('/');
39 }
40 }