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 (#845)
by
unknown
03:24
created

ItemsProcFunc::toolList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
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\Helper;
16
use TYPO3\CMS\Core\Database\ConnectionPool;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
19
use TYPO3\CMS\Extbase\Object\ObjectManager;
20
21
/**
22
 * Helper for Flexform's custom "itemsProcFunc"
23
 *
24
 * @author Sebastian Meyer <[email protected]>
25
 * @package TYPO3
26
 * @subpackage dlf
27
 * @access public
28
 */
29
class ItemsProcFunc
30
{
31
    /**
32
     * @var int
33
     */
34
    protected $storagePid;
35
36
    /**
37
     * Helper to get flexform's items array for plugin "Toolbox"
38
     *
39
     * @access public
40
     *
41
     * @param array &$params: An array with parameters
42
     *
43
     * @return void
44
     */
45
    public function toolList(&$params)
46
    {
47
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'] as $class => $label) {
48
            $params['items'][] = [Helper::getLanguageService()->getLL($label), $class];
49
        }
50
    }
51
52
    /**
53
     * Extract typoscript configuration from site root of the plugin
54
     *
55
     * @access public
56
     *
57
     * @param $params
58
     *
59
     * @return void
60
     */
61
    public function getTyposcriptConfigFromPluginSiteRoot($params) {
62
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
63
        $pid = $params['flexParentDatabaseRow']['pid'];
64
        $rootline = \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($pid);
65
        $siterootRow = [];
66
        foreach($rootline as $_uid=>$_row) {
67
            if($_row['is_siteroot'] == '1') {
68
                $siterootRow = $_row;
69
                break;
70
            }
71
        }
72
73
        try {
74
            $ts = $objectManager->get(\TYPO3\CMS\Core\TypoScript\TemplateService::class,[$siterootRow['uid']]);
75
            $ts->rootLine = $rootline;
76
            $ts->runThroughTemplates($rootline, 0);
77
            $ts->generateConfig();
78
        } catch (\Exception $e) {
79
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
80
        }
81
82
        $typoscriptConfig = $ts->setup;
83
        $this->storagePid = $typoscriptConfig['plugin.']['tx_dlf.']['persistence.']['storagePid'];
84
85
    }
86
87
    /**
88
     * Helper to get flexform's items array for plugin "Search"
89
     *
90
     * @access public
91
     *
92
     * @param array &$params: An array with parameters
93
     *
94
     * @return void
95
     */
96
    public function extendedSearchList(&$params)
97
    {
98
        $this->generateList(
99
            $params,
100
            'label,index_name',
101
            'tx_dlf_metadata',
102
            'label',
103
            'index_indexed=1'
104
        );
105
    }
106
107
    /**
108
     * Helper to get flexform's items array for plugin "Search"
109
     *
110
     * @access public
111
     *
112
     * @param array &$params: An array with parameters
113
     */
114
    public function getFacetsList(array &$params): void
115
    {
116
        $this->generateList(
117
            $params,
118
            'label,index_name',
119
            'tx_dlf_metadata',
120
            'label',
121
            'is_facet=1'
122
        );
123
    }
124
125
    /**
126
     * Get list items from database
127
     *
128
     * @access protected
129
     *
130
     * @param array &$params: An array with parameters
131
     * @param string $fields: Comma-separated list of fields to fetch
132
     * @param string $table: Table name to fetch the items from
133
     * @param string $sorting: Field to sort items by (optionally appended by 'ASC' or 'DESC')
134
     * @param string $andWhere: Additional AND WHERE clause
135
     *
136
     * @return void
137
     */
138
    protected function generateList(&$params, $fields, $table, $sorting, $andWhere = '')
139
    {
140
        $this->getTyposcriptConfigFromPluginSiteRoot($params);
141
142
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
143
            ->getQueryBuilderForTable($table);
144
145
        // Get $fields from $table on given pid.
146
        $result = $queryBuilder
147
            ->select(...explode(',', $fields))
148
            ->from($table)
149
            ->where(
150
                $queryBuilder->expr()->eq($table . '.pid', intval($this->storagePid)),
151
                $queryBuilder->expr()->in($table . '.sys_language_uid', [-1, 0]),
152
                $andWhere
153
            )
154
            ->orderBy($sorting)
155
            ->execute();
156
157
        while ($resArray = $result->fetch(\PDO::FETCH_NUM)) {
158
            if ($resArray) {
159
                $params['items'][] = $resArray;
160
            }
161
        }
162
    }
163
}
164