Passed
Push — master ( c8bbb4...290e8c )
by Ralf
02:24 queued 10s
created

DocumentFormBEController::createAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace EWW\Dpf\Controller;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use EWW\Dpf\Services\Transfer\ElasticsearchRepository;
18
19
class DocumentFormBEController extends AbstractDocumentFormController
20
{
21
22
    public function __construct()
23
    {
24
        parent::__construct();
25
26
    }
27
28
    protected function redirectToList($message = null)
29
    {
30
        $this->redirect('list', 'Document', null, array('message' => $message));
31
    }
32
33
    /**
34
     * action delete
35
     *
36
     * @param array $documentData
37
     * @throws \Exception
38
     */
39
    public function deleteAction($documentData)
40
    {
41
42
        if (!$GLOBALS['BE_USER']) {
43
            throw new \Exception('Access denied');
44
        }
45
46
        $document = $this->documentRepository->findByUid($documentData['documentUid']);
47
48
        $elasticsearchRepository = $this->objectManager->get(ElasticsearchRepository::class);
49
        // send document to index
50
        $elasticsearchRepository->delete($document, "");
51
52
        $document->setState(\EWW\Dpf\Domain\Model\Document::OBJECT_STATE_LOCALLY_DELETED);
53
        $document = $this->documentRepository->update($document);
0 ignored issues
show
Unused Code introduced by
The assignment to $document is dead and can be removed.
Loading history...
54
55
        $this->redirectToList();
56
    }
57
58
    public function editAction(\EWW\Dpf\Domain\Model\DocumentForm $documentForm)
59
    {
60
61
        $document = $this->documentRepository->findByUid($documentForm->getDocumentUid());
62
        $this->view->assign('document', $document);
63
        parent::editAction($documentForm);
64
    }
65
66
67
    public function createAction(\EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm)
68
    {
69
        parent::createAction($newDocumentForm);
70
        $this->redirectToList('CREATE_OK');
71
    }
72
}
73