Skip to content

Commit

Permalink
Merge branch 'master' into Pres_02-2023_Sicherheitswarnungen_security…
Browse files Browse the repository at this point in the history
…_codeql
  • Loading branch information
sebastian-meyer authored Oct 4, 2023
2 parents ac1d262 + c7c1368 commit 7344f67
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 81 deletions.
12 changes: 6 additions & 6 deletions Classes/Api/Orcid/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Profile
* @access private
* @var \SimpleXmlElement|false The raw ORCID profile
**/
private $raw;
private $raw = false;

/**
* Constructs client instance
Expand All @@ -71,7 +71,7 @@ public function __construct(string $orcid)
public function getData()
{
$this->getRaw('person');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$data = [];
$data['address'] = $this->getAddress();
$data['email'] = $this->getEmail();
Expand All @@ -93,7 +93,7 @@ public function getData()
public function getAddress()
{
$this->getRaw('address');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$this->raw->registerXPathNamespace('address', 'http://www.orcid.org/ns/address');
return (string) $this->raw->xpath('./address:address/address:country')[0];
} else {
Expand All @@ -112,7 +112,7 @@ public function getAddress()
public function getEmail()
{
$this->getRaw('email');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$this->raw->registerXPathNamespace('email', 'http://www.orcid.org/ns/email');
return (string) $this->raw->xpath('./email:email/email:email')[0];
} else {
Expand All @@ -131,7 +131,7 @@ public function getEmail()
public function getFullName()
{
$this->getRaw('personal-details');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$this->raw->registerXPathNamespace('personal-details', 'http://www.orcid.org/ns/personal-details');
$givenNames = $this->raw->xpath('./personal-details:name/personal-details:given-names');
$familyName = $this->raw->xpath('./personal-details:name/personal-details:family-name');
Expand All @@ -155,7 +155,7 @@ private function getRaw(string $endpoint): void
{
$this->client->setEndpoint($endpoint);
$data = $this->client->getData();
if (!isset($this->raw) && $data != false) {
if ($data != false) {
$this->raw = Helper::getXmlFileAsString($data);
}
}
Expand Down
14 changes: 8 additions & 6 deletions Classes/Api/Viaf/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Profile
* @access private
* @var \SimpleXmlElement|false The raw VIAF profile or false if not found
**/
private $raw;
private $raw = false;

/**
* Constructs client instance
Expand All @@ -71,7 +71,7 @@ public function __construct(string $viaf)
public function getData()
{
$this->getRaw();
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$data = [];
$data['address'] = $this->getAddress();
$data['fullName'] = $this->getFullName();
Expand All @@ -92,7 +92,7 @@ public function getData()
public function getAddress()
{
$this->getRaw();
if (!empty($this->raw->asXML())) {
if ($this->raw !== false && !empty($this->raw->asXML())) {
return (string) $this->raw->xpath('./ns1:nationalityOfEntity/ns1:data/ns1:text')[0];
} else {
$this->logger->warning('No address found for given VIAF URL');
Expand All @@ -110,7 +110,7 @@ public function getAddress()
public function getFullName()
{
$this->getRaw();
if (!empty($this->raw->asXML())) {
if ($this->raw !== false && !empty($this->raw->asXML())) {
$rawName = $this->raw->xpath('./ns1:mainHeadings/ns1:data/ns1:text');
$name = (string) $rawName[0];
$name = trim(trim(trim($name), ','), '.');
Expand All @@ -131,9 +131,11 @@ public function getFullName()
private function getRaw(): void
{
$data = $this->client->getData();
if (!isset($this->raw) && $data != false) {
if ($data != false) {
$this->raw = Helper::getXmlFileAsString($data);
$this->raw->registerXPathNamespace('ns1', 'http://viaf.org/viaf/terms#');
if ($this->raw != false && !empty($this->raw->asXML())) {
$this->raw->registerXPathNamespace('ns1', 'http://viaf.org/viaf/terms#');
}
}
}
}
2 changes: 1 addition & 1 deletion Classes/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected function saveToDatabase(Document $document): bool
$document->setMetsLabel($metadata['mets_label'][0] ? : '');
$document->setMetsOrderlabel($metadata['mets_orderlabel'][0] ? : '');

$structure = $this->structureRepository->findOneByIndexName($metadata['type'][0], 'tx_dlf_structures');
$structure = $this->structureRepository->findOneByIndexName($metadata['type'][0]);
$document->setStructure($structure);

if (is_array($metadata['collection'])) {
Expand Down
25 changes: 14 additions & 11 deletions Classes/Common/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,15 @@ public static function &getInstance(string $location, array $settings = [], bool
$xml = null;
$iiif = null;

if ($instance = self::getDocCache($location) && !$forceReload) {
return $instance;
} else {
$instance = null;
if (!$forceReload) {
$instance = self::getDocumentCache($location);
if ($instance !== false) {
return $instance;
}
}

$instance = null;

// Try to load a file from the url
if (GeneralUtility::isValidUrl($location)) {
// Load extension configuration
Expand Down Expand Up @@ -444,8 +447,8 @@ public static function &getInstance(string $location, array $settings = [], bool
$instance = new IiifManifest($location, $pid, $iiif);
}

if ($instance) {
self::setDocCache($location, $instance);
if (!is_null($instance)) {
self::setDocumentCache($location, $instance);
}

return $instance;
Expand Down Expand Up @@ -1243,17 +1246,17 @@ public function __set(string $var, $value): void
}

/**
* Gets Cache Hit for $doc
* Get Cache Hit for document instance
*
* @access private
*
* @static
*
* @param string $location
*
* @return Doc|false
* @return AbstractDocument|false
*/
private static function getDocCache(string $location)
private static function getDocumentCache(string $location)
{
$cacheIdentifier = md5($location);
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('tx_dlf_doc');
Expand All @@ -1263,7 +1266,7 @@ private static function getDocCache(string $location)
}

/**
* Sets Cache for $doc
* Set Cache for document instance
*
* @access private
*
Expand All @@ -1274,7 +1277,7 @@ private static function getDocCache(string $location)
*
* @return void
*/
private static function setDocCache(string $location, AbstractDocument $currentDocument): void
private static function setDocumentCache(string $location, AbstractDocument $currentDocument): void
{
$cacheIdentifier = md5($location);
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('tx_dlf_doc');
Expand Down
4 changes: 1 addition & 3 deletions Classes/Common/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,7 @@ private static function removeAppendsFromAuthor($authors)
*
* @return void
*/
private function __construct(DocumentRepository $documentRepository)
private function __construct()
{
// This is a static class, thus no instances should be created.
$this->documentRepository = $documentRepository;
}
}
2 changes: 1 addition & 1 deletion Classes/Common/Solr/SolrSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ protected function searchSolr($parameters = [], $enableCache = true)
}

// Save value in cache.
if (!empty($resultSet) && $enableCache === true) {
if (!empty($resultSet['documents']) && $enableCache === true) {
$cache->set($cacheIdentifier, $resultSet);
}
} else {
Expand Down
28 changes: 15 additions & 13 deletions Classes/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MetadataController extends AbstractController
* @access private
* @var AbstractDocument
*/
private $doc;
private $currentDocument;

/**
* @access protected
Expand Down Expand Up @@ -110,14 +110,15 @@ public function mainAction()
$this->setDefault('displayIiifLinks', 1);
}

$this->doc = $this->document->getCurrentDocument();
$this->currentDocument = $this->document->getCurrentDocument();

$useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->doc instanceof IiifManifest;
$useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->currentDocument instanceof IiifManifest;
$metadata = $this->getMetadata();
$topLevelId = $this->currentDocument->toplevelId;
// Get titledata?
if (empty($metadata) || ($this->settings['rootline'] == 1 && $metadata[0]['_id'] != $this->doc->toplevelId)) {
$data = $useOriginalIiifManifestMetadata ? $this->doc->getManifestMetadata($this->doc->toplevelId, $this->settings['storagePid']) : $this->doc->getTitledata($this->settings['storagePid']);
$data['_id'] = $this->doc->toplevelId;
if (empty($metadata) || ($this->settings['rootline'] == 1 && $metadata[0]['_id'] != $topLevelId)) {
$data = $useOriginalIiifManifestMetadata ? $this->currentDocument->getManifestMetadata($topLevelId, $this->settings['storagePid']) : $this->currentDocument->getTitledata($this->settings['storagePid']);
$data['_id'] = $topLevelId;
array_unshift($metadata, $data);
}
if (empty($metadata)) {
Expand Down Expand Up @@ -285,7 +286,7 @@ private function buildUrlFromMetadata(array $metadata)

foreach ($metadata as $i => $section) {
if ($this->settings['linkTitle'] && $section['_id'] && isset($section['title']) && !empty($section['title'])) {
$details = $this->doc->getLogicalStructure($section['_id']);
$details = $this->currentDocument->getLogicalStructure($section['_id']);
$buildUrl[$i]['title'] = [
'id' => $this->document->getUid(),
'page' => (!empty($details['points']) ? intval($details['points']) : 1),
Expand Down Expand Up @@ -390,9 +391,10 @@ private function getMetadata()
if ($this->settings['rootline'] < 2) {
// Get current structure's @ID.
$ids = [];
if (!empty($this->doc->physicalStructure[$this->requestData['page']]) && !empty($this->doc->smLinks['p2l'][$this->doc->physicalStructure[$this->requestData['page']]])) {
foreach ($this->doc->smLinks['p2l'][$this->doc->physicalStructure[$this->requestData['page']]] as $logId) {
$count = $this->doc->getStructureDepth($logId);
$page = $this->currentDocument->physicalStructure[$this->requestData['page']];
if (!empty($page) && !empty($this->currentDocument->smLinks['p2l'][$page])) {
foreach ($this->currentDocument->smLinks['p2l'][$page] as $logId) {
$count = $this->currentDocument->getStructureDepth($logId);
$ids[$count][] = $logId;
}
}
Expand Down Expand Up @@ -425,12 +427,12 @@ private function getMetadata()
*/
private function getMetadataForIds($id, $metadata)
{
$useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->doc instanceof IiifManifest;
$useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->currentDocument instanceof IiifManifest;
foreach ($id as $sid) {
if ($useOriginalIiifManifestMetadata) {
$data = $this->doc->getManifestMetadata($sid, $this->settings['storagePid']);
$data = $this->currentDocument->getManifestMetadata($sid, $this->settings['storagePid']);
} else {
$data = $this->doc->getMetadata($sid, $this->settings['storagePid']);
$data = $this->currentDocument->getMetadata($sid, $this->settings['storagePid']);
}
if (!empty($data)) {
$data['_id'] = $sid;
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public function getFeCruserId(): int
}

/**
* @param string $feCruserId
* @param int $feCruserId
*/
public function setFeCruserId(string $feCruserId): void
public function setFeCruserId(int $feCruserId): void
{
$this->feCruserId = $feCruserId;
}
Expand Down
3 changes: 2 additions & 1 deletion Classes/ExpressionLanguage/DocumentTypeFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use TYPO3\CMS\Core\ExpressionLanguage\RequestWrapper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
Expand Down Expand Up @@ -206,7 +207,7 @@ protected function loadDocument(array $requestData, int $pid): void

if ($this->document !== null) {
$doc = AbstractDocument::getInstance($this->document->getLocation(), ['storagePid' => $pid], true);
if ($this->document !== null && $doc !== null) {
if ($doc !== null) {
$this->document->setCurrentDocument($doc);
} else {
$this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"');
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/JsFooterViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function renderStatic(
{
$inlineCode = $arguments['inlineCode'];

/** @var $pageRenderer PageRenderer */
/** @var PageRenderer $pageRenderer */
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsFooterInlineCode('js-dlf-inline-footer', $inlineCode);
}
Expand Down
Loading

0 comments on commit 7344f67

Please sign in to comment.