Failed Conditions
Pull Request — release-11.2.x (#3154)
by Markus
53:46 queued 08:43
created

AbstractDataUpdateEvent   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 191
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
eloc 30
c 1
b 0
f 0
dl 0
loc 191
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setStopProcessing() 0 3 1
A getTable() 0 3 1
A getUid() 0 3 1
A isPageUpdate() 0 3 1
A getFields() 0 3 1
A __construct() 0 6 1
A isImmediateProcessingForced() 0 3 1
A __sleep() 0 20 2
A isContentElementUpdate() 0 3 1
A setForceImmediateProcessing() 0 3 1
A isPropagationStopped() 0 3 1
A frontendGroupsRemoved() 0 3 1
1
<?php declare(strict_types = 1);
2
namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2021 Markus Friedrich <[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 Psr\EventDispatcher\StoppableEventInterface;
28
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\DataUpdateHandler;
29
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\GarbageHandler;
30
31
/**
32
 * Abstract data update event
33
 */
34
abstract class AbstractDataUpdateEvent implements DataUpdateEventInterface, StoppableEventInterface
35
{
36
    /**
37
     * Record uid
38
     *
39
     * @var int
40
     */
41
    protected $uid;
42
43
    /**
44
     * Record table
45
     *
46
     * @var string
47
     */
48
    protected $table;
49
50
    /**
51
     * Updated record fields
52
     *
53
     * @var array
54
     */
55
    protected $fields = [];
56
57
    /**
58
     * Flag indicating that propagation is stopped
59
     *
60
     * @var bool
61
     */
62
    protected $stopProcessing = false;
63
64
    /**
65
     * Flag indicating that immediate processing is forced
66
     *
67
     * @var bool
68
     */
69
    protected $forceImmediateProcessing = false;
70
71
    /**
72
     * Flag indicating that frontend groups were removed
73
     *
74
     * @var array
75
     */
76
    protected $frontendGroupsRemoved = false;
77
78
    /**
79
     * Constructor
80
     *
81
     * @param int $uid
82
     * @param string $uid
83
     * @param array $fields
84
     * @param bool $frontendGroupsRemoved
85
     */
86
    public function __construct(int $uid, string $table, array $fields = [], bool $frontendGroupsRemoved = false)
87
    {
88
        $this->uid = $uid;
89
        $this->table = $table;
90
        $this->fields = $fields;
91
        $this->frontendGroupsRemoved = $frontendGroupsRemoved;
0 ignored issues
show
Documentation Bug introduced by
It seems like $frontendGroupsRemoved of type boolean is incompatible with the declared type array of property $frontendGroupsRemoved.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
92
    }
93
94
    /**
95
     * Cleans the event before serialisation
96
     * e.g. only required fields should be kept
97
     * in fields array
98
     *
99
     * @return array
100
     */
101
    public function __sleep(): array
102
    {
103
        // always remove l10n_diffsource
104
        unset($this->fields['l10n_diffsource']);
105
106
        $properties = array_keys(get_object_vars($this));
107
        if ($this->table == 'pages') {
108
            // skip cleanup for pages as there might be additional
109
            // required update fields in TypoScript which
110
            // we don't want to load here. (see: "recursiveUpdateFields")
111
            return $properties;
112
        }
113
114
        $requiredUpdateFields = array_unique(array_merge(
115
            DataUpdateHandler::getRequiredUpdatedFields(),
116
            GarbageHandler::getRequiredUpdatedFields()
117
        ));
118
        $this->fields = array_intersect_key($this->fields, array_flip($requiredUpdateFields));
119
120
        return $properties;
121
    }
122
123
    /**
124
     * Returns the uid of the updated record
125
     *
126
     * @return int
127
     */
128
    public function getUid(): int
129
    {
130
        return $this->uid;
131
    }
132
133
    /**
134
     * Returns the table of the updated record
135
     *
136
     * @return string
137
     */
138
    public function getTable(): string
139
    {
140
        return $this->table;
141
    }
142
143
    /**
144
     * Returns the updated fields
145
     *
146
     * @return array
147
     */
148
    public function getFields(): array
149
    {
150
        return $this->fields;
151
    }
152
153
    /**
154
     * Indicates if the event propagation is stopped
155
     * If stopped, it prevents other listeners from being called
156
     *
157
     * {@inheritDoc}
158
     * @see \Psr\EventDispatcher\StoppableEventInterface::isPropagationStopped()
159
     */
160
    final public function isPropagationStopped(): bool
161
    {
162
        return $this->stopProcessing;
163
    }
164
165
    /**
166
     * Sets the stop rendering flag
167
     *
168
     * If set, event propagation is stopped
169
     *
170
     * @param bool $stopRendering
171
     */
172
    final public function setStopProcessing(bool $stopProcessing): void
173
    {
174
        $this->stopProcessing = $stopProcessing;
175
    }
176
177
    /**
178
     * Indicates if event is a page update
179
     *
180
     * @return bool
181
     */
182
    public function isPageUpdate(): bool
183
    {
184
        return ($this->table === 'pages');
185
    }
186
187
    /**
188
     * Indicates if event is a content element update
189
     *
190
     * @return bool
191
     */
192
    public function isContentElementUpdate(): bool
193
    {
194
        return ($this->table === 'tt_content');
195
    }
196
197
    /**
198
     * Indicates if immediate processing is forced
199
     *
200
     * @return bool
201
     */
202
    final public function isImmediateProcessingForced(): bool
203
    {
204
        return $this->forceImmediateProcessing;
205
    }
206
207
    /**
208
     * Sets the flag indicating if immediate processing is forced
209
     *
210
     * @param bool $forceImmediateProcessing
211
     */
212
    final public function setForceImmediateProcessing(bool $forceImmediateProcessing): void
213
    {
214
        $this->forceImmediateProcessing = $forceImmediateProcessing;
215
    }
216
217
    /**
218
     * Indicates the removal of frontend groups
219
     *
220
     * @return bool
221
     */
222
    final public function frontendGroupsRemoved(): bool
223
    {
224
        return $this->frontendGroupsRemoved;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->frontendGroupsRemoved returns the type array which is incompatible with the type-hinted return boolean.
Loading history...
225
    }
226
}
227