Passed
Push — master ( 2e9456...0b360e )
by Rafael
82:52 queued 79:33
created

ClearCacheActionsHook::manipulateCacheActions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 12
cp 0
rs 9.9666
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\System\Hooks\Backend\Toolbar;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2018 Timo Hund <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
29
use TYPO3\CMS\Backend\Routing\UriBuilder;
30
use TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface;
31
use TYPO3\CMS\Backend\Utility\BackendUtility;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34
/**
35
 * Class ClearCacheActionsHook
36
 */
37
class ClearCacheActionsHook implements ClearCacheActionsHookInterface
38
{
39
40
    /**
41
     * @var UriBuilder
42
     */
43
    protected $uriBuilder;
44
45
    /**
46
     * @var BackendUserAuthentication
47
     */
48
    protected $backendUser;
49
50
    /**
51
     * ClearCacheActionsHook constructor.
52
     * @param UriBuilder|null $uriBuilder
53
     * @param BackendUserAuthentication|null $backendUser
54
     */
55
    public function __construct(UriBuilder $uriBuilder = null, BackendUserAuthentication $backendUser = null)
56
    {
57
        $this->uriBuilder = $uriBuilder ??  GeneralUtility::makeInstance(UriBuilder::class);
58
        $this->backendUser = $backendUser ?? $GLOBALS['BE_USER'];
59
    }
60
61
    /**
62
     * Adds a menu entry to the clear cache menu to detect Solr connections.
63
     *
64
     * @param array $cacheActions Array of CacheMenuItems
65
     * @param array $optionValues Array of AccessConfigurations-identifiers (typically  used by userTS with options.clearCache.identifier)
66
     */
67
    public function manipulateCacheActions(&$cacheActions, &$optionValues)
68
    {
69
        if (!$this->backendUser->isAdmin()) {
70
            return;
71
        }
72
73
        $href = $this->uriBuilder->buildUriFromRoute('ajax_solr_updateConnections');
74
        $optionValues[] = 'clearSolrConnectionCache';
75
        $cacheActions[] = [
76
            'id' => 'clearSolrConnectionCache',
77
            'title' => 'LLL:EXT:solr/Resources/Private/Language/locallang.xlf:cache_initialize_solr_connections',
78
            'href' => $href,
79
            'iconIdentifier' => 'extensions-solr-module-initsolrconnections'
80
        ];
81
    }
82
}
83