1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
6
|
|
|
* |
7
|
|
|
* @license GNU General Public License version 3 or later. |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Kitodo\Dlf\Controller; |
13
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Common\Helper; |
15
|
|
|
use Kitodo\Dlf\Domain\Model\Format; |
16
|
|
|
use Kitodo\Dlf\Domain\Repository\FormatRepository; |
17
|
|
|
use Kitodo\Dlf\Domain\Repository\MetadataRepository; |
18
|
|
|
use Kitodo\Dlf\Domain\Repository\StructureRepository; |
19
|
|
|
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository; |
20
|
|
|
|
21
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
|
|
|
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
23
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
24
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
25
|
|
|
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; |
26
|
|
|
|
27
|
|
|
class NewTenantController extends AbstractController |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
protected $pid; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $pageInfo; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Backend Template Container |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $defaultViewObjectName = \TYPO3\CMS\Backend\View\BackendTemplateView::class; |
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var FormatRepository |
48
|
|
|
*/ |
49
|
|
|
protected $formatRepository; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param FormatRepository $formatRepository |
53
|
|
|
*/ |
54
|
|
|
public function injectFormatRepository(FormatRepository $formatRepository) |
55
|
|
|
{ |
56
|
|
|
$this->formatRepository = $formatRepository; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var MetadataRepository |
61
|
|
|
*/ |
62
|
|
|
protected $metadataRepository; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param MetadataRepository $metadataRepository |
66
|
|
|
*/ |
67
|
|
|
public function injectMetadataRepository(MetadataRepository $metadataRepository) |
68
|
|
|
{ |
69
|
|
|
$this->metadataRepository = $metadataRepository; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var StructureRepository |
74
|
|
|
*/ |
75
|
|
|
protected $structureRepository; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param StructureRepository $structureRepository |
79
|
|
|
*/ |
80
|
|
|
public function injectStructureRepository(StructureRepository $structureRepository) |
81
|
|
|
{ |
82
|
|
|
$this->structureRepository = $structureRepository; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var SolrCoreRepository |
87
|
|
|
*/ |
88
|
|
|
protected $solrCoreRepository; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param SolrCoreRepository $solrCoreRepository |
92
|
|
|
*/ |
93
|
|
|
public function injectSolrCoreRepository(SolrCoreRepository $solrCoreRepository) |
94
|
|
|
{ |
95
|
|
|
$this->solrCoreRepository = $solrCoreRepository; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Initialization for all actions |
100
|
|
|
* |
101
|
|
|
*/ |
102
|
|
|
protected function initializeAction() |
103
|
|
|
{ |
104
|
|
|
// Load backend localization file. |
105
|
|
|
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_be.xlf'); |
106
|
|
|
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_mod_newtenant.xlf'); |
107
|
|
|
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_structure.xlf'); |
108
|
|
|
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_metadata.xlf'); |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Action adding formats records |
115
|
|
|
*/ |
116
|
|
|
public function addFormatAction() |
117
|
|
|
{ |
118
|
|
|
// Include formats definition file. |
119
|
|
|
$formatsDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php'); |
120
|
|
|
|
121
|
|
|
$frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK); |
122
|
|
|
// tx_dlf_formats are stored on PID = 0 |
123
|
|
|
$frameworkConfiguration['persistence']['storagePid'] = 0; |
124
|
|
|
$this->configurationManager->setConfiguration($frameworkConfiguration); |
125
|
|
|
|
126
|
|
|
$allFormats = $this->formatRepository->findAll(); |
|
|
|
|
127
|
|
|
|
128
|
|
|
foreach ($formatsDefaults as $type => $values) { |
129
|
|
|
|
130
|
|
|
if ($this->formatRepository->findOneByType($type) === null) { |
|
|
|
|
131
|
|
|
$newFormat = GeneralUtility::makeInstance(Format::class); |
132
|
|
|
$newFormat->setType($type); |
133
|
|
|
$newFormat->setRoot($values['root']); |
134
|
|
|
$newFormat->setNamespace($values['namespace']); |
135
|
|
|
$newFormat->setClass($values['class']); |
136
|
|
|
$this->formatRepository->add($newFormat); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$this->forward('index'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Action adding metadata records |
146
|
|
|
*/ |
147
|
|
|
public function addMetadataAction() |
148
|
|
|
{ |
149
|
|
|
// Include metadata definition file. |
150
|
|
|
$metadataDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php'); |
151
|
|
|
$i = 0; |
152
|
|
|
// Build data array. |
153
|
|
|
$this->pid = (int) GeneralUtility::_GP('id'); |
154
|
|
|
|
155
|
|
|
foreach ($metadataDefaults as $index_name => $values) { |
156
|
|
|
$formatIds = []; |
157
|
|
|
foreach ($values['format'] as $format) { |
158
|
|
|
$formatIds[] = uniqid('NEW'); |
159
|
|
|
$data['tx_dlf_metadataformat'][end($formatIds)] = $format; |
160
|
|
|
$data['tx_dlf_metadataformat'][end($formatIds)]['pid'] = intval($this->pid); |
161
|
|
|
$i++; |
162
|
|
|
} |
163
|
|
|
$data['tx_dlf_metadata'][uniqid('NEW')] = [ |
164
|
|
|
'pid' => intval($this->pid), |
165
|
|
|
'label' => $this->getLanguageService()->getLL('metadata.' . $index_name), |
166
|
|
|
'index_name' => $index_name, |
167
|
|
|
'format' => implode(',', $formatIds), |
168
|
|
|
'default_value' => $values['default_value'], |
169
|
|
|
'wrap' => (!empty($values['wrap']) ? $values['wrap'] : $GLOBALS['TCA']['tx_dlf_metadata']['columns']['wrap']['config']['default']), |
170
|
|
|
'index_tokenized' => $values['index_tokenized'], |
171
|
|
|
'index_stored' => $values['index_stored'], |
172
|
|
|
'index_indexed' => $values['index_indexed'], |
173
|
|
|
'index_boost' => $values['index_boost'], |
174
|
|
|
'is_sortable' => $values['is_sortable'], |
175
|
|
|
'is_facet' => $values['is_facet'], |
176
|
|
|
'is_listed' => $values['is_listed'], |
177
|
|
|
'index_autocomplete' => $values['index_autocomplete'], |
178
|
|
|
]; |
179
|
|
|
$i++; |
180
|
|
|
} |
181
|
|
|
$_ids = Helper::processDBasAdmin($data, [], true); |
182
|
|
|
// Check for failed inserts. |
183
|
|
|
if (count($_ids) == $i) { |
184
|
|
|
// Fine. |
185
|
|
|
$this->addFlashMessage( |
186
|
|
|
$this->getLanguageService()->getLL('flash.metadataAddedMsg'), |
187
|
|
|
$this->getLanguageService()->getLL('flash.metadataAdded'), |
188
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
189
|
|
|
); |
190
|
|
|
} else { |
191
|
|
|
// Something went wrong. |
192
|
|
|
$this->addFlashMessage( |
193
|
|
|
$this->getLanguageService()->getLL('flash.metadataNotAddedMsg'), |
194
|
|
|
$this->getLanguageService()->getLL('flash.metadataNotAdded'), |
195
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
196
|
|
|
); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$this->forward('index'); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Action adding Solr core records |
204
|
|
|
*/ |
205
|
|
|
public function addSolrCoreAction() |
206
|
|
|
{ |
207
|
|
|
$this->pid = (int) GeneralUtility::_GP('id'); |
208
|
|
|
// Build data array. |
209
|
|
|
$data['tx_dlf_solrcores'][uniqid('NEW')] = [ |
210
|
|
|
'pid' => intval($this->pid), |
211
|
|
|
'label' => $this->getLanguageService()->getLL('flexform.solrcore') . ' (PID ' . $this->pid . ')', |
212
|
|
|
'index_name' => '', |
213
|
|
|
]; |
214
|
|
|
$_ids = Helper::processDBasAdmin($data); |
215
|
|
|
// Check for failed inserts. |
216
|
|
|
if (count($_ids) == 1) { |
217
|
|
|
// Fine. |
218
|
|
|
$this->addFlashMessage( |
219
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreAddedMsg'), |
220
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreAdded'), |
221
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
222
|
|
|
); |
223
|
|
|
} else { |
224
|
|
|
// Something went wrong. |
225
|
|
|
$this->addFlashMessage( |
226
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreNotAddedMsg'), |
227
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreNotAdded'), |
228
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
229
|
|
|
); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
$this->forward('index'); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Action adding structure records |
237
|
|
|
*/ |
238
|
|
|
public function addStructureAction() |
239
|
|
|
{ |
240
|
|
|
$this->pid = (int) GeneralUtility::_GP('id'); |
241
|
|
|
// Include structure definition file. |
242
|
|
|
$structureDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php'); |
243
|
|
|
// Build data array. |
244
|
|
|
foreach ($structureDefaults as $index_name => $values) { |
245
|
|
|
$data['tx_dlf_structures'][uniqid('NEW')] = [ |
246
|
|
|
'pid' => intval($this->pid), |
247
|
|
|
'toplevel' => $values['toplevel'], |
248
|
|
|
'label' => $this->getLanguageService()->getLL('structure.' . $index_name), |
249
|
|
|
'index_name' => $index_name, |
250
|
|
|
'oai_name' => $values['oai_name'], |
251
|
|
|
'thumbnail' => 0, |
252
|
|
|
]; |
253
|
|
|
} |
254
|
|
|
$_ids = Helper::processDBasAdmin($data, [], true); |
255
|
|
|
// Check for failed inserts. |
256
|
|
|
if (count($_ids) == count($structureDefaults)) { |
257
|
|
|
// Fine. |
258
|
|
|
$this->addFlashMessage( |
259
|
|
|
$this->getLanguageService()->getLL('flash.structureAddedMsg'), |
260
|
|
|
$this->getLanguageService()->getLL('flash.structureAdded'), |
261
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
262
|
|
|
); |
263
|
|
|
} else { |
264
|
|
|
// Something went wrong. |
265
|
|
|
$this->addFlashMessage( |
266
|
|
|
$this->getLanguageService()->getLL('flash.structureNotAddedMsg'), |
267
|
|
|
$this->getLanguageService()->getLL('flash.structureNotAdded'), |
268
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
269
|
|
|
); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
$this->forward('index'); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Set up the doc header properly here |
277
|
|
|
* |
278
|
|
|
* @param ViewInterface $view |
279
|
|
|
* @return void |
280
|
|
|
*/ |
281
|
|
|
protected function initializeView(ViewInterface $view) |
282
|
|
|
{ |
283
|
|
|
/** @var BackendTemplateView $view */ |
284
|
|
|
parent::initializeView($view); |
285
|
|
|
if ($this->actionMethodName == 'indexAction' |
286
|
|
|
|| $this->actionMethodName == 'onlineAction' |
287
|
|
|
|| $this->actionMethodName == 'compareAction') { |
288
|
|
|
$this->pid = (int) GeneralUtility::_GP('id'); |
289
|
|
|
$this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1)); |
290
|
|
|
$view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue()); |
291
|
|
|
} |
292
|
|
|
if ($view instanceof BackendTemplateView) { |
|
|
|
|
293
|
|
|
$view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal'); |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Main function of the module |
299
|
|
|
* |
300
|
|
|
* @access public |
301
|
|
|
* |
302
|
|
|
*/ |
303
|
|
|
public function indexAction() |
304
|
|
|
{ |
305
|
|
|
$this->pid = (int) GeneralUtility::_GP('id'); |
306
|
|
|
|
307
|
|
|
$formatsDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php'); |
308
|
|
|
|
309
|
|
|
if ($this->pageInfo['doktype'] != 254) { |
310
|
|
|
$this->addFlashMessage( |
311
|
|
|
$this->getLanguageService()->getLL('flash.wrongPageTypeMsg'), |
312
|
|
|
$this->getLanguageService()->getLL('flash.wrongPageType'), |
313
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
314
|
|
|
); |
315
|
|
|
return; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
$countFormats = $this->formatRepository->countAll(); |
319
|
|
|
|
320
|
|
|
if ($countFormats >= count($formatsDefaults)) { |
321
|
|
|
// Fine. |
322
|
|
|
$this->addFlashMessage( |
323
|
|
|
$this->getLanguageService()->getLL('flash.formatOkayMsg'), |
324
|
|
|
$this->getLanguageService()->getLL('flash.formatOkay'), |
325
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
326
|
|
|
); |
327
|
|
|
} else { |
328
|
|
|
// Configuration missing. |
329
|
|
|
$this->addFlashMessage( |
330
|
|
|
$this->getLanguageService()->getLL('flash.formatNotOkayMsg'), |
331
|
|
|
$this->getLanguageService()->getLL('flash.formatNotOkay'), |
332
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
333
|
|
|
); |
334
|
|
|
$this->view->assign('format', 1); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
$structures = $this->structureRepository->countByPid($this->pid); |
|
|
|
|
338
|
|
|
|
339
|
|
|
if ($structures) { |
340
|
|
|
// Fine. |
341
|
|
|
$this->addFlashMessage( |
342
|
|
|
$this->getLanguageService()->getLL('flash.structureOkayMsg'), |
343
|
|
|
$this->getLanguageService()->getLL('flash.structureOkay'), |
344
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
345
|
|
|
); |
346
|
|
|
} else { |
347
|
|
|
// Configuration missing. |
348
|
|
|
$this->addFlashMessage( |
349
|
|
|
$this->getLanguageService()->getLL('flash.structureNotOkayMsg'), |
350
|
|
|
$this->getLanguageService()->getLL('flash.structureNotOkay'), |
351
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
352
|
|
|
); |
353
|
|
|
$this->view->assign('structure', 1); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
$metadata = $this->metadataRepository->countByPid($this->pid); |
|
|
|
|
357
|
|
|
|
358
|
|
|
if ($metadata) { |
359
|
|
|
// Fine. |
360
|
|
|
$this->addFlashMessage( |
361
|
|
|
$this->getLanguageService()->getLL('flash.metadataOkayMsg'), |
362
|
|
|
$this->getLanguageService()->getLL('flash.metadataOkay'), |
363
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
364
|
|
|
); |
365
|
|
|
} else { |
366
|
|
|
// Configuration missing. |
367
|
|
|
$this->addFlashMessage( |
368
|
|
|
$this->getLanguageService()->getLL('flash.metadataNotOkayMsg'), |
369
|
|
|
$this->getLanguageService()->getLL('flash.metadataNotOkay'), |
370
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
371
|
|
|
); |
372
|
|
|
$this->view->assign('metadata', 1); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
$solrCore = $this->solrCoreRepository->countByPid($this->pid); |
|
|
|
|
376
|
|
|
|
377
|
|
|
if ($solrCore) { |
378
|
|
|
// Fine. |
379
|
|
|
$this->addFlashMessage( |
380
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreOkayMsg'), |
381
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreOkay'), |
382
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
383
|
|
|
); |
384
|
|
|
} else { |
385
|
|
|
// Solr core missing. |
386
|
|
|
$this->addFlashMessage( |
387
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreMissingMsg'), |
388
|
|
|
$this->getLanguageService()->getLL('flash.solrcoreMissing'), |
389
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING |
390
|
|
|
); |
391
|
|
|
$this->view->assign('solr', 1); |
392
|
|
|
} |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths