Completed
Push — master ( 543fe1...7ff5ba )
by diego
14:03
created

ImportrController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 9
cp 0
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 5
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HDNET\Importr\Controller;
6
7
use HDNET\Importr\Domain\Model\Import;
8
use HDNET\Importr\Domain\Model\Strategy;
9
use HDNET\Importr\Domain\Repository\ImportRepository;
10
use HDNET\Importr\Domain\Repository\StrategyRepository;
11
use HDNET\Importr\Service\ImportServiceInterface;
12
use HDNET\Importr\Service\Manager;
13
use TYPO3\CMS\Core\Messaging\FlashMessage;
14
use TYPO3\CMS\Core\Messaging\FlashMessageService;
15
use TYPO3\CMS\Core\Resource\ResourceFactory;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
18
19
/**
20
 * Description of ImportrController
21
 *
22
 * @author timlochmueller
23
 */
24
class ImportrController extends ActionController
25
{
26
    /**
27
     * @var \TYPO3\CMS\Core\Resource\ResourceFactory
28
     */
29
    protected $resourceFactory;
30
31
    /**
32
     * @var \HDNET\Importr\Domain\Repository\StrategyRepository
33
     */
34
    protected $strategyRepository;
35
36
    /**
37
     * @var \HDNET\Importr\Domain\Repository\ImportRepository
38
     */
39
    protected $importRepository;
40
41
    /**
42
     * @var \HDNET\Importr\Service\Manager
43
     */
44
    protected $importManager;
45
46
    /**
47
     * @var \HDNET\Importr\Service\ImportServiceInterface
48
     */
49
    protected $importService;
50
51
    public function __construct(
52
        ResourceFactory $resourceFactory,
53
        StrategyRepository $strategyRepository,
54
        ImportRepository $importRepository,
55
        Manager $importManager,
56
        ImportServiceInterface $importService
57
    ) {
58
        $this->resourceFactory = $resourceFactory;
59
        $this->strategyRepository = $strategyRepository;
60
        $this->importRepository = $importRepository;
61
        $this->importManager = $importManager;
62
        $this->importService = $importService;
63
    }
64
65
    public function indexAction()
66
    {
67
        $combinedIdentifier = GeneralUtility::_GP('id');
68
        if (isset($combinedIdentifier) && \is_string($combinedIdentifier)) {
69
            $folder = $this->resourceFactory->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
70
            $files = [];
71
            foreach ($folder->getFiles() as $file) {
72
                $files[$file->getStorage()
73
                    ->getUid() . ':' . $file->getIdentifier()] = $file->getName();
74
            }
75
            $this->view->assign('folder', $files);
76
        }
77
        $this->view->assign('imports', $this->importRepository->findUserQueue());
78
    }
79
80
    /**
81
     * @param string $identifier
82
     */
83
    public function importAction($identifier)
84
    {
85
        $file = $this->resourceFactory->getObjectFromCombinedIdentifier($identifier);
86
        $this->view->assign('file', $file);
87
        $this->view->assign('strategies', $this->strategyRepository->findAllUser());
88
    }
89
90
    /**
91
     * @param string $identifier
92
     * @param \HDNET\Importr\Domain\Model\Strategy $strategy
93
     */
94
    public function previewAction($identifier, Strategy $strategy)
95
    {
96
        $file = $this->resourceFactory->getObjectFromCombinedIdentifier($identifier);
97
        $this->view->assign('filepath', $file->getPublicUrl());
98
        $this->view->assign('strategy', $strategy);
99
100
        $previewData = $this->importManager->getPreview($strategy, $file->getPublicUrl());
101
        $this->view->assign('preview', $previewData);
102
    }
103
104
    /**
105
     * @param string $filepath
106
     * @param \HDNET\Importr\Domain\Model\Strategy $strategy
107
     */
108
    public function createAction($filepath, Strategy $strategy)
109
    {
110
        $this->importService->addToQueue($filepath, $strategy);
111
        $text = 'The Import file %s width the strategy %s was successfully added to the queue';
112
        $message = GeneralUtility::makeInstance(
113
            FlashMessage::class,
114
            \sprintf($text, $filepath, $strategy->getTitle()),
115
            'Import is in Queue',
116
            FlashMessage::INFO,
117
            true
118
        );
119
120
        $flashMessageService = $this->objectManager->get(
0 ignored issues
show
Deprecated Code introduced by
The method TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated with message: since TYPO3 10.4, will be removed in version 12.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
121
            FlashMessageService::class
122
        );
123
        $messageQueue = $flashMessageService->getMessageQueueByIdentifier();
124
        $messageQueue->addMessage($message);
125
126
        $this->redirect('index');
127
    }
128
129
    /**
130
     * @param Import $import
131
     */
132
    public function resetAction(Import $import)
133
    {
134
        $import->reset();
135
        $this->importRepository->update($import);
136
        $this->redirect('index');
137
    }
138
}
139