Passed
Push — master ( 90f5c3...f8e2ef )
by Timo
23:55 queued 19:58
created

AjaxController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 45
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateConnection() 0 21 3
A updateConnections() 0 5 1
1
<?php
2
declare(strict_types=1);
3
namespace ApacheSolrForTypo3\Solr\Controller\Backend;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2012-2015 Ingo Renner <[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 2 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 ApacheSolrForTypo3\Solr\ConnectionManager;
29
use Psr\Http\Message\ResponseInterface;
30
use Psr\Http\Message\ServerRequestInterface;
31
use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33
/**
34
 * Handling of Ajax requests
35
 */
36
class AjaxController
37
{
38
    /**
39
     * Update a single solr connection
40
     *
41
     * @param ServerRequestInterface $request
42
     * @param ResponseInterface $response
43
     * @return ResponseInterface
44
     */
45
    public function updateConnection(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
46
    {
47
        $queryParams = $request->getQueryParams();
48
        $pageId = 0;
49
        if (isset($queryParams['id'])) {
50
            $pageId = (int)$queryParams['id'];
51
        }
52
53
        // Currently no return value from connection manager
54
        $content = [
55
            'success' => true,
56
            'message' => 'The cache has bee cleared'
57
        ];
58
        if ($pageId) {
59
            $connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);
60
            $connectionManager->updateConnectionByRootPageId($pageId);
61
        }
62
63
        $response->getBody()->write(json_encode($content));
64
        return $response;
65
    }
66
67
    /**
68
     * Update all connections
69
     *
70
     * @param ServerRequestInterface $request
71
     * @param ResponseInterface $response
72
     * @return ResponseInterface
73
     */
74
    public function updateConnections(ServerRequestInterface $request, ResponseInterface $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        $connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);
77
        $connectionManager->updateConnections();
78
    }
79
80
}
81