Skip to content

Commit

Permalink
Use nested configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Jan 30, 2024
1 parent 5f66665 commit 2822a16
Show file tree
Hide file tree
Showing 21 changed files with 314 additions and 305 deletions.
2 changes: 1 addition & 1 deletion Classes/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private function addCollections(Document &$document, array $collections, Persist
$documentCollection = GeneralUtility::makeInstance(Collection::class);
$documentCollection->setIndexName($collection);
$documentCollection->setLabel($collection);
$documentCollection->setOaiName((!empty($this->extConf['publishNewCollections']) ? Helper::getCleanString($collection) : ''));
$documentCollection->setOaiName((!empty($this->extConf['general']['publishNewCollections']) ? Helper::getCleanString($collection) : ''));
$documentCollection->setIndexSearch('');
$documentCollection->setDescription('');
// add to CollectionRepository
Expand Down
4 changes: 2 additions & 2 deletions Classes/Common/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ public static function &getInstance(string $location, array $settings = [], bool
$contentAsJsonArray = json_decode($content, true);
if ($contentAsJsonArray !== null) {
IiifHelper::setUrlReader(IiifUrlReader::getInstance());
IiifHelper::setMaxThumbnailHeight($extConf['iiifThumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($extConf['iiifThumbnailWidth']);
IiifHelper::setMaxThumbnailHeight($extConf['iiif']['thumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($extConf['iiif']['thumbnailWidth']);
$iiif = IiifHelper::loadIiifResource($contentAsJsonArray);
if ($iiif instanceof IiifResourceInterface) {
$documentFormat = 'IIIF';
Expand Down
4 changes: 2 additions & 2 deletions Classes/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,14 +903,14 @@ public static function getUrl(string $url)
}

// Get extension configuration.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf');
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf', 'general');

/** @var RequestFactory $requestFactory */
$requestFactory = GeneralUtility::makeInstance(RequestFactory::class);
$configuration = [
'timeout' => 30,
'headers' => [
'User-Agent' => $extConf['useragent'] ?? 'Kitodo.Presentation Proxy',
'User-Agent' => $extConf['userAgent'] ?? 'Kitodo.Presentation Proxy',
],
];
try {
Expand Down
22 changes: 11 additions & 11 deletions Classes/Common/IiifManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected function getUseGroups(string $use)
{
if (!$this->useGrpsLoaded) {
// Get configured USE attributes.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files');
if (!empty($extConf['fileGrpImages'])) {
$this->useGrps['fileGrpImages'] = GeneralUtility::trimExplode(',', $extConf['fileGrpImages']);
}
Expand Down Expand Up @@ -265,7 +265,7 @@ protected function magicGetPhysicalStructure(): array
if ($this->iiif == null || !($this->iiif instanceof ManifestInterface)) {
return [];
}
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'iiif');
$iiifId = $this->iiif->getId();
$this->physicalStructureInfo[$iiifId]['id'] = $iiifId;
$this->physicalStructureInfo[$iiifId]['dmdId'] = $iiifId;
Expand Down Expand Up @@ -787,15 +787,15 @@ public function getFullText(string $id): string
$this->magicGetPhysicalStructure();
// ... and extension configuration.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$fileGrpsFulltext = GeneralUtility::trimExplode(',', $extConf['fileGrpFulltext']);
$fileGrpsFulltext = GeneralUtility::trimExplode(',', $extConf['files']['fileGrpFulltext']);
if (!empty($this->physicalStructureInfo[$id])) {
while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
if (!empty($this->physicalStructureInfo[$id]['files'][$fileGrpFulltext])) {
$rawText = parent::getFullTextFromXml($id);
break;
}
}
if ($extConf['indexAnnotations'] == 1) {
if ($extConf['iiif']['indexAnnotations'] == 1) {
$iiifResource = $this->iiif->getContainedResourceById($id);
// Get annotation containers
$annotationContainerIds = $this->physicalStructureInfo[$id]['annotationContainers'];
Expand Down Expand Up @@ -840,10 +840,10 @@ protected function loadLocation(string $location): bool
{
$fileResource = GeneralUtility::getUrl($location);
if ($fileResource !== false) {
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'iiif');
IiifHelper::setUrlReader(IiifUrlReader::getInstance());
IiifHelper::setMaxThumbnailHeight($conf['iiifThumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($conf['iiifThumbnailWidth']);
IiifHelper::setMaxThumbnailHeight($conf['thumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($conf['thumbnailWidth']);
$resource = IiifHelper::loadIiifResource($fileResource);
if ($resource instanceof ManifestInterface) {
$this->iiif = $resource;
Expand Down Expand Up @@ -898,7 +898,7 @@ protected function ensureHasFulltextIsSet(): void
$this->hasFulltext = true;
return;
}
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'iiif');
if ($extConf['indexAnnotations'] == 1 && !empty($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING))) {
foreach ($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING) as $annotationContainer) {
$textAnnotations = $annotationContainer->getTextAnnotations(Motivation::PAINTING);
Expand Down Expand Up @@ -981,10 +981,10 @@ private function getAnnotationTexts($annotationContainerIds, $iiifId): array
*/
public function __wakeup(): void
{
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'iiif');
IiifHelper::setUrlReader(IiifUrlReader::getInstance());
IiifHelper::setMaxThumbnailHeight($conf['iiifThumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($conf['iiifThumbnailWidth']);
IiifHelper::setMaxThumbnailHeight($conf['thumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($conf['thumbnailWidth']);
$resource = IiifHelper::loadIiifResource($this->asJson);
if ($resource instanceof ManifestInterface) {
$this->asJson = '';
Expand Down
2 changes: 1 addition & 1 deletion Classes/Common/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ protected static function processPhysical(Document $document, int $page, array $
$doc->cPid = $document->getPid();
if ($doc->hasFulltext && $fullText = $doc->getFullText($physicalUnit['id'])) {
// Read extension configuration.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files');
// Create new Solr document.
$updateQuery = self::$solr->service->createUpdate();
$solrDoc = self::getSolrDocument($updateQuery, $document, $physicalUnit, $fullText);
Expand Down
14 changes: 7 additions & 7 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ public function getDownloadLocation(string $id): string
$file = $this->getFileInfo($id);
if ($file['mimeType'] === 'application/vnd.kitodo.iiif') {
$file['location'] = (strrpos($file['location'], 'info.json') === strlen($file['location']) - 9) ? $file['location'] : (strrpos($file['location'], '/') === strlen($file['location']) ? $file['location'] . 'info.json' : $file['location'] . '/info.json');
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'iiif');
IiifHelper::setUrlReader(IiifUrlReader::getInstance());
IiifHelper::setMaxThumbnailHeight($conf['iiifThumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($conf['iiifThumbnailWidth']);
IiifHelper::setMaxThumbnailHeight($conf['thumbnailHeight']);
IiifHelper::setMaxThumbnailWidth($conf['thumbnailWidth']);
$service = IiifHelper::loadIiifResource($file['location']);
if ($service instanceof AbstractImageService) {
return $service->getImageUrl();
Expand Down Expand Up @@ -407,7 +407,7 @@ protected function getLogicalStructureInfo(\SimpleXMLElement $structure, bool $r
private function getThumbnail(string $id = '')
{
// Load plugin configuration.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files');
$fileGrpsThumb = GeneralUtility::trimExplode(',', $extConf['fileGrpThumbs']);

$thumbnail = null;
Expand Down Expand Up @@ -591,7 +591,7 @@ private function extractMetadataIfTypeSupported(string $dmdId, string $mdSection
if (class_exists($class)) {
$obj = GeneralUtility::makeInstance($class);
if ($obj instanceof MetadataInterface) {
$obj->extractMetadata($this->mdSec[$dmdId]['xml'], $metadata, GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey)['useExternalApisForMetadata']);
$obj->extractMetadata($this->mdSec[$dmdId]['xml'], $metadata, GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'general')['useExternalApisForMetadata']);
return true;
}
} else {
Expand Down Expand Up @@ -959,7 +959,7 @@ protected function magicGetFileGrps(): array
{
if (!$this->fileGrpsLoaded) {
// Get configured USE attributes.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files');
$useGrps = GeneralUtility::trimExplode(',', $extConf['fileGrpImages']);
if (!empty($extConf['fileGrpThumbs'])) {
$useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf['fileGrpThumbs']));
Expand Down Expand Up @@ -1127,7 +1127,7 @@ protected function magicGetThumbnail(bool $forceReload = false): string
return $this->thumbnail;
}
// Load extension configuration.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files');
if (empty($extConf['fileGrpThumbs'])) {
$this->logger->warning('No fileGrp for thumbnails specified');
$this->thumbnailLoaded = true;
Expand Down
72 changes: 36 additions & 36 deletions Classes/Common/Solr/Solr.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,34 +242,34 @@ public static function escapeQueryKeepField(string $query, int $pid): string
public static function getFields(): array
{
if (empty(self::$fields)) {
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);

self::$fields['id'] = $conf['solrFieldId'];
self::$fields['uid'] = $conf['solrFieldUid'];
self::$fields['pid'] = $conf['solrFieldPid'];
self::$fields['page'] = $conf['solrFieldPage'];
self::$fields['partof'] = $conf['solrFieldPartof'];
self::$fields['root'] = $conf['solrFieldRoot'];
self::$fields['sid'] = $conf['solrFieldSid'];
self::$fields['toplevel'] = $conf['solrFieldToplevel'];
self::$fields['type'] = $conf['solrFieldType'];
self::$fields['title'] = $conf['solrFieldTitle'];
self::$fields['volume'] = $conf['solrFieldVolume'];
self::$fields['date'] = $conf['solrFieldDate'];
self::$fields['thumbnail'] = $conf['solrFieldThumbnail'];
self::$fields['default'] = $conf['solrFieldDefault'];
self::$fields['timestamp'] = $conf['solrFieldTimestamp'];
self::$fields['autocomplete'] = $conf['solrFieldAutocomplete'];
self::$fields['fulltext'] = $conf['solrFieldFulltext'];
self::$fields['record_id'] = $conf['solrFieldRecordId'];
self::$fields['purl'] = $conf['solrFieldPurl'];
self::$fields['urn'] = $conf['solrFieldUrn'];
self::$fields['location'] = $conf['solrFieldLocation'];
self::$fields['collection'] = $conf['solrFieldCollection'];
self::$fields['license'] = $conf['solrFieldLicense'];
self::$fields['terms'] = $conf['solrFieldTerms'];
self::$fields['restrictions'] = $conf['solrFieldRestrictions'];
self::$fields['geom'] = $conf['solrFieldGeom'];
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'solr');
$solrFields = $conf['fields'];
self::$fields['id'] = $solrFields['id'];
self::$fields['uid'] = $solrFields['uid'];
self::$fields['pid'] = $solrFields['pid'];
self::$fields['page'] = $solrFields['page'];
self::$fields['partof'] = $solrFields['partof'];
self::$fields['root'] = $solrFields['root'];
self::$fields['sid'] = $solrFields['sid'];
self::$fields['toplevel'] = $solrFields['toplevel'];
self::$fields['type'] = $solrFields['type'];
self::$fields['title'] = $solrFields['title'];
self::$fields['volume'] = $solrFields['volume'];
self::$fields['date'] = $solrFields['date'];
self::$fields['thumbnail'] = $solrFields['thumbnail'];
self::$fields['default'] = $solrFields['default'];
self::$fields['timestamp'] = $solrFields['timestamp'];
self::$fields['autocomplete'] = $solrFields['autocomplete'];
self::$fields['fulltext'] = $solrFields['fulltext'];
self::$fields['record_id'] = $solrFields['recordId'];
self::$fields['purl'] = $solrFields['purl'];
self::$fields['urn'] = $solrFields['urn'];
self::$fields['location'] = $solrFields['location'];
self::$fields['collection'] = $solrFields['collection'];
self::$fields['license'] = $solrFields['license'];
self::$fields['terms'] = $solrFields['terms'];
self::$fields['restrictions'] = $solrFields['restrictions'];
self::$fields['geom'] = $solrFields['geom'];
}

return self::$fields;
Expand Down Expand Up @@ -349,25 +349,25 @@ protected function loadSolrConnectionInfo(): void
if (empty($this->config)) {
$config = [];
// Extract extension configuration.
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
$conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'solr');
// Derive Solr scheme
$config['scheme'] = empty($conf['solrHttps']) ? 'http' : 'https';
$config['scheme'] = empty($conf['https']) ? 'http' : 'https';
// Derive Solr host name.
$config['host'] = ($conf['solrHost'] ? $conf['solrHost'] : '127.0.0.1');
$config['host'] = ($conf['host'] ? $conf['host'] : '127.0.0.1');
// Set username and password.
$config['username'] = $conf['solrUser'];
$config['password'] = $conf['solrPass'];
$config['username'] = $conf['user'];
$config['password'] = $conf['pass'];
// Set port if not set.
$config['port'] = MathUtility::forceIntegerInRange($conf['solrPort'], 1, 65535, 8983);
$config['port'] = MathUtility::forceIntegerInRange($conf['port'], 1, 65535, 8983);
// Trim path of slashes and (re-)add trailing slash if path not empty.
$config['path'] = trim($conf['solrPath'], '/');
$config['path'] = trim($conf['path'], '/');
if (!empty($config['path'])) {
$config['path'] .= '/';
}

// Set connection timeout lower than PHP's max_execution_time.
$maxExecutionTime = (int) ini_get('max_execution_time') ? : 30;
$config['timeout'] = MathUtility::forceIntegerInRange($conf['solrTimeout'], 1, $maxExecutionTime, 10);
$config['timeout'] = MathUtility::forceIntegerInRange($conf['timeout'], 1, $maxExecutionTime, 10);
$this->config = $config;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function configureProxyUrl(string &$url): void
{
$this->uriBuilder->reset()
->setTargetPageUid($GLOBALS['TSFE']->id)
->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']))
->setCreateAbsoluteUri(!empty($this->settings['general']['forceAbsoluteUrl']))
->setArguments(
[
'eID' => 'tx_dlf_pageview_proxy',
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/AudioPlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function mainAction(): void
$this->setDefaultPage();

// Check if there are any audio files available.
$fileGrpsAudio = GeneralUtility::trimExplode(',', $this->extConf['fileGrpAudio']);
$fileGrpsAudio = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpAudio']);
while ($fileGrpAudio = array_shift($fileGrpsAudio)) {
$physicalStructureInfo = $this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$this->requestData['page']]];
$fileId = $physicalStructureInfo['files'][$fileGrpAudio];
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/PageGridController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function mainAction(): void
$this->loadDocument();
if (
$this->isDocMissingOrEmpty()
|| empty($this->extConf['fileGrpThumbs'])
|| empty($this->extConf['files']['fileGrpThumbs'])
) {
// Quit without doing anything if required variables are not set.
return;
Expand All @@ -48,7 +48,7 @@ public function mainAction(): void
$numPages = $this->document->getCurrentDocument()->numPages;
// Iterate through visible page set and display thumbnails.
for ($i = 1; $i <= $numPages; $i++) {
$foundEntry = $this->getEntry($i, $this->extConf['fileGrpThumbs']);
$foundEntry = $this->getEntry($i, $this->extConf['files']['fileGrpThumbs']);
$foundEntry['state'] = ($i == $this->requestData['page']) ? 'cur' : 'no';
$entryArray[] = $foundEntry;
}
Expand Down
Loading

0 comments on commit 2822a16

Please sign in to comment.