Skip to content

Commit 2497e64

Browse files
Merge branch 'main' into fix-dlf-search-in-document-loading-clearing-main
2 parents 7a415ee + 61a70ba commit 2497e64

File tree

16 files changed

+312
-35
lines changed

16 files changed

+312
-35
lines changed

.github/phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ parameters:
2323
- '#Constant LOG_SEVERITY_ERROR not found\.#'
2424
- '#Constant LOG_SEVERITY_NOTICE not found\.#'
2525
- '#Constant LOG_SEVERITY_WARNING not found\.#'
26+
- '#^Parameter \#2 \$callback of function array_filter expects \(callable\(mixed\)\: bool\)\|null, ''strlen'' given\.$#'
2627
level: 5
2728
paths:
2829
- ../Classes/

Build/Test/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ services:
4444
"
4545
4646
solr:
47-
image: docker.io/solr:9
47+
image: docker.io/solr:9.7
4848
volumes:
4949
- ${DLF_ROOT}/Configuration/ApacheSolr/configsets:/var/solr/data/configsets
5050
- ./solr/modules/ocrsearch:/opt/solr/modules/ocrsearch

Classes/Common/Helper.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use TYPO3\CMS\Core\Messaging\FlashMessageService;
2727
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
2828
use TYPO3\CMS\Core\Resource\MimeTypeCollection;
29+
use TYPO3\CMS\Core\Resource\MimeTypeDetector;
2930
use TYPO3\CMS\Core\Utility\ArrayUtility;
3031
use TYPO3\CMS\Core\Utility\GeneralUtility;
3132
use TYPO3\CMS\Core\Utility\MathUtility;
@@ -988,4 +989,28 @@ function ($mimeType) use ($categories) {
988989
}
989990
return false;
990991
}
992+
993+
/**
994+
* Get file extensions for a given MIME type
995+
*
996+
* @param string $mimeType
997+
* @return array
998+
*/
999+
public static function getFileExtensionsForMimeType(string $mimeType): array
1000+
{
1001+
$mimeTypeDetector = GeneralUtility::makeInstance(MimeTypeDetector::class);
1002+
return $mimeTypeDetector->getFileExtensionsForMimeType($mimeType);
1003+
}
1004+
1005+
/**
1006+
* Get MIME types for a given file extension
1007+
*
1008+
* @param string $fileExtension
1009+
* @return array
1010+
*/
1011+
public static function getMimeTypesForFileExtension(string $fileExtension): array
1012+
{
1013+
$mimeTypeDetector = GeneralUtility::makeInstance(MimeTypeDetector::class);
1014+
return $mimeTypeDetector->getMimeTypesForFileExtension($fileExtension);
1015+
}
9911016
}

Classes/Controller/ListViewController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,13 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
7979
public function mainAction(): ResponseInterface
8080
{
8181
$this->searchParams = $this->getParametersSafely('searchParameter');
82+
$this->searchParams = is_array($this->searchParams) ? array_filter($this->searchParams, 'strlen') : [];
8283

8384
// extract collection(s) from collection parameter
8485
$collections = [];
85-
if (is_array($this->searchParams) && array_key_exists('collection', $this->searchParams)) {
86+
if (array_key_exists('collection', $this->searchParams)) {
8687
foreach(explode(',', $this->searchParams['collection']) as $collectionEntry) {
87-
if (!empty($collectionEntry)) {
88-
$collections[] = $this->collectionRepository->findByUid((int) $collectionEntry);
89-
}
88+
$collections[] = $this->collectionRepository->findByUid((int) $collectionEntry);
9089
}
9190
}
9291

@@ -104,7 +103,7 @@ public function mainAction(): ResponseInterface
104103

105104
$solrResults = null;
106105
$numResults = 0;
107-
if (is_array($this->searchParams) && !empty($this->searchParams)) {
106+
if (!empty($this->searchParams)) {
108107
$solrResults = $this->documentRepository->findSolrByCollections($collections, $this->settings, $this->searchParams, $listedMetadata, $indexedMetadata);
109108
$numResults = $solrResults->getNumFound();
110109

Classes/Controller/NavigationController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ public function mainAction(): ResponseInterface
8181
$this->viewData['requestData'] = $this->requestData;
8282
}
8383

84+
// get the closest previous sibling or leaf node
85+
$prevDocumentUid = $this->documentRepository->getPreviousDocumentUid($this->document->getUid());
86+
$this->view->assign('documentBack', $prevDocumentUid);
87+
88+
// get the closest next sibling or leaf node
89+
$nextDocumentUid = $this->documentRepository->getNextDocumentUid($this->document->getUid());
90+
$this->view->assign('documentForward', $nextDocumentUid);
91+
8492
// Steps for X pages backward / forward. Double page view uses double steps.
8593
$pageSteps = $this->settings['pageStep'] * ($this->requestData['double'] + 1);
8694

Classes/Controller/OaiPmhController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ protected function verbGetRecord()
390390
*/
391391
protected function verbIdentify()
392392
{
393-
$library = $this->libraryRepository->findByUid($this->settings['library']);
393+
$library = $this->libraryRepository->findByUid($this->settings['library'] ?? 0);
394394

395395
$oaiIdentifyInfo = [];
396396

@@ -642,7 +642,12 @@ protected function fetchDocumentSet(): array
642642

643643
$solrQuery .= ' AND timestamp:[' . $from . ' TO ' . $until . ']';
644644

645-
$solr = Solr::getInstance($this->settings['solrcore']);
645+
$solrcore = $this->settings['solrcore'] ?? false;
646+
if (!$solrcore) {
647+
$this->logger->error('Solr core not configured');
648+
return $documentSet;
649+
}
650+
$solr = Solr::getInstance($solrcore);
646651
if (!$solr->ready) {
647652
$this->logger->error('Apache Solr not available');
648653
return $documentSet;

Classes/Controller/PageViewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ protected function getMeasures(int $page, MetsDocument $specificDoc = null, $doc
320320
$measureCoordsFromCurrentSite = [];
321321
$measureCounterToMeasureId = [];
322322
$measureLinks = [];
323-
$defaultFileId = $doc->physicalStructureInfo[$currentPhysId]['files']['DEFAULT'];
323+
$defaultFileId = $doc->physicalStructureInfo[$currentPhysId]['files']['DEFAULT'] ?? null;
324324
if ($doc instanceof MetsDocument) {
325325
if (isset($defaultFileId)) {
326326
$musicalStruct = $doc->musicalStructureInfo;

Classes/Controller/SearchController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function mainAction(): ResponseInterface
115115

116116
// if search was triggered, get search parameters from POST variables
117117
$this->searchParams = $this->getParametersSafely('searchParameter');
118+
118119
// if search was triggered by the ListView plugin, get the parameters from GET variables
119120
// replace with $this->request->getQueryParams() when dropping support for Typo3 v11, see Deprecation-100596
120121
$listRequestData = GeneralUtility::_GPmerged('tx_dlf_listview');
@@ -130,13 +131,15 @@ public function mainAction(): ResponseInterface
130131
$GLOBALS['TSFE']->fe_user->setKey('ses', 'search', $this->searchParams);
131132
}
132133

134+
$this->searchParams = is_array($this->searchParams) ? array_filter($this->searchParams, 'strlen') : [];
135+
133136
// sanitize date search input
134-
if (!empty($this->searchParams['dateFrom']) || !empty($this->searchParams['dateTo'])) {
135-
if (empty($this->searchParams['dateFrom']) && !empty($this->searchParams['dateTo'])) {
137+
if (array_key_exists('dateFrom', $this->searchParams) || array_key_exists('dateTo', $this->searchParams)) {
138+
if (!array_key_exists('dateFrom', $this->searchParams) && array_key_exists('dateTo', $this->searchParams)) {
136139
$this->searchParams['dateFrom'] = '*';
137140
}
138141

139-
if (empty($this->searchParams['dateTo']) && !empty($this->searchParams['dateFrom'])) {
142+
if (!array_key_exists('dateTo', $this->searchParams) && array_key_exists('dateFrom', $this->searchParams)) {
140143
$this->searchParams['dateTo'] = 'NOW';
141144
}
142145

@@ -168,7 +171,7 @@ public function mainAction(): ResponseInterface
168171

169172
// If no search has been executed, no variables have to be prepared.
170173
// An empty form will be shown.
171-
if (is_array($this->searchParams) && !empty($this->searchParams)) {
174+
if (!empty($this->searchParams)) {
172175
// get all sortable metadata records
173176
$sortableMetadata = $this->metadataRepository->findByIsSortable(true);
174177

@@ -276,7 +279,7 @@ public function makeFacetsMenuArray(array $facets): array
276279
// Set search query.
277280
$searchParams = $this->searchParams;
278281
if (
279-
(!empty($searchParams['fulltext']))
282+
(array_key_exists('fulltext', $searchParams))
280283
|| preg_match('/' . $fields['fulltext'] . ':\((.*)\)/', trim($searchParams['query']), $matches)
281284
) {
282285
// If the query already is a fulltext query e.g using the facets
@@ -298,7 +301,7 @@ public function makeFacetsMenuArray(array $facets): array
298301
}
299302

300303
// add filter query for date search
301-
if (!empty($this->searchParams['dateFrom']) && !empty($this->searchParams['dateTo'])) {
304+
if (array_key_exists('dateFrom', $this->searchParams) && array_key_exists('dateTo', $this->searchParams)) {
302305
// combine dateFrom and dateTo into filterquery as range search
303306
$search['params']['filterquery'][]['query'] = '{!join from=' . $fields['uid'] . ' to=' . $fields['uid'] . '}' . $fields['date'] . ':[' . $this->searchParams['dateFrom'] . ' TO ' . $this->searchParams['dateTo'] . ']';
304307
}
@@ -326,7 +329,7 @@ public function makeFacetsMenuArray(array $facets): array
326329
}
327330
}
328331

329-
if (isset($this->searchParams['fq']) && is_array($this->searchParams['fq'])) {
332+
if (array_key_exists('fq', $this->searchParams) && is_array($this->searchParams['fq'])) {
330333
foreach ($this->searchParams['fq'] as $fq) {
331334
$search['params']['filterquery'][]['query'] = $fq;
332335
}

Classes/Controller/ToolboxController.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,13 @@ private function renderToolByName(string $tool): void
139139
*
140140
* @return array Array of image information's.
141141
*/
142-
public function getImage(int $page): array
142+
private function getImage(int $page): array
143143
{
144144
// Get @USE value of METS fileGroup.
145145
$image = $this->getFile($page, GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload']));
146-
switch ($image['mimetype']) {
147-
case 'image/jpeg':
148-
$image['mimetypeLabel'] = ' (JPG)';
149-
break;
150-
case 'image/tiff':
151-
$image['mimetypeLabel'] = ' (TIFF)';
152-
break;
153-
default:
154-
$image['mimetypeLabel'] = '';
146+
if (isset($image['mimetype'])) {
147+
$fileExtension = Helper::getFileExtensionsForMimeType($image['mimetype']);
148+
$image['mimetypeLabel'] = !empty($fileExtension) ? ' (' . strtoupper($fileExtension[0]) . ')' : '';
155149
}
156150
return $image;
157151
}
@@ -321,14 +315,18 @@ private function renderImageDownloadTool(): void
321315
private function getFile(int $page, array $fileGrps): array
322316
{
323317
$file = [];
318+
$physicalStructureInfo = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$page]] ?? null;
324319
while ($fileGrp = @array_pop($fileGrps)) {
325-
$physicalStructureInfo = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$page]];
326-
$fileId = $physicalStructureInfo['files'][$fileGrp];
327-
if (!empty($fileId)) {
328-
$file['url'] = $this->currentDocument->getDownloadLocation($fileId);
329-
$file['mimetype'] = $this->currentDocument->getFileMimeType($fileId);
320+
if (isset($physicalStructureInfo['files'][$fileGrp])) {
321+
$fileId = $physicalStructureInfo['files'][$fileGrp];
322+
if (!empty($fileId)) {
323+
$file['url'] = $this->currentDocument->getDownloadLocation($fileId);
324+
$file['mimetype'] = $this->currentDocument->getFileMimeType($fileId);
325+
} else {
326+
$this->logger->warning('File not found in fileGrp "' . $fileGrp . '"');
327+
}
330328
} else {
331-
$this->logger->warning('File not found in fileGrp "' . $fileGrp . '"');
329+
$this->logger->warning('fileGrp "' . $fileGrp . '" not found in Document mets:fileSec');
332330
}
333331
}
334332
return $file;

0 commit comments

Comments
 (0)