1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Media\Services\ProductMediaProcessor |
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-product-media |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Media\Services; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* A SLSB providing methods to load product data using a PDO connection. |
25
|
|
|
* |
26
|
|
|
* @author Tim Wagner <[email protected]> |
27
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/techdivision/import-product-media |
30
|
|
|
* @link http://www.techdivision.com |
31
|
|
|
*/ |
32
|
|
|
class ProductMediaProcessor implements ProductMediaProcessorInterface |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* A PDO connection initialized with the values from the Doctrine EntityManager. |
37
|
|
|
* |
38
|
|
|
* @var \PDO |
39
|
|
|
*/ |
40
|
|
|
protected $connection; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The repository to load product media galleries. |
44
|
|
|
* |
45
|
|
|
* @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepository |
46
|
|
|
*/ |
47
|
|
|
protected $productMediaGalleryRepository; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The repository to load product media gallery to entities. |
51
|
|
|
* |
52
|
|
|
* @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepository |
53
|
|
|
*/ |
54
|
|
|
protected $productMediaGalleryValueToEntityRepository; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The repository to load product media gallery values. |
58
|
|
|
* |
59
|
|
|
* @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepository |
60
|
|
|
*/ |
61
|
|
|
protected $productMediaGalleryValueRepository; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The action with the product media gallery CRUD methods. |
65
|
|
|
* |
66
|
|
|
* @var \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction |
67
|
|
|
*/ |
68
|
|
|
protected $productMediaGalleryAction; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The action with the product media gallery value CRUD methods. |
72
|
|
|
* |
73
|
|
|
* @var \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryValueAction |
74
|
|
|
*/ |
75
|
|
|
protected $productMediaGalleryValueAction; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* The action with the product media gallery value to entity CRUD methods. |
79
|
|
|
* |
80
|
|
|
* @var \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryValueToEntityAction |
81
|
|
|
*/ |
82
|
|
|
protected $productMediaGalleryValueToEntityAction; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* The action with the product media gallery video CRUD methods. |
86
|
|
|
* |
87
|
|
|
* @var \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryVideoAction |
88
|
|
|
*/ |
89
|
|
|
protected $productMediaGalleryVideoAction; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set's the passed connection. |
93
|
|
|
* |
94
|
|
|
* @param \PDO $connection The connection to set |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function setConnection(\PDO $connection) |
99
|
|
|
{ |
100
|
|
|
$this->connection = $connection; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Return's the connection. |
105
|
|
|
* |
106
|
|
|
* @return \PDO The connection instance |
107
|
|
|
*/ |
108
|
|
|
public function getConnection() |
109
|
|
|
{ |
110
|
|
|
return $this->connection; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
115
|
|
|
* object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
116
|
|
|
* Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
117
|
|
|
* to autocommit mode. |
118
|
|
|
* |
119
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
120
|
|
|
* @link http://php.net/manual/en/pdo.begintransaction.php |
121
|
|
|
*/ |
122
|
|
|
public function beginTransaction() |
123
|
|
|
{ |
124
|
|
|
return $this->connection->beginTransaction(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Commits a transaction, returning the database connection to autocommit mode until the next call to |
129
|
|
|
* ProductProcessor::beginTransaction() starts a new transaction. |
130
|
|
|
* |
131
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
132
|
|
|
* @link http://php.net/manual/en/pdo.commit.php |
133
|
|
|
*/ |
134
|
|
|
public function commit() |
135
|
|
|
{ |
136
|
|
|
return $this->connection->commit(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
141
|
|
|
* |
142
|
|
|
* If the database was set to autocommit mode, this function will restore autocommit mode after it has |
143
|
|
|
* rolled back the transaction. |
144
|
|
|
* |
145
|
|
|
* Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
146
|
|
|
* language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
147
|
|
|
* COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
148
|
|
|
* |
149
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
150
|
|
|
* @link http://php.net/manual/en/pdo.rollback.php |
151
|
|
|
*/ |
152
|
|
|
public function rollBack() |
153
|
|
|
{ |
154
|
|
|
return $this->connection->rollBack(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set's the repository to load product media gallery data. |
159
|
|
|
* |
160
|
|
|
* @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepository $productMediaGalleryRepository The repository instance |
161
|
|
|
* |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
public function setProductMediaGalleryRepository($productMediaGalleryRepository) |
165
|
|
|
{ |
166
|
|
|
$this->productMediaGalleryRepository = $productMediaGalleryRepository; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Return's the repository to load product media gallery data. |
171
|
|
|
* |
172
|
|
|
* @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepository The repository instance |
173
|
|
|
*/ |
174
|
|
|
public function getProductMediaGalleryRepository() |
175
|
|
|
{ |
176
|
|
|
return $this->productMediaGalleryRepository; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Set's the repository to load product media gallery value to entity data. |
181
|
|
|
* |
182
|
|
|
* @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepository $productMediaGalleryValueToEntityRepository The repository instance |
183
|
|
|
* |
184
|
|
|
* @return void |
185
|
|
|
*/ |
186
|
|
|
public function setProductMediaGalleryValueToEntityRepository($productMediaGalleryValueToEntityRepository) |
187
|
|
|
{ |
188
|
|
|
$this->productMediaGalleryValueToEntityRepository = $productMediaGalleryValueToEntityRepository; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Return's the repository to load product media gallery value to entity data. |
193
|
|
|
* |
194
|
|
|
* @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepository The repository instance |
195
|
|
|
*/ |
196
|
|
|
public function getProductMediaGalleryValueToEntityRepository() |
197
|
|
|
{ |
198
|
|
|
return $this->productMediaGalleryValueToEntityRepository; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Set's the repository to load product media gallery value data. |
203
|
|
|
* |
204
|
|
|
* @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepository $productMediaGalleryValueRepository The repository instance |
205
|
|
|
* |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function setProductMediaGalleryValueRepository($productMediaGalleryValueRepository) |
209
|
|
|
{ |
210
|
|
|
$this->productMediaGalleryValueRepository = $productMediaGalleryValueRepository; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Return's the repository to load product media gallery value data. |
215
|
|
|
* |
216
|
|
|
* @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepository The repository instance |
217
|
|
|
*/ |
218
|
|
|
public function getProductMediaGalleryValueRepository() |
219
|
|
|
{ |
220
|
|
|
return $this->productMediaGalleryValueRepository; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Set's the action with the product media gallery CRUD methods. |
225
|
|
|
* |
226
|
|
|
* @param \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction $productMediaGalleryAction The action with the product media gallery CRUD methods |
227
|
|
|
* |
228
|
|
|
* @return void |
229
|
|
|
*/ |
230
|
|
|
public function setProductMediaGalleryAction($productMediaGalleryAction) |
231
|
|
|
{ |
232
|
|
|
$this->productMediaGalleryAction = $productMediaGalleryAction; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Return's the action with the product media gallery CRUD methods. |
237
|
|
|
* |
238
|
|
|
* @return \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction The action with the product media gallery CRUD methods |
239
|
|
|
*/ |
240
|
|
|
public function getProductMediaGalleryAction() |
241
|
|
|
{ |
242
|
|
|
return $this->productMediaGalleryAction; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Set's the action with the product media gallery valueCRUD methods. |
247
|
|
|
* |
248
|
|
|
* @param \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction $productMediaGalleryValueAction The action with the product media gallery value CRUD methods |
249
|
|
|
* |
250
|
|
|
* @return void |
251
|
|
|
*/ |
252
|
|
|
public function setProductMediaGalleryValueAction($productMediaGalleryValueAction) |
253
|
|
|
{ |
254
|
|
|
$this->productMediaGalleryValueAction = $productMediaGalleryValueAction; |
|
|
|
|
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Return's the action with the product media gallery valueCRUD methods. |
259
|
|
|
* |
260
|
|
|
* @return \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction The action with the product media gallery value CRUD methods |
261
|
|
|
*/ |
262
|
|
|
public function getProductMediaGalleryValueAction() |
263
|
|
|
{ |
264
|
|
|
return $this->productMediaGalleryValueAction; |
|
|
|
|
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Set's the action with the product media gallery value to entity CRUD methods. |
269
|
|
|
* |
270
|
|
|
* @param \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction $productMediaGalleryValueToEntityAction The action with the product media gallery value to entity CRUD methods |
271
|
|
|
* |
272
|
|
|
* @return void |
273
|
|
|
*/ |
274
|
|
|
public function setProductMediaGalleryValueToEntityAction($productMediaGalleryValueToEntityAction) |
275
|
|
|
{ |
276
|
|
|
$this->productMediaGalleryValueToEntityAction = $productMediaGalleryValueToEntityAction; |
|
|
|
|
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Return's the action with the product media gallery value to entity CRUD methods. |
281
|
|
|
* |
282
|
|
|
* @return \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction $productMediaGalleryAction The action with the product media gallery value to entity CRUD methods |
283
|
|
|
*/ |
284
|
|
|
public function getProductMediaGalleryValueToEntityAction() |
285
|
|
|
{ |
286
|
|
|
return $this->productMediaGalleryValueToEntityAction; |
|
|
|
|
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Set's the action with the product media gallery value video CRUD methods. |
291
|
|
|
* |
292
|
|
|
* @param \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction $productMediaGalleryValueVideoAction The action with the product media gallery value video CRUD methods |
293
|
|
|
* |
294
|
|
|
* @return void |
295
|
|
|
*/ |
296
|
|
|
public function setProductMediaGalleryValueVideoAction($productMediaGalleryValueVideoAction) |
297
|
|
|
{ |
298
|
|
|
$this->productMediaGalleryValueVideoAction = $productMediaGalleryValueVideoAction; |
|
|
|
|
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Return's the action with the product media gallery value video CRUD methods. |
303
|
|
|
* |
304
|
|
|
* @return \TechDivision\Import\Product\Media\Actions\ProductMediaGalleryAction The action with the product media gallery value video CRUD methods |
305
|
|
|
*/ |
306
|
|
|
public function getProductMediaGalleryValueVideoAction() |
307
|
|
|
{ |
308
|
|
|
return $this->productMediaGalleryValueVideoAction; |
|
|
|
|
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Load's the product media gallery with the passed attribute ID + value. |
313
|
|
|
* |
314
|
|
|
* @param integer $attributeId The attribute ID of the product media gallery to load |
315
|
|
|
* @param string $value The value of the product media gallery to load |
316
|
|
|
* |
317
|
|
|
* @return array The product media gallery |
318
|
|
|
*/ |
319
|
|
|
public function loadProductMediaGallery($attributeId, $value) |
320
|
|
|
{ |
321
|
|
|
return $this->getProductMediaGalleryRepository()->findOneByAttributeIdAndValue($attributeId, $value); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Load's the product media gallery with the passed value/entity ID. |
326
|
|
|
* |
327
|
|
|
* @param integer $valueId The value ID of the product media gallery value to entity to load |
328
|
|
|
* @param integer $entityId The entity ID of the product media gallery value to entity to load |
329
|
|
|
* |
330
|
|
|
* @return array The product media gallery |
331
|
|
|
*/ |
332
|
|
|
public function loadProductMediaGalleryValueToEntity($valueId, $entityId) |
333
|
|
|
{ |
334
|
|
|
return $this->getProductMediaGalleryValueToEntityRepository()->findOneByValueIdAndEntityId($valueId, $entityId); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Load's the product media gallery value with the passed value/store/parent ID. |
339
|
|
|
* |
340
|
|
|
* @param integer $valueId The value ID of the product media gallery value to load |
341
|
|
|
* @param string $storeId The store ID of the product media gallery value to load |
342
|
|
|
* @param string $entityId The entity ID of the parent product of the product media gallery value to load |
343
|
|
|
* |
344
|
|
|
* @return array The product media gallery value |
345
|
|
|
*/ |
346
|
|
|
public function loadProductMediaGalleryValue($valueId, $storeId, $entityId) |
347
|
|
|
{ |
348
|
|
|
return $this->getProductMediaGalleryValueRepository()->findOneByValueIdAndStoreIdAndEntityId($valueId, $storeId, $entityId); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Persist's the passed product media gallery data and return's the ID. |
353
|
|
|
* |
354
|
|
|
* @param array $productMediaGallery The product media gallery data to persist |
355
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
356
|
|
|
* |
357
|
|
|
* @return string The ID of the persisted entity |
358
|
|
|
*/ |
359
|
|
|
public function persistProductMediaGallery($productMediaGallery, $name = null) |
360
|
|
|
{ |
361
|
|
|
return $this->getProductMediaGalleryAction()->persist($productMediaGallery, $name); |
|
|
|
|
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Persist's the passed product media gallery value data. |
366
|
|
|
* |
367
|
|
|
* @param array $productMediaGalleryValue The product media gallery value data to persist |
368
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
369
|
|
|
* |
370
|
|
|
* @return void |
371
|
|
|
*/ |
372
|
|
|
public function persistProductMediaGalleryValue($productMediaGalleryValue, $name = null) |
373
|
|
|
{ |
374
|
|
|
$this->getProductMediaGalleryValueAction()->persist($productMediaGalleryValue, $name); |
|
|
|
|
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* Persist's the passed product media gallery value to entity data. |
379
|
|
|
* |
380
|
|
|
* @param array $productMediaGalleryValuetoEntity The product media gallery value to entity data to persist |
381
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
382
|
|
|
* |
383
|
|
|
* @return void |
384
|
|
|
*/ |
385
|
|
|
public function persistProductMediaGalleryValueToEntity($productMediaGalleryValuetoEntity, $name = null) |
386
|
|
|
{ |
387
|
|
|
$this->getProductMediaGalleryValueToEntityAction()->persist($productMediaGalleryValuetoEntity, $name); |
|
|
|
|
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Persist's the passed product media gallery value video data. |
392
|
|
|
* |
393
|
|
|
* @param array $productMediaGalleryValueVideo The product media gallery value video data to persist |
394
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
395
|
|
|
* |
396
|
|
|
* @return void |
397
|
|
|
*/ |
398
|
|
|
public function persistProductMediaGalleryValueVideo($productMediaGalleryValueVideo, $name = null) |
399
|
|
|
{ |
400
|
|
|
$this->getProductMediaGalleryValueVideoAction()->persist($productMediaGalleryValueVideo, $name); |
|
|
|
|
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
|
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..