Skip to content

Commit

Permalink
Merge branch 'kitodo:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-ulrich-weber authored Oct 25, 2023
2 parents fd9fe94 + 8ba4471 commit a2bb3e7
Show file tree
Hide file tree
Showing 64 changed files with 639 additions and 507 deletions.
31 changes: 31 additions & 0 deletions .github/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
parameters:
ignoreErrors:
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::countByPid\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findByIsListed\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findByIsSortable\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByFeUserId\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByIndexName\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByPid\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByRecordId\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByRoot\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneBySessionId\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByType\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByUid\(\)\.#'
- '#Call to an undefined method Psr\\Http\\Message\\RequestFactoryInterface::request\(\)\.#'
- '#Call to an undefined method Solarium\\Core\\Query\\DocumentInterface::setField\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getHeight\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getWidth\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getPossibleTextAnnotationContainers\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getTextAnnotations\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\ManifestInterface::getOriginalJsonArray\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\RangeInterface::getMemberRangesAndRanges\(\)\.#'
- '#Constant LOG_SEVERITY_ERROR not found\.#'
- '#Constant LOG_SEVERITY_NOTICE not found\.#'
- '#Constant LOG_SEVERITY_WARNING not found\.#'
- '#Constant TYPO3_MODE not found\.#'
level: 5
paths:
- ../Classes/
excludePaths:
- ../Classes/Controller/OaiPmhController.php
treatPhpDocTypesAsCertain: false
25 changes: 25 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PHPStan

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
uses: php-actions/composer@v6
with:
command: update
php_version: "7.4"

- name: PHPStan Static Analysis
uses: php-actions/phpstan@v3
with:
configuration: ./.github/phpstan.neon
4 changes: 2 additions & 2 deletions Classes/Api/Orcid/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class Client
/**
* @var string constant for API hostname
**/
const HOSTNAME = 'orcid.org';
const HOSTNAME = 'orcid.org';

/**
* @var string constant for API version
**/
const VERSION = '3.0';
const VERSION = '3.0';

/**
* @access protected
Expand Down
4 changes: 1 addition & 3 deletions Classes/Api/Viaf/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class Client
protected Logger $logger;

/**
* The VIAF API endpoint
*
* @access private
* @var string The VIAF API endpoint
**/
Expand Down Expand Up @@ -110,7 +108,7 @@ public function getData()
*
* @return string
**/
private function getApiEndpoint(): string
private function getApiEndpoint(): string
{
return $this->viafUrl . '/' . $this->endpoint;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected function getSolrCores(int $pageId): array
*
* @access protected
*
* @param Document $doc The document instance
* @param Document $document The document instance
*
* @return bool true on success, false otherwise
*/
Expand Down
8 changes: 7 additions & 1 deletion Classes/Command/HarvestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (
!is_array($input->getOption('set'))
&& !empty($input->getOption('set'))
&& !empty($oai)
) {
$setsAvailable = $oai->listSets();
foreach ($setsAvailable as $setAvailable) {
Expand All @@ -201,9 +202,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$identifiers = [];
// Get OAI record identifiers to process.
try {
$identifiers = $oai->listIdentifiers('mets', $from, $until, $set);
if (!empty($oai)) {
$identifiers = $oai->listIdentifiers('mets', $from, $until, $set);
} else {
$io->error('ERROR: OAI interface does not exist.');
}
} catch (BaseoaipmhException $exception) {
$this->handleOaiError($exception, $io);
}
Expand Down
29 changes: 16 additions & 13 deletions Classes/Common/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
* @property array $rawTextArray this holds the documents' raw text pages with their corresponding structMap//div's ID (METS) or Range / Manifest / Sequence ID (IIIF) as array key
* @property-read bool $ready Is the document instantiated successfully?
* @property-read string $recordId the METS file's / IIIF manifest's record identifier
* @property array $registry this holds the singleton object of the document
* @property-read int $rootId this holds the UID of the root document or zero if not multi-volumed
* @property-read array $smLinks this holds the smLinks between logical and physical structMap
* @property bool $smLinksLoaded flag with information if the smLinks are loaded
Expand Down Expand Up @@ -83,7 +82,7 @@ abstract class AbstractDocument
* @access protected
* @var array Additional information about files (e.g., ADMID), indexed by ID.
*/
protected $fileInfos = [];
protected array $fileInfos = [];

/**
* @access protected
Expand Down Expand Up @@ -210,7 +209,7 @@ abstract class AbstractDocument
* @access protected
* @var string The METS file's / IIIF manifest's record identifier
*/
protected ?string $recordId;
protected string $recordId = '';

/**
* @access protected
Expand Down Expand Up @@ -311,11 +310,11 @@ public static function clearRegistry(): void
*
* @abstract
*
* @param int $pid: ID of the configuration page with the recordId config
* @param int $pid ID of the configuration page with the recordId config
*
* @return void
*/
protected abstract function establishRecordId(int $pid);
protected abstract function establishRecordId(int $pid): void;

/**
* Source document PHP object which is represented by a Document instance
Expand Down Expand Up @@ -394,7 +393,7 @@ public abstract function getFileMimeType(string $id): string;
*
* @return AbstractDocument|null Instance of this class, either MetsDocument or IiifManifest
*/
public static function &getInstance(string $location, array $settings = [], bool $forceReload = false): ?AbstractDocument
public static function &getInstance(string $location, array $settings = [], bool $forceReload = false)
{
// Create new instance depending on format (METS or IIIF) ...
$documentFormat = null;
Expand Down Expand Up @@ -442,9 +441,11 @@ public static function &getInstance(string $location, array $settings = [], bool
// Sanitize input.
$pid = max(intval($settings['storagePid']), 0);
if ($documentFormat == 'METS') {
$instance = new MetsDocument($location, $pid, $xml);
$instance = new MetsDocument($pid, $location, $xml, $settings);
} elseif ($documentFormat == 'IIIF') {
$instance = new IiifManifest($location, $pid, $iiif);
// TODO: Parameter $preloadedDocument of class Kitodo\Dlf\Common\IiifManifest constructor expects SimpleXMLElement|Ubl\Iiif\Presentation\Common\Model\Resources\IiifResourceInterface, Ubl\Iiif\Presentation\Common\Model\AbstractIiifEntity|null given.
// @phpstan-ignore-next-line
$instance = new IiifManifest($pid, $location, $iiif);
}

if (!is_null($instance)) {
Expand Down Expand Up @@ -751,10 +752,11 @@ public function getStructureDepth(string $logId)
* @abstract
*
* @param string $location The location URL of the XML file to parse
* @param array $settings The extension settings
*
* @return void
*/
protected abstract function init(string $location): void;
abstract protected function init(string $location, array $settings): void;

/**
* Reuse any document object that might have been already loaded to determine whether document is METS or IIIF
Expand Down Expand Up @@ -1087,6 +1089,8 @@ protected function _getRootId(): int
{
if (!$this->rootIdLoaded) {
if ($this->parentId) {
// TODO: Parameter $location of static method AbstractDocument::getInstance() expects string, int<min, -1>|int<1, max> given.
// @phpstan-ignore-next-line
$parent = self::getInstance($this->parentId, ['storagePid' => $this->pid]);
$this->rootId = $parent->rootId;
}
Expand Down Expand Up @@ -1169,20 +1173,19 @@ protected function _setCPid(int $value): void
*
* @access protected
*
* @param string $location The location URL of the XML file to parse
* @param int $pid If > 0, then only document with this PID gets loaded
* @param string $location The location URL of the XML file to parse
* @param \SimpleXMLElement|IiifResourceInterface $preloadedDocument Either null or the \SimpleXMLElement
* or IiifResourceInterface that has been loaded to determine the basic document format.
*
* @return void
*/
protected function __construct(string $location, int $pid, $preloadedDocument)
protected function __construct(int $pid, string $location, $preloadedDocument, array $settings = [])
{
$this->pid = $pid;
$this->setPreloadedDocument($preloadedDocument);
$this->init($location);
$this->init($location, $settings);
$this->establishRecordId($pid);
return;
}

/**
Expand Down
40 changes: 19 additions & 21 deletions Classes/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;

Expand Down Expand Up @@ -149,6 +146,8 @@ public static function checkIdentifier(string $id, string $type): bool
if (!preg_match('/\d{8}-\d{1}/i', $id)) {
return false;
} elseif ($checksum == 10) {
//TODO: Binary operation "+" between string and 1 results in an error.
// @phpstan-ignore-next-line
return self::checkIdentifier(($digits + 1) . substr($id, -2, 2), 'SWD');
} elseif (substr($id, -1, 1) != $checksum) {
return false;
Expand Down Expand Up @@ -218,11 +217,10 @@ public static function decrypt(string $encrypted)
*
* @static
*
* @param string $content: content of file to read
* @param mixed $content content of file to read
*
* @return \SimpleXMLElement|false
*/
//TODO: make sure that this is called only with string then update
public static function getXmlFileAsString($content)
{
// Don't make simplexml_load_string throw (when $content is an array
Expand Down Expand Up @@ -605,7 +603,7 @@ public static function getURN(string $base, string $id): string
for ($i = 0, $j = strlen($digits); $i < $j; $i++) {
$checksum += ($i + 1) * intval(substr($digits, $i, 1));
}
$checksum = substr(intval($checksum / intval(substr($digits, -1, 1))), -1, 1);
$checksum = substr((string) floor($checksum / (int) substr($digits, -1, 1)), -1, 1);
return $base . $id . $checksum;
}

Expand Down Expand Up @@ -699,21 +697,21 @@ public static function renderFlashMessages(string $queue = 'kitodo.default.flash
*
* @static
*
* @param string $index_name The internal "index_name" to translate
* @param string $indexName The internal "index_name" to translate
* @param string $table Get the translation from this table
* @param string $pid Get the translation from this page
*
* @return string Localized label for $index_name
* @return string Localized label for $indexName
*/
public static function translate(string $index_name, string $table, string $pid): string
public static function translate(string $indexName, string $table, string $pid): string
{
// Load labels into static variable for future use.
static $labels = [];
// Sanitize input.
$pid = max(intval($pid), 0);
if (!$pid) {
self::log('Invalid PID ' . $pid . ' for translation', LOG_SEVERITY_WARNING);
return $index_name;
return $indexName;
}
/** @var PageRepository $pageRepository */
$pageRepository = GeneralUtility::makeInstance(PageRepository::class);
Expand All @@ -722,12 +720,12 @@ public static function translate(string $index_name, string $table, string $pid)
$languageContentId = $languageAspect->getContentId();

// Check if "index_name" is an UID.
if (MathUtility::canBeInterpretedAsInteger($index_name)) {
$index_name = self::getIndexNameFromUid($index_name, $table, $pid);
if (MathUtility::canBeInterpretedAsInteger($indexName)) {
$indexName = self::getIndexNameFromUid((int) $indexName, $table, $pid);
}
/* $labels already contains the translated content element, but with the index_name of the translated content element itself
* and not with the $index_name of the original that we receive here. So we have to determine the index_name of the
* associated translated content element. E.g. $labels['title0'] != $index_name = title. */
* and not with the $indexName of the original that we receive here. So we have to determine the index_name of the
* associated translated content element. E.g. $labels['title0'] != $indexName = title. */

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
Expand All @@ -741,7 +739,7 @@ public static function translate(string $index_name, string $table, string $pid)
->from($table)
->where(
$queryBuilder->expr()->eq($table . '.pid', $pid),
$queryBuilder->expr()->eq($table . '.index_name', $queryBuilder->expr()->literal($index_name)),
$queryBuilder->expr()->eq($table . '.index_name', $queryBuilder->expr()->literal($indexName)),
self::whereExpression($table, true)
)
->setMaxResults(1)
Expand All @@ -766,13 +764,13 @@ public static function translate(string $index_name, string $table, string $pid)
$row = $result->fetchAssociative();

if ($row) {
// If there is an translated content element, overwrite the received $index_name.
$index_name = $row['index_name'];
// If there is an translated content element, overwrite the received $indexName.
$indexName = $row['index_name'];
}
}

// Check if we already got a translation.
if (empty($labels[$table][$pid][$languageContentId][$index_name])) {
if (empty($labels[$table][$pid][$languageContentId][$indexName])) {
// Check if this table is allowed for translation.
if (in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures'])) {
$additionalWhere = $queryBuilder->expr()->in($table . '.sys_language_uid', [-1, 0]);
Expand Down Expand Up @@ -816,10 +814,10 @@ public static function translate(string $index_name, string $table, string $pid)
}
}

if (!empty($labels[$table][$pid][$languageContentId][$index_name])) {
return $labels[$table][$pid][$languageContentId][$index_name];
if (!empty($labels[$table][$pid][$languageContentId][$indexName])) {
return $labels[$table][$pid][$languageContentId][$indexName];
} else {
return $index_name;
return $indexName;
}
}

Expand Down
Loading

0 comments on commit a2bb3e7

Please sign in to comment.