aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/ImportController.php
blob: 53211eec4f8b783ddc66f995dd1b20bf9f9ab83f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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('/');
    }
}