1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Elasticsearch\Framework\Indexing; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\Feature; |
6
|
|
|
use Shopware\Core\Framework\Log\Package; |
7
|
|
|
use Shopware\Elasticsearch\Framework\AbstractElasticsearchDefinition; |
8
|
|
|
|
9
|
|
|
#[Package('core')] |
10
|
|
|
class IndexerOffset |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var list<string> |
|
|
|
|
14
|
|
|
*/ |
15
|
|
|
protected array $definitions; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var list<string> |
19
|
|
|
*/ |
20
|
|
|
protected array $allDefinitions; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @deprecated tag:v6.6.0 - Property $languageId will be removed. |
24
|
|
|
*/ |
25
|
|
|
protected ?string $languageId = null; |
26
|
|
|
|
27
|
|
|
protected ?string $definition = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param list<string> $languages |
31
|
|
|
* @param iterable<AbstractElasticsearchDefinition>|iterable<string> $mappingDefinitions |
32
|
|
|
* @param array{offset: int|null}|null $lastId |
33
|
|
|
* |
34
|
|
|
* @deprecated tag:v6.6.0 - Parameter $languages will be removed. |
35
|
|
|
*/ |
36
|
|
|
public function __construct( |
37
|
|
|
protected array $languages, |
38
|
|
|
iterable $mappingDefinitions, |
39
|
|
|
protected ?int $timestamp, |
40
|
|
|
protected ?array $lastId = null |
41
|
|
|
) { |
42
|
|
|
$mapping = []; |
43
|
|
|
/** @var AbstractElasticsearchDefinition|string $mappingDefinition */ |
44
|
|
|
foreach ($mappingDefinitions as $mappingDefinition) { |
45
|
|
|
if ($mappingDefinition instanceof AbstractElasticsearchDefinition) { |
46
|
|
|
Feature::triggerDeprecationOrThrow('v6.6.0.0', 'Passing definitions objects is deprecated. Pass the entity name instead.'); |
47
|
|
|
$mapping[] = $mappingDefinition->getEntityDefinition()->getEntityName(); |
48
|
|
|
} else { |
49
|
|
|
$mapping[] = $mappingDefinition; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->allDefinitions = $mapping; |
|
|
|
|
54
|
|
|
$this->definitions = $mapping; |
|
|
|
|
55
|
|
|
|
56
|
|
|
if (!Feature::isActive('ES_MULTILINGUAL_INDEX')) { |
57
|
|
|
$this->selectNextLanguage(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->selectNextDefinition(); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @deprecated tag:v6.6.0 - Will be removed. Use selectNextDefinition instead |
65
|
|
|
* |
66
|
|
|
* @phpstan-ignore-next-line ignore needs to be removed when deprecation is removed |
67
|
|
|
*/ |
68
|
|
|
public function setNextDefinition(): ?string |
69
|
|
|
{ |
70
|
|
|
Feature::triggerDeprecationOrThrow( |
71
|
|
|
'v6.6.0.0', |
72
|
|
|
Feature::deprecatedMethodMessage(__CLASS__, __METHOD__, 'v6.6.0.0', 'selectNextDefinition') |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
return $this->selectNextDefinition(); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @deprecated tag:v6.6.0 - reason:return-type-change - will be changed to void and not return anything anymore |
80
|
|
|
*/ |
81
|
|
|
public function selectNextDefinition(): ?string |
82
|
|
|
{ |
83
|
|
|
return $this->definition = array_shift($this->definitions); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function resetDefinitions(): void |
87
|
|
|
{ |
88
|
|
|
$this->definitions = $this->allDefinitions; |
|
|
|
|
89
|
|
|
$this->definition = array_shift($this->definitions); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function hasNextDefinition(): bool |
93
|
|
|
{ |
94
|
|
|
return !empty($this->definitions); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed. |
99
|
|
|
* |
100
|
|
|
* @phpstan-ignore-next-line ignore needs to be removed when deprecation is removed |
101
|
|
|
*/ |
102
|
|
|
public function setNextLanguage(): ?string |
103
|
|
|
{ |
104
|
|
|
Feature::triggerDeprecationOrThrow( |
105
|
|
|
'v6.6.0.0', |
106
|
|
|
Feature::deprecatedMethodMessage(__CLASS__, __METHOD__, 'v6.6.0.0', 'selectNextLanguage') |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
return $this->selectNextLanguage(); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed. |
114
|
|
|
*/ |
115
|
|
|
public function selectNextLanguage(): ?string |
116
|
|
|
{ |
117
|
|
|
return $this->languageId = array_shift($this->languages); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed. |
122
|
|
|
*/ |
123
|
|
|
public function hasNextLanguage(): bool |
124
|
|
|
{ |
125
|
|
|
return !empty($this->languages); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed. |
130
|
|
|
*/ |
131
|
|
|
public function getLanguageId(): ?string |
132
|
|
|
{ |
133
|
|
|
return $this->languageId; |
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return list<string> |
138
|
|
|
* |
139
|
|
|
* @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed. |
140
|
|
|
*/ |
141
|
|
|
public function getLanguages(): array |
142
|
|
|
{ |
143
|
|
|
return $this->languages; |
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return list<string> |
148
|
|
|
*/ |
149
|
|
|
public function getDefinitions(): array |
150
|
|
|
{ |
151
|
|
|
return $this->definitions; |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getTimestamp(): ?int |
155
|
|
|
{ |
156
|
|
|
return $this->timestamp; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return array{offset: int|null}|null |
161
|
|
|
*/ |
162
|
|
|
public function getLastId(): ?array |
163
|
|
|
{ |
164
|
|
|
return $this->lastId; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getDefinition(): ?string |
168
|
|
|
{ |
169
|
|
|
return $this->definition; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param array{offset: int|null}|null $lastId |
174
|
|
|
*/ |
175
|
|
|
public function setLastId(?array $lastId): void |
176
|
|
|
{ |
177
|
|
|
$this->lastId = $lastId; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @internal This method is internal and will be used by Symfony serializer |
182
|
|
|
* |
183
|
|
|
* @return array<string> |
184
|
|
|
*/ |
185
|
|
|
public function getAllDefinitions(): array |
186
|
|
|
{ |
187
|
|
|
return $this->allDefinitions; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param list<string> $allDefinitions |
192
|
|
|
* |
193
|
|
|
* @internal This method is internal and will be used by Symfony serializer |
194
|
|
|
*/ |
195
|
|
|
public function setAllDefinitions(array $allDefinitions): void |
196
|
|
|
{ |
197
|
|
|
$this->allDefinitions = $allDefinitions; |
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param list<string> $definitions |
202
|
|
|
* |
203
|
|
|
* @internal This method is internal and will be used by Symfony serializer |
204
|
|
|
*/ |
205
|
|
|
public function setDefinitions(array $definitions): void |
206
|
|
|
{ |
207
|
|
|
$this->definitions = $definitions; |
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed. |
212
|
|
|
* |
213
|
|
|
* @internal This method is internal and will be used by Symfony serializer |
214
|
|
|
*/ |
215
|
|
|
public function setLanguageId(?string $languageId): void |
216
|
|
|
{ |
217
|
|
|
$this->languageId = $languageId; |
|
|
|
|
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @internal This method is internal and will be used by Symfony serializer |
222
|
|
|
*/ |
223
|
|
|
public function setDefinition(?string $definition): void |
224
|
|
|
{ |
225
|
|
|
$this->definition = $definition; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths