Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#438)
by Sebastian
03:50
created

UserFunc::loadDocument()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 31
rs 9.2728
cc 5
nc 5
nop 1
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Hooks;
14
15
use Kitodo\Dlf\Common\Document;
16
use Kitodo\Dlf\Common\Helper;
17
use Kitodo\Dlf\Common\IiifManifest;
18
use TYPO3\CMS\Core\Database\ConnectionPool;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21
/**
22
 * Helper for custom "userFunc"
23
 *
24
 * @author Alexander Bigga <[email protected]>
25
 * @author Sebastian Meyer <[email protected]>
26
 * @package TYPO3
27
 * @subpackage dlf
28
 * @access public
29
 */
30
class UserFunc
31
{
32
    /**
33
     * This holds the extension's parameter prefix
34
     * @see \Kitodo\Dlf\Common\AbstractPlugin
35
     *
36
     * @var string
37
     * @access protected
38
     */
39
    protected $prefixId = 'tx_dlf';
40
41
    /**
42
     * Helper to display document's thumbnail
43
     * @see dlf/Configuration/TCA/tx_dlf_documents.php
44
     *
45
     * @access public
46
     *
47
     * @param array &$params: An array with parameters
48
     *
49
     * @return string HTML <img> tag for thumbnail
50
     */
51
    public function displayThumbnail(&$params)
52
    {
53
        // Simulate TCA field type "passthrough".
54
        $output = '<input type="hidden" name="' . $params['itemFormElName'] . '" value="' . $params['itemFormElValue'] . '" />';
55
        if (!empty($params['itemFormElValue'])) {
56
            $output .= '<img alt="Thumbnail" title="' . $params['itemFormElValue'] . '" src="' . $params['itemFormElValue'] . '" />';
57
        }
58
        return $output;
59
    }
60
61
    /**
62
     * Helper to check the current document's type in a Typoscript condition
63
     * @see dlf/ext_localconf.php->user_dlf_docTypeCheck()
64
     *
65
     * @access public
66
     *
67
     * @return string The type of the current document or 'undefined'
68
     */
69
    public function getDocumentType()
70
    {
71
        $type = 'undefined';
72
        // Load document with current plugin parameters.
73
        $doc = $this->loadDocument(GeneralUtility::_GPmerged($this->prefixId));
74
        if ($doc === null) {
75
            return $type;
76
        }
77
        $metadata = $doc->getTitledata();
78
        if (!empty($metadata['type'][0])) {
79
            // Calendar plugin does not support IIIF (yet). Abort for all newspaper related types.
80
            if (
81
                $doc instanceof IiifManifest
82
                && array_search($metadata['type'][0], ['newspaper', 'ephemera', 'year', 'issue']) !== false
83
            ) {
84
                return $type;
85
            }
86
            $type = $metadata['type'][0];
87
        }
88
        return $type;
89
    }
90
91
    /**
92
     * Loads the current document
93
     * @see \Kitodo\Dlf\Common\AbstractPlugin->loadDocument()
94
     *
95
     * @access protected
96
     *
97
     * @param array $piVars The current plugin variables containing a document identifier
98
     *
99
     * @return \Kitodo\Dlf\Common\Document Instance of the current document
100
     */
101
    protected function loadDocument(array $piVars)
102
    {
103
        // Check for required variable.
104
        if (!empty($piVars['id'])) {
105
            // Get instance of document.
106
            $doc = Document::getInstance($piVars['id']);
107
            if ($doc->ready) {
108
                return $doc;
109
            } else {
110
                Helper::devLog('Failed to load document with UID ' . $piVars['id'], DEVLOG_SEVERITY_WARNING);
111
            }
112
        } elseif (!empty($piVars['recordId'])) {
113
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
114
                ->getQueryBuilderForTable('tx_dlf_documents');
115
116
            // Get UID of document with given record identifier.
117
            $result = $queryBuilder
118
                ->select('tx_dlf_documents.uid AS uid')
119
                ->from('tx_dlf_documents')
120
                ->where(
121
                    $queryBuilder->expr()->eq('tx_dlf_documents.record_id', $queryBuilder->expr()->literal($piVars['recordId'])),
122
                    Helper::whereExpression('tx_documents')
123
                )
124
                ->setMaxResults(1)
125
                ->execute();
126
127
            if ($resArray = $result->fetch()) {
128
                // Try to load document.
129
                return $this->loadDocument(['id' => $resArray['uid']]);
130
            } else {
131
                Helper::devLog('Failed to load document with record ID "' . $piVars['recordId'] . '"', DEVLOG_SEVERITY_WARNING);
132
            }
133
        }
134
    }
135
}
136