Skip to content

Commit

Permalink
Merge branch 'slub_master' into midi-player-navigation
Browse files Browse the repository at this point in the history
# Conflicts:
#	Classes/Common/MetsDocument.php
  • Loading branch information
chrizzor committed Jul 8, 2024
2 parents 4645f91 + a47a53e commit 5921bf0
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 424 deletions.
10 changes: 5 additions & 5 deletions Classes/Command/HarvestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
// Abort if solrCoreUid is empty or not in the array of allowed solr cores.
if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) {
$output_solrCores = [];
foreach ($allSolrCores as $index_name => $uid) {
$output_solrCores[] = $uid . ' : ' . $index_name;
$outputSolrCores = [];
foreach ($allSolrCores as $indexName => $uid) {
$outputSolrCores[] = $uid . ' : ' . $indexName;
}
if (empty($output_solrCores)) {
if (empty($outputSolrCores)) {
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $this->storagePid . ".\n");
return BaseCommand::FAILURE;
} else {
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $output_solrCores) . "\n");
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $outputSolrCores) . "\n");
return BaseCommand::FAILURE;
}
}
Expand Down
10 changes: 5 additions & 5 deletions Classes/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Abort if solrCoreUid is empty or not in the array of allowed solr cores.
if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) {
$output_solrCores = [];
foreach ($allSolrCores as $index_name => $uid) {
$output_solrCores[] = $uid . ' : ' . $index_name;
$outputSolrCores = [];
foreach ($allSolrCores as $indexName => $uid) {
$outputSolrCores[] = $uid . ' : ' . $indexName;
}
if (empty($output_solrCores)) {
if (empty($outputSolrCores)) {
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $this->storagePid . ".\n");
return BaseCommand::FAILURE;
} else {
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $output_solrCores) . "\n");
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $outputSolrCores) . "\n");
return BaseCommand::FAILURE;
}
}
Expand Down
10 changes: 5 additions & 5 deletions Classes/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Abort if solrCoreUid is empty or not in the array of allowed solr cores.
if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) {
$output_solrCores = [];
foreach ($allSolrCores as $index_name => $uid) {
$output_solrCores[] = $uid . ' : ' . $index_name;
$outputSolrCores = [];
foreach ($allSolrCores as $indexName => $uid) {
$outputSolrCores[] = $uid . ' : ' . $indexName;
}
if (empty($output_solrCores)) {
if (empty($outputSolrCores)) {
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $this->storagePid . ".\n");
return BaseCommand::FAILURE;
} else {
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $output_solrCores) . "\n");
$io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $outputSolrCores) . "\n");
return BaseCommand::FAILURE;
}
}
Expand Down
185 changes: 52 additions & 133 deletions Classes/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Kitodo\Dlf\Common;

use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\Uri;
Expand Down Expand Up @@ -207,7 +208,7 @@ public static function decrypt(string $encrypted)
self::log('OpenSSL library doesn\'t support cipher and/or hash algorithm', LOG_SEVERITY_ERROR);
return false;
}
if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
if (empty(self::getEncryptionKey())) {
self::log('No encryption key set in TYPO3 configuration', LOG_SEVERITY_ERROR);
return false;
}
Expand All @@ -222,7 +223,7 @@ public static function decrypt(string $encrypted)
$binary = base64_decode($encrypted);
$iv = substr($binary, 0, openssl_cipher_iv_length(self::$cipherAlgorithm));
$data = substr($binary, openssl_cipher_iv_length(self::$cipherAlgorithm));
$key = openssl_digest($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], self::$hashAlgorithm, true);
$key = openssl_digest(self::getEncryptionKey(), self::$hashAlgorithm, true);
// Decrypt data.
return openssl_decrypt($data, self::$cipherAlgorithm, $key, OPENSSL_RAW_DATA, $iv);
}
Expand Down Expand Up @@ -342,13 +343,13 @@ public static function encrypt(string $string)
self::log('OpenSSL library doesn\'t support cipher and/or hash algorithm', LOG_SEVERITY_ERROR);
return false;
}
if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
if (empty(self::getEncryptionKey())) {
self::log('No encryption key set in TYPO3 configuration', LOG_SEVERITY_ERROR);
return false;
}
// Generate random initialization vector.
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::$cipherAlgorithm));
$key = openssl_digest($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], self::$hashAlgorithm, true);
$key = openssl_digest(self::getEncryptionKey(), self::$hashAlgorithm, true);
// Encrypt data.
$encrypted = openssl_encrypt($string, self::$cipherAlgorithm, $key, OPENSSL_RAW_DATA, $iv);
// Merge initialization vector and encrypted data.
Expand All @@ -358,23 +359,6 @@ public static function encrypt(string $string)
return $encrypted;
}

/**
* Get the unqualified name of a class
*
* @access public
*
* @static
*
* @param string $qualifiedClassName The qualified class name from get_class()
*
* @return string The unqualified class name
*/
public static function getUnqualifiedClassName(string $qualifiedClassName): string
{
$nameParts = explode('\\', $qualifiedClassName);
return end($nameParts);
}

/**
* Clean up a string to use in an URL.
*
Expand Down Expand Up @@ -412,8 +396,8 @@ public static function getCleanString(string $string): string
public static function getHookObjects(string $scriptRelPath): array
{
$hookObjects = [];
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey . '/' . $scriptRelPath]['hookClass'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey . '/' . $scriptRelPath]['hookClass'] as $classRef) {
if (is_array(self::getOptions()[self::$extKey . '/' . $scriptRelPath]['hookClass'])) {
foreach (self::getOptions()[self::$extKey . '/' . $scriptRelPath]['hookClass'] as $classRef) {
$hookObjects[] = GeneralUtility::makeInstance($classRef);
}
}
Expand Down Expand Up @@ -556,94 +540,6 @@ public static function getDocumentStructures(int $pid = -1): array
return array_column($allStructures, 'indexName', 'uid');
}

/**
* Get the URN of an object
* @see http://www.persistent-identifier.de/?link=316
*
* @access public
*
* @static
*
* @param string $base The namespace and base URN
* @param string $id The object's identifier
*
* @return string Uniform Resource Name as string
*/
public static function getURN(string $base, string $id): string
{
$concordance = [
'0' => 1,
'1' => 2,
'2' => 3,
'3' => 4,
'4' => 5,
'5' => 6,
'6' => 7,
'7' => 8,
'8' => 9,
'9' => 41,
'a' => 18,
'b' => 14,
'c' => 19,
'd' => 15,
'e' => 16,
'f' => 21,
'g' => 22,
'h' => 23,
'i' => 24,
'j' => 25,
'k' => 42,
'l' => 26,
'm' => 27,
'n' => 13,
'o' => 28,
'p' => 29,
'q' => 31,
'r' => 12,
's' => 32,
't' => 33,
'u' => 11,
'v' => 34,
'w' => 35,
'x' => 36,
'y' => 37,
'z' => 38,
'-' => 39,
':' => 17,
];
$urn = strtolower($base . $id);
if (preg_match('/[^a-z\d:-]/', $urn)) {
self::log('Invalid chars in given parameters', LOG_SEVERITY_WARNING);
return '';
}
$digits = '';
for ($i = 0, $j = strlen($urn); $i < $j; $i++) {
$digits .= $concordance[substr($urn, $i, 1)];
}
$checksum = 0;
for ($i = 0, $j = strlen($digits); $i < $j; $i++) {
$checksum += ($i + 1) * (int) substr($digits, $i, 1);
}
$checksum = substr((string) floor($checksum / (int) substr($digits, -1, 1)), -1, 1);
return $base . $id . $checksum;
}

/**
* Check if given ID is a valid Pica Production Number (PPN)
*
* @access public
*
* @static
*
* @param string $id The identifier to check
*
* @return bool Is $id a valid PPN?
*/
public static function isPPN(string $id): bool
{
return self::checkIdentifier($id, 'PPN');
}

/**
* Determine whether or not $url is a valid URL using HTTP or HTTPS scheme.
*
Expand All @@ -670,28 +566,6 @@ public static function isValidHttpUrl(string $url): bool
}
}

/**
* Merges two arrays recursively and actually returns the modified array.
* @see ArrayUtility::mergeRecursiveWithOverrule()
*
* @access public
*
* @static
*
* @param array $original Original array
* @param array $overrule Overrule array, overruling the original array
* @param bool $addKeys If set to false, keys that are not found in $original will not be set
* @param bool $includeEmptyValues If set, values from $overrule will overrule if they are empty
* @param bool $enableUnsetFeature If set, special value "__UNSET" can be used in the overrule array to unset keys in the original array
*
* @return array Merged array
*/
public static function mergeRecursiveWithOverrule(array $original, array $overrule, bool $addKeys = true, bool $includeEmptyValues = true, bool $enableUnsetFeature = true): array
{
ArrayUtility::mergeRecursiveWithOverrule($original, $overrule, $addKeys, $includeEmptyValues, $enableUnsetFeature);
return $original;
}

/**
* Process a data and/or command map with TYPO3 core engine as admin.
*
Expand Down Expand Up @@ -1018,4 +892,49 @@ public static function isValidXmlId($id): bool
{
return preg_match('/^[_a-z][_a-z0-9-.]*$/i', $id) === 1;
}

/**
* Get options from local configuration.
*
* @access private
*
* @static
*
* @return array
*/
private static function getOptions(): array
{
return self::getLocalConfigurationByPath('SC_OPTIONS');
}

/**
* Get encryption key from local configuration.
*
* @access private
*
* @static
*
* @return string|null
*/
private static function getEncryptionKey(): ?string
{
return self::getLocalConfigurationByPath('SYS/encryptionKey');
}

/**
* Get local configuration for given path.
*
* @access private
*
* @static
*
* @param string $path
*
* @return mixed
*/
private static function getLocalConfigurationByPath(string $path)
{
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
return $configurationManager->getLocalConfigurationValueByPath($path);
}
}
Loading

0 comments on commit 5921bf0

Please sign in to comment.