Completed
Push — 19.x ( 2d1425...ec9646 )
by Tim
01:35
created

ProductMediaProcessor::deleteProductMediaGallery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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
use TechDivision\Import\Actions\ActionInterface;
24
use TechDivision\Import\Connection\ConnectionInterface;
25
use TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface;
26
use TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface;
27
use TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface;
28
29
/**
30
 * The product media processor implementation.
31
 *
32
 * @author    Tim Wagner <[email protected]>
33
 * @copyright 2016 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-product-media
36
 * @link      http://www.techdivision.com
37
 */
38
class ProductMediaProcessor implements ProductMediaProcessorInterface
39
{
40
41
    /**
42
     * A PDO connection initialized with the values from the Doctrine EntityManager.
43
     *
44
     * @var \TechDivision\Import\Connection\ConnectionInterface
45
     */
46
    protected $connection;
47
48
    /**
49
     * The repository to load product media galleries.
50
     *
51
     * @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface
52
     */
53
    protected $productMediaGalleryRepository;
54
55
    /**
56
     * The repository to load product media gallery to entities.
57
     *
58
     * @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface
59
     */
60
    protected $productMediaGalleryValueToEntityRepository;
61
62
    /**
63
     * The repository to load product media gallery values.
64
     *
65
     * @var \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface
66
     */
67
    protected $productMediaGalleryValueRepository;
68
69
    /**
70
     * The action with the product media gallery CRUD methods.
71
     *
72
     * @var \TechDivision\Import\Actions\ActionInterface
73
     */
74
    protected $productMediaGalleryAction;
75
76
    /**
77
     * The action with the product media gallery value CRUD methods.
78
     *
79
     * @var \TechDivision\Import\Actions\ActionInterface
80
     */
81
    protected $productMediaGalleryValueAction;
82
83
    /**
84
     * The action with the product media gallery value to entity CRUD methods.
85
     *
86
     * @var \TechDivision\Import\Actions\ActionInterface
87
     */
88
    protected $productMediaGalleryValueToEntityAction;
89
90
    /**
91
     * The action with the product media gallery video CRUD methods.
92
     *
93
     * @var \TechDivision\Import\Actions\ActionInterface
94
     */
95
    protected $productMediaGalleryVideoAction;
96
97
    /**
98
     * Initialize the processor with the necessary assembler and repository instances.
99
     *
100
     * @param \TechDivision\Import\Connection\ConnectionInterface                                                 $connection                                 The connection to use
101
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface              $productMediaGalleryRepository              The product media gallery repository to use
102
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface         $productMediaGalleryValueRepository         The product media gallery value repository to use
103
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository The product media gallery value to entity repository to use
104
     * @param \TechDivision\Import\Actions\ActionInterface                                                        $productMediaGalleryAction                  The product media gallery action to use
105
     * @param \TechDivision\Import\Actions\ActionInterface                                                        $productMediaGalleryValueAction             The product media gallery value action to use
106
     * @param \TechDivision\Import\Actions\ActionInterface                                                        $productMediaGalleryValueToEntityAction     The product media gallery value to entity action to use
107
     * @param \TechDivision\Import\Actions\ActionInterface                                                        $productMediaGalleryValueVideoAction        The product media gallery value video action to use
108
     */
109
    public function __construct(
110
        ConnectionInterface $connection,
111
        ProductMediaGalleryRepositoryInterface $productMediaGalleryRepository,
112
        ProductMediaGalleryValueRepositoryInterface $productMediaGalleryValueRepository,
113
        ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository,
114
        ActionInterface $productMediaGalleryAction,
115
        ActionInterface $productMediaGalleryValueAction,
116
        ActionInterface $productMediaGalleryValueToEntityAction,
117
        ActionInterface $productMediaGalleryValueVideoAction
118
    ) {
119
        $this->setConnection($connection);
120
        $this->setProductMediaGalleryRepository($productMediaGalleryRepository);
121
        $this->setProductMediaGalleryValueRepository($productMediaGalleryValueRepository);
122
        $this->setProductMediaGalleryValueToEntityRepository($productMediaGalleryValueToEntityRepository);
123
        $this->setProductMediaGalleryAction($productMediaGalleryAction);
124
        $this->setProductMediaGalleryValueAction($productMediaGalleryValueAction);
125
        $this->setProductMediaGalleryValueToEntityAction($productMediaGalleryValueToEntityAction);
126
        $this->setProductMediaGalleryValueVideoAction($productMediaGalleryValueVideoAction);
127
    }
128
129
    /**
130
     * Set's the passed connection.
131
     *
132
     * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to set
133
     *
134
     * @return void
135
     */
136
    public function setConnection(ConnectionInterface $connection)
137
    {
138
        $this->connection = $connection;
139
    }
140
141
    /**
142
     * Return's the connection.
143
     *
144
     * @return \TechDivision\Import\Connection\ConnectionInterface The connection instance
145
     */
146
    public function getConnection()
147
    {
148
        return $this->connection;
149
    }
150
151
    /**
152
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
153
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
154
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
155
     * to autocommit mode.
156
     *
157
     * @return boolean Returns TRUE on success or FALSE on failure
158
     * @link http://php.net/manual/en/pdo.begintransaction.php
159
     */
160
    public function beginTransaction()
161
    {
162
        return $this->connection->beginTransaction();
163
    }
164
165
    /**
166
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
167
     * ProductProcessor::beginTransaction() starts a new transaction.
168
     *
169
     * @return boolean Returns TRUE on success or FALSE on failure
170
     * @link http://php.net/manual/en/pdo.commit.php
171
     */
172
    public function commit()
173
    {
174
        return $this->connection->commit();
175
    }
176
177
    /**
178
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
179
     *
180
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
181
     * rolled back the transaction.
182
     *
183
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
184
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
185
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
186
     *
187
     * @return boolean Returns TRUE on success or FALSE on failure
188
     * @link http://php.net/manual/en/pdo.rollback.php
189
     */
190
    public function rollBack()
191
    {
192
        return $this->connection->rollBack();
193
    }
194
195
    /**
196
     * Set's the repository to load product media gallery data.
197
     *
198
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface $productMediaGalleryRepository The repository instance
199
     *
200
     * @return void
201
     */
202
    public function setProductMediaGalleryRepository(ProductMediaGalleryRepositoryInterface $productMediaGalleryRepository)
203
    {
204
        $this->productMediaGalleryRepository = $productMediaGalleryRepository;
205
    }
206
207
    /**
208
     * Return's the repository to load product media gallery data.
209
     *
210
     * @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryRepositoryInterface The repository instance
211
     */
212
    public function getProductMediaGalleryRepository()
213
    {
214
        return $this->productMediaGalleryRepository;
215
    }
216
217
    /**
218
     * Set's the repository to load product media gallery value to entity data.
219
     *
220
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository The repository instance
221
     *
222
     * @return void
223
     */
224
    public function setProductMediaGalleryValueToEntityRepository(ProductMediaGalleryValueToEntityRepositoryInterface $productMediaGalleryValueToEntityRepository)
225
    {
226
        $this->productMediaGalleryValueToEntityRepository = $productMediaGalleryValueToEntityRepository;
227
    }
228
229
    /**
230
     * Return's the repository to load product media gallery value to entity data.
231
     *
232
     * @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueToEntityRepositoryInterface The repository instance
233
     */
234
    public function getProductMediaGalleryValueToEntityRepository()
235
    {
236
        return $this->productMediaGalleryValueToEntityRepository;
237
    }
238
239
    /**
240
     * Set's the repository to load product media gallery value data.
241
     *
242
     * @param \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface $productMediaGalleryValueRepository The repository instance
243
     *
244
     * @return void
245
     */
246
    public function setProductMediaGalleryValueRepository(ProductMediaGalleryValueRepositoryInterface $productMediaGalleryValueRepository)
247
    {
248
        $this->productMediaGalleryValueRepository = $productMediaGalleryValueRepository;
249
    }
250
251
    /**
252
     * Return's the repository to load product media gallery value data.
253
     *
254
     * @return \TechDivision\Import\Product\Media\Repositories\ProductMediaGalleryValueRepositoryInterface The repository instance
255
     */
256
    public function getProductMediaGalleryValueRepository()
257
    {
258
        return $this->productMediaGalleryValueRepository;
259
    }
260
261
    /**
262
     * Set's the action with the product media gallery CRUD methods.
263
     *
264
     * @param \TechDivision\Import\Actions\ActionInterface $productMediaGalleryAction The action with the product media gallery CRUD methods
265
     *
266
     * @return void
267
     */
268
    public function setProductMediaGalleryAction(ActionInterface $productMediaGalleryAction)
269
    {
270
        $this->productMediaGalleryAction = $productMediaGalleryAction;
271
    }
272
273
    /**
274
     * Return's the action with the product media gallery CRUD methods.
275
     *
276
     * @return \TechDivision\Import\Actions\ActionInterface The action with the product media gallery CRUD methods
277
     */
278
    public function getProductMediaGalleryAction()
279
    {
280
        return $this->productMediaGalleryAction;
281
    }
282
283
    /**
284
     * Set's the action with the product media gallery valueCRUD methods.
285
     *
286
     * @param \TechDivision\Import\Actions\ActionInterface $productMediaGalleryValueAction The action with the product media gallery value CRUD methods
287
     *
288
     * @return void
289
     */
290
    public function setProductMediaGalleryValueAction(ActionInterface $productMediaGalleryValueAction)
291
    {
292
        $this->productMediaGalleryValueAction = $productMediaGalleryValueAction;
293
    }
294
295
    /**
296
     * Return's the action with the product media gallery valueCRUD methods.
297
     *
298
     * @return \TechDivision\Import\Actions\ActionInterface The action with the product media gallery value CRUD methods
299
     */
300
    public function getProductMediaGalleryValueAction()
301
    {
302
        return $this->productMediaGalleryValueAction;
303
    }
304
305
    /**
306
     * Set's the action with the product media gallery value to entity CRUD methods.
307
     *
308
     * @param \TechDivision\Import\Actions\ActionInterface $productMediaGalleryValueToEntityAction The action with the product media gallery value to entity CRUD methods
309
     *
310
     * @return void
311
     */
312
    public function setProductMediaGalleryValueToEntityAction(ActionInterface $productMediaGalleryValueToEntityAction)
313
    {
314
        $this->productMediaGalleryValueToEntityAction = $productMediaGalleryValueToEntityAction;
315
    }
316
317
    /**
318
     * Return's the action with the product media gallery value to entity CRUD methods.
319
     *
320
     * @return \TechDivision\Import\Actions\ActionInterface $productMediaGalleryAction The action with the product media gallery value to entity CRUD methods
321
     */
322
    public function getProductMediaGalleryValueToEntityAction()
323
    {
324
        return $this->productMediaGalleryValueToEntityAction;
325
    }
326
327
    /**
328
     * Set's the action with the product media gallery value video CRUD methods.
329
     *
330
     * @param \TechDivision\Import\Actions\ActionInterface $productMediaGalleryValueVideoAction The action with the product media gallery value video CRUD methods
331
     *
332
     * @return void
333
     */
334
    public function setProductMediaGalleryValueVideoAction(ActionInterface $productMediaGalleryValueVideoAction)
335
    {
336
        $this->productMediaGalleryValueVideoAction = $productMediaGalleryValueVideoAction;
0 ignored issues
show
Bug introduced by
The property productMediaGalleryValueVideoAction does not seem to exist. Did you mean productMediaGalleryValueAction?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
337
    }
338
339
    /**
340
     * Return's the action with the product media gallery value video CRUD methods.
341
     *
342
     * @return \TechDivision\Import\Actions\ActionInterface The action with the product media gallery value video CRUD methods
343
     */
344
    public function getProductMediaGalleryValueVideoAction()
345
    {
346
        return $this->productMediaGalleryValueVideoAction;
0 ignored issues
show
Bug introduced by
The property productMediaGalleryValueVideoAction does not seem to exist. Did you mean productMediaGalleryValueAction?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
347
    }
348
349
    /**
350
     * Load's the product media gallery with the passed attribute ID + value.
351
     *
352
     * @param integer $attributeId The attribute ID of the product media gallery to load
353
     * @param string  $value       The value of the product media gallery to load
354
     *
355
     * @return array The product media gallery
356
     */
357
    public function loadProductMediaGallery($attributeId, $value)
358
    {
359
        return $this->getProductMediaGalleryRepository()->findOneByAttributeIdAndValue($attributeId, $value);
360
    }
361
362
    /**
363
     * Load's the product media gallery with the passed value/entity ID.
364
     *
365
     * @param integer $valueId  The value ID of the product media gallery value to entity to load
366
     * @param integer $entityId The entity ID of the product media gallery value to entity to load
367
     *
368
     * @return array The product media gallery
369
     */
370
    public function loadProductMediaGalleryValueToEntity($valueId, $entityId)
371
    {
372
        return $this->getProductMediaGalleryValueToEntityRepository()->findOneByValueIdAndEntityId($valueId, $entityId);
373
    }
374
375
    /**
376
     * Load's the product media gallery value with the passed value/store/parent ID.
377
     *
378
     * @param integer $valueId  The value ID of the product media gallery value to load
379
     * @param string  $storeId  The store ID of the product media gallery value to load
380
     * @param string  $entityId The entity ID of the parent product of the product media gallery value to load
381
     *
382
     * @return array The product media gallery value
383
     */
384
    public function loadProductMediaGalleryValue($valueId, $storeId, $entityId)
385
    {
386
        return $this->getProductMediaGalleryValueRepository()->findOneByValueIdAndStoreIdAndEntityId($valueId, $storeId, $entityId);
387
    }
388
389
    /**
390
     * Load's the product media gallery entities with the passed SKU.
391
     *
392
     * @param string $sku The SKU to load the media gallery entities for
393
     *
394
     * @return array The product media gallery entities
395
     */
396
    public function getProductMediaGalleriesBySku($sku)
397
    {
398
        return $this->getProductMediaGalleryRepository()->findAllBySku($sku);
399
    }
400
401
    /**
402
     * Persist's the passed product media gallery data and return's the ID.
403
     *
404
     * @param array       $productMediaGallery The product media gallery data to persist
405
     * @param string|null $name                The name of the prepared statement that has to be executed
406
     *
407
     * @return string The ID of the persisted entity
408
     */
409
    public function persistProductMediaGallery($productMediaGallery, $name = null)
410
    {
411
        return $this->getProductMediaGalleryAction()->persist($productMediaGallery, $name);
412
    }
413
414
    /**
415
     * Persist's the passed product media gallery value data.
416
     *
417
     * @param array       $productMediaGalleryValue The product media gallery value data to persist
418
     * @param string|null $name                     The name of the prepared statement that has to be executed
419
     *
420
     * @return void
421
     */
422
    public function persistProductMediaGalleryValue($productMediaGalleryValue, $name = null)
423
    {
424
        $this->getProductMediaGalleryValueAction()->persist($productMediaGalleryValue, $name);
425
    }
426
427
    /**
428
     * Persist's the passed product media gallery value to entity data.
429
     *
430
     * @param array       $productMediaGalleryValuetoEntity The product media gallery value to entity data to persist
431
     * @param string|null $name                             The name of the prepared statement that has to be executed
432
     *
433
     * @return void
434
     */
435
    public function persistProductMediaGalleryValueToEntity($productMediaGalleryValuetoEntity, $name = null)
436
    {
437
        $this->getProductMediaGalleryValueToEntityAction()->persist($productMediaGalleryValuetoEntity, $name);
438
    }
439
440
    /**
441
     * Persist's the passed product media gallery value video data.
442
     *
443
     * @param array       $productMediaGalleryValueVideo The product media gallery value video data to persist
444
     * @param string|null $name                          The name of the prepared statement that has to be executed
445
     *
446
     * @return void
447
     */
448
    public function persistProductMediaGalleryValueVideo($productMediaGalleryValueVideo, $name = null)
449
    {
450
        $this->getProductMediaGalleryValueVideoAction()->persist($productMediaGalleryValueVideo, $name);
451
    }
452
453
    /**
454
     * Delete's the passed product media gallery data.
455
     *
456
     * @param array       $row  The product media gallery data to be deleted
457
     * @param string|null $name The name of the prepared statement that has to be executed
458
     *
459
     * @return string The ID of the persisted entity
460
     */
461
    public function deleteProductMediaGallery(array $row, $name = null)
462
    {
463
        return $this->getProductMediaGalleryAction()->delete($row, $name);
464
    }
465
}
466