|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kitodo\Dlf\Module; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU General Public License version 3 or later. |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Module 'New Tenant' for the 'dlf' extension. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
20
|
|
|
* @package TYPO3 |
|
21
|
|
|
* @subpackage dlf |
|
22
|
|
|
* @access public |
|
23
|
|
|
*/ |
|
24
|
|
|
class NewTenant extends \Kitodo\Dlf\Common\AbstractModule { |
|
25
|
|
|
protected $markerArray = [ |
|
26
|
|
|
'CSH' => '', |
|
27
|
|
|
'MOD_MENU' => '', |
|
28
|
|
|
'CONTENT' => '', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Add metadata configuration |
|
33
|
|
|
* |
|
34
|
|
|
* @access protected |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function cmdAddMetadata() { |
|
39
|
|
|
// Include metadata definition file. |
|
40
|
|
|
include_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey).'Resources/Private/Data/MetadataDefaults.php'); |
|
41
|
|
|
$i = 0; |
|
42
|
|
|
// Build data array. |
|
43
|
|
|
foreach ($metadataDefaults as $index_name => $values) { |
|
|
|
|
|
|
44
|
|
|
$formatIds = []; |
|
45
|
|
|
foreach ($values['format'] as $format) { |
|
46
|
|
|
$formatIds[] = uniqid('NEW'); |
|
47
|
|
|
$data['tx_dlf_metadataformat'][end($formatIds)] = $format; |
|
48
|
|
|
$data['tx_dlf_metadataformat'][end($formatIds)]['pid'] = intval($this->id); |
|
49
|
|
|
$i++; |
|
50
|
|
|
} |
|
51
|
|
|
$data['tx_dlf_metadata'][uniqid('NEW')] = [ |
|
52
|
|
|
'pid' => intval($this->id), |
|
53
|
|
|
'label' => $GLOBALS['LANG']->getLL($index_name), |
|
54
|
|
|
'index_name' => $index_name, |
|
55
|
|
|
'format' => implode(',', $formatIds), |
|
56
|
|
|
'default_value' => $values['default_value'], |
|
57
|
|
|
'wrap' => (!empty($values['wrap']) ? $values['wrap'] : $GLOBALS['TCA']['tx_dlf_metadata']['columns']['wrap']['config']['default']), |
|
58
|
|
|
'index_tokenized' => $values['index_tokenized'], |
|
59
|
|
|
'index_stored' => $values['index_stored'], |
|
60
|
|
|
'index_indexed' => $values['index_indexed'], |
|
61
|
|
|
'index_boost' => $values['index_boost'], |
|
62
|
|
|
'is_sortable' => $values['is_sortable'], |
|
63
|
|
|
'is_facet' => $values['is_facet'], |
|
64
|
|
|
'is_listed' => $values['is_listed'], |
|
65
|
|
|
'index_autocomplete' => $values['index_autocomplete'], |
|
66
|
|
|
]; |
|
67
|
|
|
$i++; |
|
68
|
|
|
} |
|
69
|
|
|
$_ids = Helper::processDBasAdmin($data, [], TRUE); |
|
|
|
|
|
|
70
|
|
|
// Check for failed inserts. |
|
71
|
|
|
if (count($_ids) == $i) { |
|
72
|
|
|
// Fine. |
|
73
|
|
|
Helper::addMessage( |
|
74
|
|
|
Helper::getMessage('flash.metadataAddedMsg'), |
|
75
|
|
|
Helper::getMessage('flash.metadataAdded', TRUE), |
|
76
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
|
77
|
|
|
); |
|
78
|
|
|
} else { |
|
79
|
|
|
// Something went wrong. |
|
80
|
|
|
Helper::addMessage( |
|
81
|
|
|
Helper::getMessage('flash.metadataNotAddedMsg'), |
|
82
|
|
|
Helper::getMessage('flash.metadataNotAdded', TRUE), |
|
83
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Add Solr core |
|
90
|
|
|
* |
|
91
|
|
|
* @access protected |
|
92
|
|
|
* |
|
93
|
|
|
* @return void |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function cmdAddSolrCore() { |
|
96
|
|
|
// Build data array. |
|
97
|
|
|
$data['tx_dlf_solrcores'][uniqid('NEW')] = [ |
|
|
|
|
|
|
98
|
|
|
'pid' => intval($this->id), |
|
99
|
|
|
'label' => $GLOBALS['LANG']->getLL('solrcore').' (PID '.$this->id.')', |
|
100
|
|
|
'index_name' => '', |
|
101
|
|
|
]; |
|
102
|
|
|
$_ids = Helper::processDBasAdmin($data); |
|
103
|
|
|
// Check for failed inserts. |
|
104
|
|
|
if (count($_ids) == 1) { |
|
105
|
|
|
// Fine. |
|
106
|
|
|
Helper::addMessage( |
|
107
|
|
|
Helper::getMessage('flash.solrcoreAddedMsg'), |
|
108
|
|
|
Helper::getMessage('flash.solrcoreAdded', TRUE), |
|
109
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
|
110
|
|
|
); |
|
111
|
|
|
} else { |
|
112
|
|
|
// Something went wrong. |
|
113
|
|
|
Helper::addMessage( |
|
114
|
|
|
Helper::getMessage('flash.solrcoreNotAddedMsg'), |
|
115
|
|
|
Helper::getMessage('flash.solrcoreNotAdded', TRUE), |
|
116
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Add structure configuration |
|
123
|
|
|
* |
|
124
|
|
|
* @access protected |
|
125
|
|
|
* |
|
126
|
|
|
* @return void |
|
127
|
|
|
*/ |
|
128
|
|
|
protected function cmdAddStructure() { |
|
129
|
|
|
// Include structure definition file. |
|
130
|
|
|
include_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey).'Resources/Private/Data/StructureDefaults.php'); |
|
131
|
|
|
// Build data array. |
|
132
|
|
|
foreach ($structureDefaults as $index_name => $values) { |
|
|
|
|
|
|
133
|
|
|
$data['tx_dlf_structures'][uniqid('NEW')] = [ |
|
134
|
|
|
'pid' => intval($this->id), |
|
135
|
|
|
'toplevel' => $values['toplevel'], |
|
136
|
|
|
'label' => $GLOBALS['LANG']->getLL($index_name), |
|
137
|
|
|
'index_name' => $index_name, |
|
138
|
|
|
'oai_name' => $values['oai_name'], |
|
139
|
|
|
'thumbnail' => 0, |
|
140
|
|
|
]; |
|
141
|
|
|
} |
|
142
|
|
|
$_ids = Helper::processDBasAdmin($data, [], TRUE); |
|
|
|
|
|
|
143
|
|
|
// Check for failed inserts. |
|
144
|
|
|
if (count($_ids) == count($structureDefaults)) { |
|
145
|
|
|
// Fine. |
|
146
|
|
|
Helper::addMessage( |
|
147
|
|
|
Helper::getMessage('flash.structureAddedMsg'), |
|
148
|
|
|
Helper::getMessage('flash.structureAdded', TRUE), |
|
149
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
|
150
|
|
|
); |
|
151
|
|
|
} else { |
|
152
|
|
|
// Something went wrong. |
|
153
|
|
|
Helper::addMessage( |
|
154
|
|
|
Helper::getMessage('flash.structureNotAddedMsg'), |
|
155
|
|
|
Helper::getMessage('flash.structureNotAdded', TRUE), |
|
156
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
|
157
|
|
|
); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Main function of the module |
|
163
|
|
|
* |
|
164
|
|
|
* @access public |
|
165
|
|
|
* |
|
166
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request: The request object |
|
167
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response: The response object |
|
168
|
|
|
* |
|
169
|
|
|
* @return \Psr\Http\Message\ResponseInterface The response object |
|
170
|
|
|
*/ |
|
171
|
|
|
public function main(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response) { |
|
172
|
|
|
$this->response = $response; |
|
173
|
|
|
// Initialize module. |
|
174
|
|
|
$this->MCONF = [ |
|
175
|
|
|
'name' => 'tools_dlfNewTenantModule', |
|
176
|
|
|
'access' => 'admin' |
|
177
|
|
|
]; |
|
178
|
|
|
$GLOBALS['BE_USER']->modAccess($this->MCONF, 1); |
|
179
|
|
|
parent::init(); |
|
180
|
|
|
$this->pageInfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause); |
|
181
|
|
|
// Is the user allowed to access this page? |
|
182
|
|
|
$access = is_array($this->pageInfo) && $GLOBALS['BE_USER']->isAdmin(); |
|
183
|
|
|
if ($this->id && $access) { |
|
184
|
|
|
// Check if page is sysfolder. |
|
185
|
|
|
if ($this->pageInfo['doktype'] != 254) { |
|
186
|
|
|
Helper::addMessage( |
|
187
|
|
|
Helper::getMessage('flash.wrongPageTypeMsg'), |
|
188
|
|
|
Helper::getMessage('flash.wrongPageType', TRUE), |
|
189
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
|
190
|
|
|
); |
|
191
|
|
|
$this->markerArray['CONTENT'] .= Helper::renderFlashMessages(); |
|
192
|
|
|
$this->printContent(); |
|
193
|
|
|
return $this->response; |
|
194
|
|
|
} |
|
195
|
|
|
// Should we do something? |
|
196
|
|
|
if (!empty($this->CMD)) { |
|
197
|
|
|
// Sanitize input... |
|
198
|
|
|
$_method = 'cmd'.ucfirst($this->CMD); |
|
199
|
|
|
// ...and unset to prevent infinite looping. |
|
200
|
|
|
unset ($this->CMD); |
|
201
|
|
|
if (method_exists($this, $_method)) { |
|
202
|
|
|
$this->$_method(); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
// Check for existing structure configuration. |
|
206
|
|
|
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
|
207
|
|
|
'uid', |
|
208
|
|
|
'tx_dlf_structures', |
|
209
|
|
|
'pid='.intval($this->id) |
|
210
|
|
|
.Helper::whereClause('tx_dlf_structures') |
|
211
|
|
|
); |
|
212
|
|
|
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
|
213
|
|
|
// Fine. |
|
214
|
|
|
Helper::addMessage( |
|
215
|
|
|
Helper::getMessage('flash.structureOkayMsg'), |
|
216
|
|
|
Helper::getMessage('flash.structureOkay', TRUE), |
|
217
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
|
218
|
|
|
); |
|
219
|
|
|
} else { |
|
220
|
|
|
// Configuration missing. |
|
221
|
|
|
$_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addStructure'])); |
|
222
|
|
|
Helper::addMessage( |
|
223
|
|
|
sprintf(Helper::getMessage('flash.structureNotOkayMsg'), $_url), |
|
224
|
|
|
Helper::getMessage('flash.structureNotOkay', TRUE), |
|
225
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
|
226
|
|
|
); |
|
227
|
|
|
} |
|
228
|
|
|
// Check for existing metadata configuration. |
|
229
|
|
|
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
|
230
|
|
|
'uid', |
|
231
|
|
|
'tx_dlf_metadata', |
|
232
|
|
|
'pid='.intval($this->id) |
|
233
|
|
|
.Helper::whereClause('tx_dlf_metadata') |
|
234
|
|
|
); |
|
235
|
|
|
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
|
236
|
|
|
// Fine. |
|
237
|
|
|
Helper::addMessage( |
|
238
|
|
|
Helper::getMessage('flash.metadataOkayMsg'), |
|
239
|
|
|
Helper::getMessage('flash.metadataOkay', TRUE), |
|
240
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
|
241
|
|
|
); |
|
242
|
|
|
} else { |
|
243
|
|
|
// Configuration missing. |
|
244
|
|
|
$_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addMetadata'])); |
|
245
|
|
|
Helper::addMessage( |
|
246
|
|
|
sprintf(Helper::getMessage('flash.metadataNotOkayMsg'), $_url), |
|
247
|
|
|
Helper::getMessage('flash.metadataNotOkay', TRUE), |
|
248
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
|
249
|
|
|
); |
|
250
|
|
|
} |
|
251
|
|
|
// Check for existing Solr core. |
|
252
|
|
|
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
|
253
|
|
|
'uid,pid', |
|
254
|
|
|
'tx_dlf_solrcores', |
|
255
|
|
|
'pid IN ('.intval($this->id).',0)' |
|
256
|
|
|
.Helper::whereClause('tx_dlf_solrcores') |
|
257
|
|
|
); |
|
258
|
|
|
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
|
259
|
|
|
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
|
260
|
|
|
if ($resArray['pid']) { |
|
261
|
|
|
// Fine. |
|
262
|
|
|
Helper::addMessage( |
|
263
|
|
|
Helper::getMessage('flash.solrcoreOkayMsg'), |
|
264
|
|
|
Helper::getMessage('flash.solrcoreOkay', TRUE), |
|
265
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
|
266
|
|
|
); |
|
267
|
|
|
} else { |
|
268
|
|
|
// Default core available, but this is deprecated. |
|
269
|
|
|
$_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addSolrcore'])); |
|
270
|
|
|
Helper::addMessage( |
|
271
|
|
|
sprintf(Helper::getMessage('flash.solrcoreDeprecatedMsg'), $_url), |
|
272
|
|
|
Helper::getMessage('flash.solrcoreDeprecatedOkay', TRUE), |
|
273
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE |
|
274
|
|
|
); |
|
275
|
|
|
} |
|
276
|
|
|
} else { |
|
277
|
|
|
// Solr core missing. |
|
278
|
|
|
$_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addSolrcore'])); |
|
279
|
|
|
Helper::addMessage( |
|
280
|
|
|
sprintf(Helper::getMessage('flash.solrcoreMissingMsg'), $_url), |
|
281
|
|
|
Helper::getMessage('flash.solrcoreMissing', TRUE), |
|
282
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING |
|
283
|
|
|
); |
|
284
|
|
|
} |
|
285
|
|
|
$this->markerArray['CONTENT'] .= Helper::renderFlashMessages(); |
|
286
|
|
|
} else { |
|
287
|
|
|
// TODO: Ändern! |
|
288
|
|
|
$this->markerArray['CONTENT'] .= 'You are not allowed to access this page or have not selected a page, yet.'; |
|
289
|
|
|
} |
|
290
|
|
|
$this->printContent(); |
|
291
|
|
|
return $this->response; |
|
292
|
|
|
} |
|
293
|
|
|
} |
|
294
|
|
|
|