diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index b30395c39..1fc094763 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -269,6 +269,55 @@ protected function sanitizeRequestData(): void $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'] ?? 0, 0, 1); } + /** + * Sanitize settings from FlexForm. + * + * @access protected + * + * @return void + */ + protected function sanitizeSettings(): void + { + $this->setDefaultIntSetting('storagePid', 0); + + if ($this instanceof MetadataController) { + $this->setDefaultIntSetting('rootline', 0); + $this->setDefaultIntSetting('originalIiifMetadata', 0); + $this->setDefaultIntSetting('displayIiifDescription', 1); + $this->setDefaultIntSetting('displayIiifRights', 1); + $this->setDefaultIntSetting('displayIiifLinks', 1); + } + + if ($this instanceof OaiPmhController) { + $this->setDefaultIntSetting('limit', 5); + $this->setDefaultIntSetting('solr_limit', 50000); + } + + if ($this instanceof PageViewController) { + $this->setDefaultIntSetting('useInternalProxy', 0); + } + } + + /** + * Sets default value for setting if not yet set. + * + * @access protected + * + * @param string $setting name of setting + * @param int $value for being set if empty + * + * @return void + */ + protected function setDefaultIntSetting(string $setting, int $value): void + { + if (empty($this->settings[$setting])) { + $this->settings[$setting] = $value; + $this->logger->warning('Setting "' . $setting . '" not set, using default value "' . $value . '". Probably FlexForm for controller "' . get_class($this) . '" is not read.'); + } else { + $this->settings[$setting] = (int) $this->settings[$setting]; + } + } + /** * Sets page value. * @@ -492,7 +541,7 @@ private function getDocumentByUrl(string $documentId) // Make sure configuration PID is set when applicable if ($doc->cPid == 0) { - $doc->cPid = max((int) $this->settings['storagePid'], 0); + $doc->cPid = max($this->settings['storagePid'], 0); } $this->document->setLocation($documentId); diff --git a/Classes/Controller/MetadataController.php b/Classes/Controller/MetadataController.php index 499a99daf..142385b15 100644 --- a/Classes/Controller/MetadataController.php +++ b/Classes/Controller/MetadataController.php @@ -107,16 +107,10 @@ public function mainAction(): void if ($this->isDocMissing()) { // Quit without doing anything if required variables are not set. return; - } else { - // Set default values if not set. - $this->setDefault('rootline', 0); - $this->setDefault('originalIiifMetadata', 0); - $this->setDefault('displayIiifDescription', 1); - $this->setDefault('displayIiifRights', 1); - $this->setDefault('displayIiifLinks', 1); - $this->setPage(); } + $this->setPage(); + $this->currentDocument = $this->document->getCurrentDocument(); $this->useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->currentDocument instanceof IiifManifest; @@ -518,21 +512,4 @@ private function getMetadataForIds(array $id, array $metadata): array } return $metadata; } - - /** - * Sets default value for setting if not yet set. - * - * @access private - * - * @param string $setting name of setting - * @param int $value 0 or 1 - * - * @return void - */ - private function setDefault(string $setting, int $value): void - { - if (!isset($this->settings[$setting])) { - $this->settings[$setting] = $value; - } - } } diff --git a/Classes/Controller/OaiPmhController.php b/Classes/Controller/OaiPmhController.php index 81c7430ef..e55b8ede5 100644 --- a/Classes/Controller/OaiPmhController.php +++ b/Classes/Controller/OaiPmhController.php @@ -645,8 +645,8 @@ protected function fetchDocumentSet(): array $this->logger->error('Apache Solr not available'); return $documentSet; } - if ((int) $this->settings['solr_limit'] > 0) { - $solr->limit = (int) $this->settings['solr_limit']; + if ($this->settings['solr_limit'] > 0) { + $solr->limit = $this->settings['solr_limit']; } // We only care about the UID in the results and want them sorted $parameters = [ @@ -785,7 +785,7 @@ private function checkGranularity(): void */ protected function generateOutputForDocumentList(array $documentListSet) { - $documentsToProcess = array_splice($documentListSet['elements'], 0, (int) $this->settings['limit']); + $documentsToProcess = array_splice($documentListSet['elements'], 0, $this->settings['limit']); if (empty($documentsToProcess)) { $this->error = 'noRecordsMatch'; return [];