1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Services\AttributeBunchProcessor |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-attribute |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Attribute\Services; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Attribute\Actions\AttributeAction; |
24
|
|
|
use TechDivision\Import\Attribute\Actions\AttributeOptionAction; |
25
|
|
|
use TechDivision\Import\Attribute\Actions\AttributeOptionValueAction; |
26
|
|
|
use TechDivision\Import\Attribute\Actions\CatalogAttributeAction; |
27
|
|
|
use TechDivision\Import\Attribute\Repositories\AttributeRepository; |
28
|
|
|
use TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The attribute bunch processor implementation. |
32
|
|
|
* |
33
|
|
|
* @author Tim Wagner <[email protected]> |
34
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
35
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
36
|
|
|
* @link https://github.com/techdivision/import-attribute |
37
|
|
|
* @link http://www.techdivision.com |
38
|
|
|
*/ |
39
|
|
|
class AttributeBunchProcessor implements AttributeBunchProcessorInterface |
40
|
|
|
{ |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* A PDO connection initialized with the values from the Doctrine EntityManager. |
44
|
|
|
* |
45
|
|
|
* @var \PDO |
46
|
|
|
*/ |
47
|
|
|
protected $connection; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The attribute repository instance. |
51
|
|
|
* |
52
|
|
|
* @var \TechDivision\Import\Attribute\Repositories\AttributeRepository |
53
|
|
|
*/ |
54
|
|
|
protected $attributeRepository; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The catalog attribute repository instance. |
58
|
|
|
* |
59
|
|
|
* @var \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository |
60
|
|
|
*/ |
61
|
|
|
protected $catalogAttributeRepository; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The attribute action instance. |
65
|
|
|
* |
66
|
|
|
* @var \TechDivision\Import\Attribute\Actions\AttributeAction |
67
|
|
|
*/ |
68
|
|
|
protected $attributeAction; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The attribute option action instance. |
72
|
|
|
* |
73
|
|
|
* @var \TechDivision\Import\Attribute\Actions\AttributeOptionAction |
74
|
|
|
*/ |
75
|
|
|
protected $attributeOptionAction; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* The attribute option action instance. |
79
|
|
|
* |
80
|
|
|
* @var \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction |
81
|
|
|
*/ |
82
|
|
|
protected $attributeOptionValueAction; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* The attribute action instance. |
86
|
|
|
* |
87
|
|
|
* @var \TechDivision\Import\Attribute\Actions\CatalogAttributeAction |
88
|
|
|
*/ |
89
|
|
|
protected $catalogAttributeAction; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Initialize the processor with the necessary assembler and repository instances. |
93
|
|
|
* |
94
|
|
|
* @param \PDO $connection The PDO connection to use |
95
|
|
|
* @param \TechDivision\Import\Attribute\Repositories\AttributeRepository $attributeRepository The attribute repository instance |
96
|
|
|
* @param \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository $catalogAttributeRepository The catalog attribute repository instance |
97
|
|
|
* @param \TechDivision\Import\Attribute\Actions\AttributeAction $attributeAction The attribute action instance |
98
|
|
|
* @param \TechDivision\Import\Attribute\Actions\AttributeOptionAction $attributeOptionAction The attribute option action instance |
99
|
|
|
* @param \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction $attributeOptionValueAction The attribute option value action instance |
100
|
|
|
* @param \TechDivision\Import\Attribute\Actions\CatalogAttributeAction $catalogAttributeAction The catalog attribute action instance |
101
|
|
|
*/ |
102
|
|
|
public function __construct( |
103
|
|
|
\PDO $connection, |
104
|
|
|
AttributeRepository $attributeRepository, |
105
|
|
|
CatalogAttributeRepository $catalogAttributeRepository, |
106
|
|
|
AttributeAction $attributeAction, |
107
|
|
|
AttributeOptionAction $attributeOptionAction, |
108
|
|
|
AttributeOptionValueAction $attributeOptionValueAction, |
109
|
|
|
CatalogAttributeAction $catalogAttributeAction |
110
|
|
|
) { |
111
|
|
|
$this->setConnection($connection); |
112
|
|
|
$this->setAttributeRepository($attributeRepository); |
113
|
|
|
$this->setCatalogAttributeRepository($catalogAttributeRepository); |
114
|
|
|
$this->setAttributeAction($attributeAction); |
115
|
|
|
$this->setAttributeOptionAction($attributeOptionAction); |
116
|
|
|
$this->setAttributeOptionValueAction($attributeOptionValueAction); |
117
|
|
|
$this->setCatalogAttributeAction($catalogAttributeAction); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set's the passed connection. |
122
|
|
|
* |
123
|
|
|
* @param \PDO $connection The connection to set |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
|
|
public function setConnection(\PDO $connection) |
128
|
|
|
{ |
129
|
|
|
$this->connection = $connection; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Return's the connection. |
134
|
|
|
* |
135
|
|
|
* @return \PDO The connection instance |
136
|
|
|
*/ |
137
|
|
|
public function getConnection() |
138
|
|
|
{ |
139
|
|
|
return $this->connection; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
144
|
|
|
* object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
145
|
|
|
* Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
146
|
|
|
* to autocommit mode. |
147
|
|
|
* |
148
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
149
|
|
|
* @link http://php.net/manual/en/pdo.begintransaction.php |
150
|
|
|
*/ |
151
|
|
|
public function beginTransaction() |
152
|
|
|
{ |
153
|
|
|
return $this->connection->beginTransaction(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Commits a transaction, returning the database connection to autocommit mode until the next call to |
158
|
|
|
* ProductProcessor::beginTransaction() starts a new transaction. |
159
|
|
|
* |
160
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
161
|
|
|
* @link http://php.net/manual/en/pdo.commit.php |
162
|
|
|
*/ |
163
|
|
|
public function commit() |
164
|
|
|
{ |
165
|
|
|
return $this->connection->commit(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
170
|
|
|
* |
171
|
|
|
* If the database was set to autocommit mode, this function will restore autocommit mode after it has |
172
|
|
|
* rolled back the transaction. |
173
|
|
|
* |
174
|
|
|
* Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
175
|
|
|
* language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
176
|
|
|
* COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
177
|
|
|
* |
178
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
179
|
|
|
* @link http://php.net/manual/en/pdo.rollback.php |
180
|
|
|
*/ |
181
|
|
|
public function rollBack() |
182
|
|
|
{ |
183
|
|
|
return $this->connection->rollBack(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Set's the attribute repository instance. |
188
|
|
|
* |
189
|
|
|
* @param \TechDivision\Import\Attribute\Repositories\AttributeRepository $attributeRepository The attribute repository instance |
190
|
|
|
* |
191
|
|
|
* @return void |
192
|
|
|
*/ |
193
|
|
|
public function setAttributeRepository(AttributeRepository $attributeRepository) |
194
|
|
|
{ |
195
|
|
|
$this->attributeRepository = $attributeRepository; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Return's the attribute repository instance. |
200
|
|
|
* |
201
|
|
|
* @return \TechDivision\Import\Attribute\Repositories\AttributeRepository The attribute repository instance |
202
|
|
|
*/ |
203
|
|
|
public function getAttributeRepository() |
204
|
|
|
{ |
205
|
|
|
return $this->attributeRepository; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Set's the catalog attribute repository instance. |
210
|
|
|
* |
211
|
|
|
* @param \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository $catalogAttributeRepository The catalog attribute repository instance |
212
|
|
|
* |
213
|
|
|
* @return void |
214
|
|
|
*/ |
215
|
|
|
public function setCatalogAttributeRepository(CatalogAttributeRepository $catalogAttributeRepository) |
216
|
|
|
{ |
217
|
|
|
$this->catalogAttributeRepository = $catalogAttributeRepository; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Return's the catalog attribute repository instance. |
222
|
|
|
* |
223
|
|
|
* @return \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository The catalog attribute repository instance |
224
|
|
|
*/ |
225
|
|
|
public function getCatalogAttributeRepository() |
226
|
|
|
{ |
227
|
|
|
return $this->catalogAttributeRepository; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Set's the attribute action instance. |
232
|
|
|
* |
233
|
|
|
* @param \TechDivision\Import\Attribute\Actions\AttributeAction $attributeAction The attribute action instance |
234
|
|
|
* |
235
|
|
|
* @return void |
236
|
|
|
*/ |
237
|
|
|
public function setAttributeAction(AttributeAction $attributeAction) |
238
|
|
|
{ |
239
|
|
|
$this->attributeAction = $attributeAction; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Return's the attribute action instance. |
244
|
|
|
* |
245
|
|
|
* @return \TechDivision\Import\Attribute\Actions\AttributeAction The attribute action instance |
246
|
|
|
*/ |
247
|
|
|
public function getAttributeAction() |
248
|
|
|
{ |
249
|
|
|
return $this->attributeAction; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Set's the attribute option action instance. |
254
|
|
|
* |
255
|
|
|
* @param \TechDivision\Import\Attribute\Actions\AttributeOptionAction $attributeOptionAction The attribute option action instance |
256
|
|
|
* |
257
|
|
|
* @return void |
258
|
|
|
*/ |
259
|
|
|
public function setAttributeOptionAction(AttributeOptionAction $attributeOptionAction) |
260
|
|
|
{ |
261
|
|
|
$this->attributeOptionAction = $attributeOptionAction; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Return's the attribute option action instance. |
266
|
|
|
* |
267
|
|
|
* @return \TechDivision\Import\Attribute\Actions\AttributeOptionAction The attribute option action instance |
268
|
|
|
*/ |
269
|
|
|
public function getAttributeOptionAction() |
270
|
|
|
{ |
271
|
|
|
return $this->attributeOptionAction; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Set's the attribute option value action instance. |
276
|
|
|
* |
277
|
|
|
* @param \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction $attributeOptionValueAction The attribute option value action instance |
278
|
|
|
* |
279
|
|
|
* @return void |
280
|
|
|
*/ |
281
|
|
|
public function setAttributeOptionValueAction(AttributeOptionValueAction $attributeOptionValueAction) |
282
|
|
|
{ |
283
|
|
|
$this->attributeOptionValueAction = $attributeOptionValueAction; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Return's the attribute option value action instance. |
288
|
|
|
* |
289
|
|
|
* @return \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction The attribute option value action instance |
290
|
|
|
*/ |
291
|
|
|
public function getAttributeOptionValueAction() |
292
|
|
|
{ |
293
|
|
|
return $this->attributeOptionValueAction; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Set's the catalog attribute action instance. |
298
|
|
|
* |
299
|
|
|
* @param \TechDivision\Import\Attribute\Actions\CatalogAttributeAction $catalogAttributeAction The catalog attribute action instance |
300
|
|
|
* |
301
|
|
|
* @return void |
302
|
|
|
*/ |
303
|
|
|
public function setCatalogAttributeAction(CatalogAttributeAction $catalogAttributeAction) |
304
|
|
|
{ |
305
|
|
|
$this->catalogAttributeAction = $catalogAttributeAction; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Return's the catalog attribute action instance. |
310
|
|
|
* |
311
|
|
|
* @return \TechDivision\Import\Attribute\Actions\CatalogAttributeAction The catalog attribute action instance |
312
|
|
|
*/ |
313
|
|
|
public function getCatalogAttributeAction() |
314
|
|
|
{ |
315
|
|
|
return $this->catalogAttributeAction; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Load's and return's the EAV attribute with the passed code. |
320
|
|
|
* |
321
|
|
|
* @param string $attributeCode The code of the EAV attribute to load |
322
|
|
|
* |
323
|
|
|
* @return array The EAV attribute |
324
|
|
|
*/ |
325
|
|
|
public function loadAttributeByAttributeCode($attributeCode) |
326
|
|
|
{ |
327
|
|
|
return $this->getAttributeRepository()->findOneByAttributeCode($attributeCode); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Load's and retur's the EAV catalog attribute with the passed ID. |
332
|
|
|
* |
333
|
|
|
* @param string $attributeId The ID of the EAV catalog attribute to return |
334
|
|
|
* |
335
|
|
|
* @return array The EAV catalog attribute |
336
|
|
|
*/ |
337
|
|
|
public function loadCatalogAttribute($attributeId) |
338
|
|
|
{ |
339
|
|
|
return $this->getCatalogAttributeRepository()->load($attributeId); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Persist's the passed EAV attribute data and return's the ID. |
344
|
|
|
* |
345
|
|
|
* @param array $attribute The attribute data to persist |
346
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
347
|
|
|
* |
348
|
|
|
* @return string The ID of the persisted attribute |
349
|
|
|
*/ |
350
|
|
|
public function persistAttribute(array $attribute, $name = null) |
351
|
|
|
{ |
352
|
|
|
return $this->getAttributeAction()->persist($attribute, $name); |
|
|
|
|
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Persist's the passed EAV attribute option data and return's the ID. |
357
|
|
|
* |
358
|
|
|
* @param array $attributeOption The attribute option data to persist |
359
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
360
|
|
|
* |
361
|
|
|
* @return string The ID of the persisted attribute |
362
|
|
|
*/ |
363
|
|
|
public function persistAttributeOption(array $attributeOption, $name = null) |
364
|
|
|
{ |
365
|
|
|
return $this->getAttributeOptionAction()->persist($attributeOption, $name); |
|
|
|
|
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Persist's the passed EAV attribute option value data and return's the ID. |
370
|
|
|
* |
371
|
|
|
* @param array $attributeOptionValue The attribute option value data to persist |
372
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
373
|
|
|
* |
374
|
|
|
* @return void |
375
|
|
|
*/ |
376
|
|
|
public function persistAttributeOptionValue(array $attributeOptionValue, $name = null) |
377
|
|
|
{ |
378
|
|
|
$this->getAttributeOptionValueAction()->persist($attributeOptionValue, $name); |
|
|
|
|
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Persist's the passed EAV catalog attribute data and return's the ID. |
383
|
|
|
* |
384
|
|
|
* @param array $catalogAttribute The catalog attribute data to persist |
385
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
386
|
|
|
* |
387
|
|
|
* @return void |
388
|
|
|
*/ |
389
|
|
|
public function persistCatalogAttribute(array $catalogAttribute, $name = null) |
390
|
|
|
{ |
391
|
|
|
$this->getCatalogAttributeAction()->persist($catalogAttribute, $name); |
|
|
|
|
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Delete's the EAV attribute with the passed attributes. |
396
|
|
|
* |
397
|
|
|
* @param array $row The attributes of the EAV attribute to delete |
398
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
399
|
|
|
* |
400
|
|
|
* @return void |
401
|
|
|
*/ |
402
|
|
|
public function deleteAttribute($row, $name = null) |
403
|
|
|
{ |
404
|
|
|
$this->getAttributeAction()->delete($row, $name); |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.