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\Backend; |
13
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Common\Solr; |
15
|
|
|
use Kitodo\Dlf\Controller\AbstractController; |
16
|
|
|
use Kitodo\Dlf\Domain\Model\Format; |
17
|
|
|
use Kitodo\Dlf\Domain\Model\Metadata; |
18
|
|
|
use Kitodo\Dlf\Domain\Model\MetadataFormat; |
19
|
|
|
use Kitodo\Dlf\Domain\Model\SolrCore; |
20
|
|
|
use Kitodo\Dlf\Domain\Model\Structure; |
21
|
|
|
use Kitodo\Dlf\Domain\Repository\FormatRepository; |
22
|
|
|
use Kitodo\Dlf\Domain\Repository\MetadataRepository; |
23
|
|
|
use Kitodo\Dlf\Domain\Repository\StructureRepository; |
24
|
|
|
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository; |
25
|
|
|
|
26
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
27
|
|
|
use TYPO3\CMS\Core\Localization\LocalizationFactory; |
28
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
29
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
30
|
|
|
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; |
31
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
32
|
|
|
|
33
|
|
|
use TYPO3\CMS\Core\Exception\SiteNotFoundException; |
34
|
|
|
use TYPO3\CMS\Core\Site\Entity\NullSite; |
35
|
|
|
use TYPO3\CMS\Core\Site\Entity\Site; |
36
|
|
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage; |
37
|
|
|
use TYPO3\CMS\Core\Site\SiteFinder; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Controller class for the backend module 'New Tenant'. |
41
|
|
|
* |
42
|
|
|
* @author Christopher Timm <[email protected]> |
43
|
|
|
* @author Alexander Bigga <[email protected]> |
44
|
|
|
* @package TYPO3 |
45
|
|
|
* @subpackage dlf |
46
|
|
|
* @access public |
47
|
|
|
*/ |
48
|
|
|
class NewTenantController extends AbstractController |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $pid; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $pageInfo; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* All configured site languages |
62
|
|
|
* |
63
|
|
|
* @var array |
64
|
|
|
*/ |
65
|
|
|
protected $siteLanguages; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* LanguageFactory to get language key/values by our own. |
69
|
|
|
* |
70
|
|
|
* @var \TYPO3\CMS\Core\Localization\LocalizationFactory |
71
|
|
|
*/ |
72
|
|
|
protected $languageFactory; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Backend Template Container |
76
|
|
|
* |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
protected $defaultViewObjectName = \TYPO3\CMS\Backend\View\BackendTemplateView::class; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var FormatRepository |
83
|
|
|
*/ |
84
|
|
|
protected $formatRepository; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param FormatRepository $formatRepository |
88
|
|
|
*/ |
89
|
|
|
public function injectFormatRepository(FormatRepository $formatRepository) |
90
|
|
|
{ |
91
|
|
|
$this->formatRepository = $formatRepository; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var MetadataRepository |
96
|
|
|
*/ |
97
|
|
|
protected $metadataRepository; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param MetadataRepository $metadataRepository |
101
|
|
|
*/ |
102
|
|
|
public function injectMetadataRepository(MetadataRepository $metadataRepository) |
103
|
|
|
{ |
104
|
|
|
$this->metadataRepository = $metadataRepository; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var StructureRepository |
109
|
|
|
*/ |
110
|
|
|
protected $structureRepository; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param StructureRepository $structureRepository |
114
|
|
|
*/ |
115
|
|
|
public function injectStructureRepository(StructureRepository $structureRepository) |
116
|
|
|
{ |
117
|
|
|
$this->structureRepository = $structureRepository; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var SolrCoreRepository |
122
|
|
|
*/ |
123
|
|
|
protected $solrCoreRepository; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param SolrCoreRepository $solrCoreRepository |
127
|
|
|
*/ |
128
|
|
|
public function injectSolrCoreRepository(SolrCoreRepository $solrCoreRepository) |
129
|
|
|
{ |
130
|
|
|
$this->solrCoreRepository = $solrCoreRepository; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Initialization for all actions |
135
|
|
|
* |
136
|
|
|
*/ |
137
|
|
|
protected function initializeAction() |
138
|
|
|
{ |
139
|
|
|
$this->pid = (int) GeneralUtility::_GP('id'); |
140
|
|
|
|
141
|
|
|
$frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK); |
142
|
|
|
$frameworkConfiguration['persistence']['storagePid'] = $this->pid; |
143
|
|
|
$this->configurationManager->setConfiguration($frameworkConfiguration); |
144
|
|
|
|
145
|
|
|
$this->languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class); |
146
|
|
|
|
147
|
|
|
try { |
148
|
|
|
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($this->pid); |
149
|
|
|
} catch (SiteNotFoundException $e) { |
150
|
|
|
$site = new NullSite(); |
151
|
|
|
} |
152
|
|
|
$this->siteLanguages = $site->getLanguages(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Action adding formats records |
158
|
|
|
*/ |
159
|
|
|
public function addFormatAction() |
160
|
|
|
{ |
161
|
|
|
// Include formats definition file. |
162
|
|
|
$formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php'); |
163
|
|
|
|
164
|
|
|
$frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK); |
165
|
|
|
// tx_dlf_formats are stored on PID = 0 |
166
|
|
|
$frameworkConfiguration['persistence']['storagePid'] = 0; |
167
|
|
|
$this->configurationManager->setConfiguration($frameworkConfiguration); |
168
|
|
|
|
169
|
|
|
$doPersist = false; |
170
|
|
|
|
171
|
|
|
foreach ($formatsDefaults as $type => $values) { |
172
|
|
|
// if default format record is not found, add it to the repository |
173
|
|
|
if ($this->formatRepository->findOneByType($type) === null) { |
|
|
|
|
174
|
|
|
$newRecord = GeneralUtility::makeInstance(Format::class); |
175
|
|
|
$newRecord->setType($type); |
176
|
|
|
$newRecord->setRoot($values['root']); |
177
|
|
|
$newRecord->setNamespace($values['namespace']); |
178
|
|
|
$newRecord->setClass($values['class']); |
179
|
|
|
$this->formatRepository->add($newRecord); |
180
|
|
|
|
181
|
|
|
$doPersist = true; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
// We must persist here, if we changed anything. |
186
|
|
|
if ($doPersist === true) { |
187
|
|
|
$persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
188
|
|
|
$persistenceManager->persistAll(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$this->forward('index'); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Action adding metadata records |
196
|
|
|
*/ |
197
|
|
|
public function addMetadataAction() |
198
|
|
|
{ |
199
|
|
|
// Include metadata definition file. |
200
|
|
|
$metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php'); |
201
|
|
|
|
202
|
|
|
$doPersist = false; |
203
|
|
|
|
204
|
|
|
// load language file in own array |
205
|
|
|
$metadataLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_metadata.xlf', $this->siteLanguages[0]->getTypo3Language()); |
206
|
|
|
|
207
|
|
|
foreach ($metadataDefaults as $indexName => $values) { |
208
|
|
|
// if default format record is not found, add it to the repository |
209
|
|
|
if ($this->metadataRepository->findOneByIndexName($indexName) === null) { |
|
|
|
|
210
|
|
|
|
211
|
|
|
$newRecord = GeneralUtility::makeInstance(Metadata::class); |
212
|
|
|
$newRecord->setLabel($this->getLLL('metadata.' . $indexName, $this->siteLanguages[0]->getTypo3Language(), $metadataLabels)); |
213
|
|
|
$newRecord->setIndexName($indexName); |
214
|
|
|
$newRecord->setDefaultValue($values['default_value']); |
215
|
|
|
$newRecord->setWrap($values['wrap'] ? : $GLOBALS['TCA']['tx_dlf_metadata']['columns']['wrap']['config']['default']); |
216
|
|
|
$newRecord->setIndexTokenized($values['index_tokenized']); |
217
|
|
|
$newRecord->setIndexStored((int) $values['index_stored']); |
218
|
|
|
$newRecord->setIndexIndexed((int) $values['index_indexed']); |
219
|
|
|
$newRecord->setIndexBoost((float) $values['index_boost']); |
220
|
|
|
$newRecord->setIsSortable((int) $values['is_sortable']); |
221
|
|
|
$newRecord->setIsFacet((int) $values['is_facet']); |
222
|
|
|
$newRecord->setIsListed((int) $values['is_listed']); |
223
|
|
|
$newRecord->setIndexAutocomplete((int) $values['index_autocomplete']); |
224
|
|
|
|
225
|
|
|
if (is_array($values['format'])) { |
226
|
|
|
foreach ($values['format'] as $format) { |
227
|
|
|
$formatRecord = $this->formatRepository->findOneByRoot($format['format_root']); |
|
|
|
|
228
|
|
|
// If formatRecord is null, we cannot create a MetadataFormat record. |
229
|
|
|
if ($formatRecord !== null) { |
230
|
|
|
$newMetadataFormat = GeneralUtility::makeInstance(MetadataFormat::class); |
231
|
|
|
$newMetadataFormat->setEncoded($formatRecord->getUid()); |
|
|
|
|
232
|
|
|
$newMetadataFormat->setXpath($format['xpath']); |
233
|
|
|
$newMetadataFormat->setXpathSorting($format['xpath_sorting']); |
234
|
|
|
$newRecord->addFormat($newMetadataFormat); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
foreach ($this->siteLanguages as $siteLanguage) { |
240
|
|
|
if ($siteLanguage->getLanguageId() === 0) { |
241
|
|
|
// skip default language |
242
|
|
|
continue; |
243
|
|
|
} |
244
|
|
|
$translatedRecord = GeneralUtility::makeInstance(Metadata::class); |
245
|
|
|
$translatedRecord->setL18nParent($newRecord); |
246
|
|
|
$translatedRecord->_setProperty('_languageUid', $siteLanguage->getLanguageId()); |
247
|
|
|
$translatedRecord->setLabel($this->getLLL('metadata.' . $indexName, $siteLanguage->getTypo3Language(), $metadataLabels)); |
248
|
|
|
$translatedRecord->setIndexName($indexName); |
249
|
|
|
$translatedRecord->setWrap($newRecord->getWrap()); |
250
|
|
|
|
251
|
|
|
$this->metadataRepository->add($translatedRecord); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
$this->metadataRepository->add($newRecord); |
255
|
|
|
|
256
|
|
|
$doPersist = true; |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
// We must persist here, if we changed anything. |
261
|
|
|
if ($doPersist === true) { |
262
|
|
|
$persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
263
|
|
|
$persistenceManager->persistAll(); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$this->forward('index'); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Action adding Solr core records |
271
|
|
|
*/ |
272
|
|
|
public function addSolrCoreAction() |
273
|
|
|
{ |
274
|
|
|
$doPersist = false; |
275
|
|
|
|
276
|
|
|
// load language file in own array |
277
|
|
|
$beLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_be.xlf', $this->siteLanguages[0]->getTypo3Language()); |
278
|
|
|
|
279
|
|
|
if ($this->solrCoreRepository->findOneByPid($this->pid) === null) { |
|
|
|
|
280
|
|
|
$newRecord = GeneralUtility::makeInstance(SolrCore::class); |
281
|
|
|
$newRecord->setLabel($this->getLLL('flexform.solrcore', $this->siteLanguages[0]->getTypo3Language(), $beLabels). ' (PID ' . $this->pid . ')'); |
282
|
|
|
$indexName = Solr::createCore(''); |
283
|
|
|
$newRecord->setIndexName($indexName); |
284
|
|
|
|
285
|
|
|
$this->solrCoreRepository->add($newRecord); |
286
|
|
|
|
287
|
|
|
$doPersist = true; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
// We must persist here, if we changed anything. |
291
|
|
|
if ($doPersist === true) { |
292
|
|
|
$persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
293
|
|
|
$persistenceManager->persistAll(); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
$this->forward('index'); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Action adding structure records |
301
|
|
|
*/ |
302
|
|
|
public function addStructureAction() |
303
|
|
|
{ |
304
|
|
|
// Include structure definition file. |
305
|
|
|
$structureDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php'); |
306
|
|
|
|
307
|
|
|
$doPersist = false; |
308
|
|
|
|
309
|
|
|
// load language file in own array |
310
|
|
|
$structLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_structure.xlf', $this->siteLanguages[0]->getTypo3Language()); |
311
|
|
|
|
312
|
|
|
foreach ($structureDefaults as $indexName => $values) { |
313
|
|
|
// if default format record is not found, add it to the repository |
314
|
|
|
if ($this->structureRepository->findOneByIndexName($indexName) === null) { |
|
|
|
|
315
|
|
|
$newRecord = GeneralUtility::makeInstance(Structure::class); |
316
|
|
|
$newRecord->setLabel($this->getLLL('structure.' . $indexName, $this->siteLanguages[0]->getTypo3Language(), $structLabels)); |
317
|
|
|
$newRecord->setIndexName($indexName); |
318
|
|
|
$newRecord->setToplevel($values['toplevel']); |
319
|
|
|
$newRecord->setOaiName($values['oai_name']); |
320
|
|
|
$this->structureRepository->add($newRecord); |
321
|
|
|
|
322
|
|
|
foreach ($this->siteLanguages as $siteLanguage) { |
323
|
|
|
if ($siteLanguage->getLanguageId() === 0) { |
324
|
|
|
// skip default language |
325
|
|
|
continue; |
326
|
|
|
} |
327
|
|
|
$translatedRecord = GeneralUtility::makeInstance(Structure::class); |
328
|
|
|
$translatedRecord->setL18nParent($newRecord); |
329
|
|
|
$translatedRecord->_setProperty('_languageUid', $siteLanguage->getLanguageId()); |
330
|
|
|
$translatedRecord->setLabel($this->getLLL('structure.' . $indexName, $siteLanguage->getTypo3Language(), $structLabels)); |
331
|
|
|
$translatedRecord->setIndexName($indexName); |
332
|
|
|
|
333
|
|
|
$this->structureRepository->add($translatedRecord); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
$doPersist = true; |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
// We must persist here, if we changed anything. |
341
|
|
|
if ($doPersist === true) { |
342
|
|
|
$persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
343
|
|
|
$persistenceManager->persistAll(); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
$this->forward('index'); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Set up the doc header properly here |
351
|
|
|
* |
352
|
|
|
* @param ViewInterface $view |
353
|
|
|
* @return void |
354
|
|
|
*/ |
355
|
|
|
protected function initializeView(ViewInterface $view) |
356
|
|
|
{ |
357
|
|
|
/** @var BackendTemplateView $view */ |
358
|
|
|
parent::initializeView($view); |
359
|
|
|
if ($this->actionMethodName == 'indexAction') { |
360
|
|
|
$this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1)); |
|
|
|
|
361
|
|
|
$view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue()); |
362
|
|
|
} |
363
|
|
|
if ($view instanceof BackendTemplateView) { |
|
|
|
|
364
|
|
|
$view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal'); |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Main function of the module |
370
|
|
|
* |
371
|
|
|
* @access public |
372
|
|
|
* |
373
|
|
|
*/ |
374
|
|
|
public function indexAction() |
375
|
|
|
{ |
376
|
|
|
$recordInfos = []; |
377
|
|
|
|
378
|
|
|
if ($this->pageInfo['doktype'] != 254) { |
379
|
|
|
$this->forward('error'); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
$formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php'); |
383
|
|
|
$recordInfos['formats']['numCurrent'] = $this->formatRepository->countAll(); |
384
|
|
|
$recordInfos['formats']['numDefault'] = count($formatsDefaults); |
385
|
|
|
|
386
|
|
|
$structuresDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php'); |
387
|
|
|
$recordInfos['structures']['numCurrent'] = $this->structureRepository->countByPid($this->pid); |
|
|
|
|
388
|
|
|
$recordInfos['structures']['numDefault'] = count($structuresDefaults); |
389
|
|
|
|
390
|
|
|
$metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php'); |
391
|
|
|
$recordInfos['metadata']['numCurrent'] = $this->metadataRepository->countByPid($this->pid); |
|
|
|
|
392
|
|
|
$recordInfos['metadata']['numDefault'] = count($metadataDefaults); |
393
|
|
|
|
394
|
|
|
$recordInfos['solrcore']['numCurrent'] = $this->solrCoreRepository->countByPid($this->pid); |
|
|
|
|
395
|
|
|
|
396
|
|
|
$this->view->assign('recordInfos', $recordInfos); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Error function - there is nothing to do at the moment. |
401
|
|
|
* |
402
|
|
|
* @access public |
403
|
|
|
* |
404
|
|
|
*/ |
405
|
|
|
public function errorAction() |
406
|
|
|
{ |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Get language label for given key and language. |
411
|
|
|
* |
412
|
|
|
* @param string $index |
413
|
|
|
* @param string $lang |
414
|
|
|
* @param array $langArray |
415
|
|
|
* |
416
|
|
|
* @access public |
417
|
|
|
*/ |
418
|
|
|
protected function getLLL($index, $lang, $langArray) |
419
|
|
|
{ |
420
|
|
|
if (isset($langArray[$lang][$index][0]['target'])) { |
421
|
|
|
return $langArray[$lang][$index][0]['target']; |
422
|
|
|
} else { |
423
|
|
|
return $langArray['default'][$index][0]['target']; |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
} |
427
|
|
|
|