GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f98089...b28a0d )
by Mario
36:02
created

ExportController::exportAction()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 8.6257
c 0
b 0
f 0
cc 6
nc 3
nop 2
1
<?php
2
3
namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin;
4
5
use eZ\Publish\API\Repository\Values\Content\Content;
6
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute;
7
use eZ\Bundle\EzPublishCoreBundle\Controller;
8
use Netgen\InformationCollection\API\Service\Exporter;
9
use Netgen\InformationCollection\API\Value\Export\ExportCriteria;
10
use Netgen\InformationCollection\Form\Type\ExportType;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\Form\ClickableInterface;
13
use League\Csv\Writer;
14
use SplTempFileObject;
15
use Symfony\Component\HttpFoundation\Response;
16
17
final class ExportController extends Controller
18
{
19
    /**
20
     * @var \Netgen\InformationCollection\API\Service\Exporter
21
     */
22
    protected $exporter;
23
24
    /**
25
     * \Netgen\InformationCollection\API\Service\Exporter constructor.
26
     *
27
     * @param Exporter $exporter
28
     */
29
    public function __construct(Exporter $exporter)
30
    {
31
        $this->exporter = $exporter;
32
    }
33
34
    /**
35
     * Handles export
36
     *
37
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
38
     * @param \Symfony\Component\HttpFoundation\Request $request
39
     *
40
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
41
     */
42
    public function exportAction(Content $content, Request $request): Response
43
    {
44
        $attribute = new Attribute('infocollector', 'export');
45
        $this->denyAccessUnlessGranted($attribute);
46
47
        $form = $this->createForm(ExportType::class);
48
        $form->handleRequest($request);
49
50
        if ($form->get('cancel') instanceof ClickableInterface && $form->get('cancel')->isClicked()) {
51
            return $this->redirect($this->generateUrl('netgen_information_collection.route.admin.overview'));
52
        }
53
54
        if ($form->isValid() && $form->get('export') instanceof ClickableInterface && $form->get('export')->isClicked()) {
55
56
            $exportCriteria = new ExportCriteria(
57
                $content,
58
                $form->getData()['dateFrom'],
59
                $form->getData()['dateTo'],
60
                $form->getData()['offset'],
61
                $form->getData()['limit']
62
            );
63
64
            $export = $this->exporter->export($exportCriteria);
65
66
            $writer = Writer::createFromFileObject(new SplTempFileObject());
67
            $writer->setDelimiter(",");
68
            $writer->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries
69
            $writer->setOutputBOM(Writer::BOM_UTF8); //adding the BOM sequence on output
70
            $writer->insertOne($export->getHeader());
71
            $writer->insertAll($export->getContents());
72
73
            $writer->output('export.csv');
74
            return new Response('');
75
        }
76
77
        return $this->render("@NetgenInformationCollection/admin/export_menu.html.twig",
78
            [
79
                'content' => $content,
80
                'form' => $form->createView(),
81
            ]
82
        );
83
    }
84
}
85