Passed
Push — release-11.0.x ( 534ada...88d5f5 )
by Rafael
23:03 queued 20:08
created

AbstractFrontendHelper::deactivate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2010-2015 Ingo Renner <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 3 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest;
28
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerResponse;
29
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
32
33
/**
34
 * Index Queue page indexer frontend helper base class implementing common
35
 * functionality.
36
 *
37
 * @author Ingo Renner <[email protected]>
38
 */
39
abstract class AbstractFrontendHelper implements FrontendHelper
40
{
41
42
    /**
43
     * Index Queue page indexer request.
44
     *
45
     * @var PageIndexerRequest
46
     */
47
    protected $request;
48
49
    /**
50
     * Index Queue page indexer response.
51
     *
52
     * @var PageIndexerResponse
53
     */
54
    protected $response;
55
56
    /**
57
     * The action a frontend helper executes.
58
     */
59
    protected $action = null;
60
61
    /**
62
     * @var SolrLogManager
63
     */
64
    protected $logger = null;
65
66
    /**
67
     * Disables the frontend output for index queue requests.
68
     *
69
     * @param array $parameters Parameters from frontend
70
     */
71
    public function disableFrontendOutput(&$parameters)
72
    {
73
        $parameters['enableOutput'] = false;
74
    }
75
76
    /**
77
     * Disables caching for page generation to get reliable results.
78
     *
79
     * @param array $parameters Parameters from frontend
80
     * @param TypoScriptFrontendController $parentObject TSFE object
81
     */
82
    public function disableCaching(
83
        /** @noinspection PhpUnusedParameterInspection */
84
        &$parameters,
85
        $parentObject
86
    ) {
87
        $parentObject->no_cache = true;
88
    }
89
90
    /**
91
     * Starts the execution of a frontend helper.
92
     *
93
     * @param PageIndexerRequest $request Page indexer request
94
     * @param PageIndexerResponse $response Page indexer response
95
     */
96 10
    public function processRequest(
97
        PageIndexerRequest $request,
98
        PageIndexerResponse $response
99
    ) {
100 10
        $this->request = $request;
101 10
        $this->response = $response;
102 10
        $this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
103
104 10
        if ($request->getParameter('loggingEnabled')) {
105
            $this->logger->log(
106
                SolrLogManager::INFO,
107
                'Page indexer request received',
108
                [
109
                    'request' => (array)$request,
110
                ]
111
            );
112
        }
113 10
    }
114
115
    /**
116
     * Deactivates a frontend helper by unregistering from hooks and releasing
117
     * resources.
118
     */
119
    public function deactivate()
120
    {
121
        $this->response->addActionResult($this->action, $this->getData());
122
    }
123
}
124