Completed
Push — master ( bce332...18fde1 )
by Tim
9s
created

ProductBunchProcessor::getConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Services\ProductBunchProcessor
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Services;
22
23
/**
24
 * The product bunch processor implementation.
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
30
 * @link      http://www.techdivision.com
31
 */
32
class ProductBunchProcessor implements ProductBunchProcessorInterface
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 access EAV attribute option values.
44
     *
45
     * @var \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository
46
     */
47
    protected $eavAttributeOptionValueRepository;
48
49
    /**
50
     * The action for product CRUD methods.
51
     *
52
     * @var \TechDivision\Import\Product\Actions\ProductAction
53
     */
54
    protected $productAction;
55
56
    /**
57
     * The action for product varchar attribute CRUD methods.
58
     *
59
     * @var \TechDivision\Import\Product\Actions\ProductVarcharAction
60
     */
61
    protected $productVarcharAction;
62
63
    /**
64
     * The action for product text attribute CRUD methods.
65
     *
66
     * @var \TechDivision\Import\Product\Actions\ProductTextAction
67
     */
68
    protected $productTextAction;
69
70
    /**
71
     * The action for product int attribute CRUD methods.
72
     *
73
     * @var \TechDivision\Import\Product\Actions\ProductIntAction
74
     */
75
    protected $productIntAction;
76
77
    /**
78
     * The action for product decimal attribute CRUD methods.
79
     *
80
     * @var \TechDivision\Import\Product\Actions\ProductDecimalAction
81
     */
82
    protected $productDecimalAction;
83
84
    /**
85
     * The action for product datetime attribute CRUD methods.
86
     *
87
     * @var \TechDivision\Import\Product\Actions\ProductDatetimeAction
88
     */
89
    protected $productDatetimeAction;
90
91
    /**
92
     * The action for product website CRUD methods.
93
     *
94
     * @var \TechDivision\Import\Product\Actions\ProductWebsiteAction
95
     */
96
    protected $productWebsiteAction;
97
98
    /**
99
     * The action for product category CRUD methods.
100
     *
101
     * @var \TechDivision\Import\Product\Actions\ProductCategoryAction
102
     */
103
    protected $productCategoryAction;
104
105
    /**
106
     * The action for stock item CRUD methods.
107
     *
108
     * @var \TechDivision\Import\Product\Actions\StockItemAction
109
     */
110
    protected $stockItemAction;
111
112
    /**
113
     * The action for stock status CRUD methods.
114
     *
115
     * @var \TechDivision\Import\Product\Actions\StockStatusAction
116
     */
117
    protected $stockStatusAction;
118
119
    /**
120
     * The action for URL rewrite CRUD methods.
121
     *
122
     * @var \TechDivision\Import\Product\Actions\UrlRewriteAction
123
     */
124
    protected $urlRewriteAction;
125
126
    /**
127
     * The repository to load the URL rewrites with.
128
     *
129
     * @var \TechDivision\Import\Product\Repositories\UrlRewriteRepository
130
     */
131
    protected $urlRewriteRepository;
132
133
    /**
134
     * Set's the passed connection.
135
     *
136
     * @param \PDO $connection The connection to set
137
     *
138
     * @return void
139
     */
140
    public function setConnection(\PDO $connection)
141
    {
142
        $this->connection = $connection;
143
    }
144
145
    /**
146
     * Return's the connection.
147
     *
148
     * @return \PDO The connection instance
149
     */
150
    public function getConnection()
151
    {
152
        return $this->connection;
153
    }
154
155
    /**
156
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
157
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
158
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
159
     * to autocommit mode.
160
     *
161
     * @return boolean Returns TRUE on success or FALSE on failure
162
     * @link http://php.net/manual/en/pdo.begintransaction.php
163
     */
164
    public function beginTransaction()
165
    {
166
        return $this->connection->beginTransaction();
167
    }
168
169
    /**
170
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
171
     * ProductProcessor::beginTransaction() starts a new transaction.
172
     *
173
     * @return boolean Returns TRUE on success or FALSE on failure
174
     * @link http://php.net/manual/en/pdo.commit.php
175
     */
176
    public function commit()
177
    {
178
        return $this->connection->commit();
179
    }
180
181
    /**
182
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
183
     *
184
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
185
     * rolled back the transaction.
186
     *
187
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
188
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
189
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
190
     *
191
     * @return boolean Returns TRUE on success or FALSE on failure
192
     * @link http://php.net/manual/en/pdo.rollback.php
193
     */
194
    public function rollBack()
195
    {
196
        return $this->connection->rollBack();
197
    }
198
199
    /**
200
     * Set's the repository to access EAV attribute option values.
201
     *
202
     * @param \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository $eavAttributeOptionValueRepository The repository to access EAV attribute option values
203
     *
204
     * @return void
205
     */
206
    public function setEavAttributeOptionValueRepository($eavAttributeOptionValueRepository)
207
    {
208
        $this->eavAttributeOptionValueRepository = $eavAttributeOptionValueRepository;
209
    }
210
211
    /**
212
     * Return's the repository to access EAV attribute option values.
213
     *
214
     * @return \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository The repository instance
215
     */
216
    public function getEavAttributeOptionValueRepository()
217
    {
218
        return $this->eavAttributeOptionValueRepository;
219
    }
220
221
    /**
222
     * Set's the action with the product CRUD methods.
223
     *
224
     * @param \TechDivision\Import\Product\Actions\ProductAction $productAction The action with the product CRUD methods
225
     *
226
     * @return void
227
     */
228
    public function setProductAction($productAction)
229
    {
230
        $this->productAction = $productAction;
231
    }
232
233
    /**
234
     * Return's the action with the product CRUD methods.
235
     *
236
     * @return \TechDivision\Import\Product\Actions\ProductAction The action instance
237
     */
238
    public function getProductAction()
239
    {
240
        return $this->productAction;
241
    }
242
243
    /**
244
     * Set's the action with the product varchar attribute CRUD methods.
245
     *
246
     * @param \TechDivision\Import\Product\Actions\ProductVarcharAction $productVarcharAction The action with the product varchar attriute CRUD methods
247
     *
248
     * @return void
249
     */
250
    public function setProductVarcharAction($productVarcharAction)
251
    {
252
        $this->productVarcharAction = $productVarcharAction;
253
    }
254
255
    /**
256
     * Return's the action with the product varchar attribute CRUD methods.
257
     *
258
     * @return \TechDivision\Import\Product\Actions\ProductVarcharAction The action instance
259
     */
260
    public function getProductVarcharAction()
261
    {
262
        return $this->productVarcharAction;
263
    }
264
265
    /**
266
     * Set's the action with the product text attribute CRUD methods.
267
     *
268
     * @param \TechDivision\Import\Product\Actions\ProductTextAction $productTextAction The action with the product text attriute CRUD methods
269
     *
270
     * @return void
271
     */
272
    public function setProductTextAction($productTextAction)
273
    {
274
        $this->productTextAction = $productTextAction;
275
    }
276
277
    /**
278
     * Return's the action with the product text attribute CRUD methods.
279
     *
280
     * @return \TechDivision\Import\Product\Actions\ProductTextAction The action instance
281
     */
282
    public function getProductTextAction()
283
    {
284
        return $this->productTextAction;
285
    }
286
287
    /**
288
     * Set's the action with the product int attribute CRUD methods.
289
     *
290
     * @param \TechDivision\Import\Product\Actions\ProductIntAction $productIntAction The action with the product int attriute CRUD methods
291
     *
292
     * @return void
293
     */
294
    public function setProductIntAction($productIntAction)
295
    {
296
        $this->productIntAction = $productIntAction;
297
    }
298
299
    /**
300
     * Return's the action with the product int attribute CRUD methods.
301
     *
302
     * @return \TechDivision\Import\Product\Actions\ProductIntAction The action instance
303
     */
304
    public function getProductIntAction()
305
    {
306
        return $this->productIntAction;
307
    }
308
309
    /**
310
     * Set's the action with the product decimal attribute CRUD methods.
311
     *
312
     * @param \TechDivision\Import\Product\Actions\ProductDecimalAction $productDecimalAction The action with the product decimal attriute CRUD methods
313
     *
314
     * @return void
315
     */
316
    public function setProductDecimalAction($productDecimalAction)
317
    {
318
        $this->productDecimalAction = $productDecimalAction;
319
    }
320
321
    /**
322
     * Return's the action with the product decimal attribute CRUD methods.
323
     *
324
     * @return \TechDivision\Import\Product\Actions\ProductDecimalAction The action instance
325
     */
326
    public function getProductDecimalAction()
327
    {
328
        return $this->productDecimalAction;
329
    }
330
331
    /**
332
     * Set's the action with the product datetime attribute CRUD methods.
333
     *
334
     * @param \TechDivision\Import\Product\Actions\ProductDatetimeAction $productDatetimeAction The action with the product datetime attriute CRUD methods
335
     *
336
     * @return void
337
     */
338
    public function setProductDatetimeAction($productDatetimeAction)
339
    {
340
        $this->productDatetimeAction = $productDatetimeAction;
341
    }
342
343
    /**
344
     * Return's the action with the product datetime attribute CRUD methods.
345
     *
346
     * @return \TechDivision\Import\Product\Actions\ProductDatetimeAction The action instance
347
     */
348
    public function getProductDatetimeAction()
349
    {
350
        return $this->productDatetimeAction;
351
    }
352
353
    /**
354
     * Set's the action with the product website CRUD methods.
355
     *
356
     * @param \TechDivision\Import\Product\Actions\ProductWebsiteAction $productWebsiteAction The action with the product website CRUD methods
357
     *
358
     * @return void
359
     */
360
    public function setProductWebsiteAction($productWebsiteAction)
361
    {
362
        $this->productWebsiteAction = $productWebsiteAction;
363
    }
364
365
    /**
366
     * Return's the action with the product website CRUD methods.
367
     *
368
     * @return \TechDivision\Import\Product\Actions\ProductWebsiteAction The action instance
369
     */
370
    public function getProductWebsiteAction()
371
    {
372
        return $this->productWebsiteAction;
373
    }
374
375
    /**
376
     * Set's the action with the product category CRUD methods.
377
     *
378
     * @param \TechDivision\Import\Product\Actions\ProductCategoryAction $productCategoryAction The action with the product category CRUD methods
379
     *
380
     * @return void
381
     */
382
    public function setProductCategoryAction($productCategoryAction)
383
    {
384
        $this->productCategoryAction = $productCategoryAction;
385
    }
386
387
    /**
388
     * Return's the action with the product category CRUD methods.
389
     *
390
     * @return \TechDivision\Import\Product\Actions\ProductCategoryAction The action instance
391
     */
392
    public function getProductCategoryAction()
393
    {
394
        return $this->productCategoryAction;
395
    }
396
397
    /**
398
     * Set's the action with the stock item CRUD methods.
399
     *
400
     * @param \TechDivision\Import\Product\Actions\StockItemAction $stockItemAction The action with the stock item CRUD methods
401
     *
402
     * @return void
403
     */
404
    public function setStockItemAction($stockItemAction)
405
    {
406
        $this->stockItemAction = $stockItemAction;
407
    }
408
409
    /**
410
     * Return's the action with the stock item CRUD methods.
411
     *
412
     * @return \TechDivision\Import\Product\Actions\StockItemAction The action instance
413
     */
414
    public function getStockItemAction()
415
    {
416
        return $this->stockItemAction;
417
    }
418
419
    /**
420
     * Set's the action with the stock status CRUD methods.
421
     *
422
     * @param \TechDivision\Import\Product\Actions\StockStatusAction $stockStatusAction The action with the stock status CRUD methods
423
     *
424
     * @return void
425
     */
426
    public function setStockStatusAction($stockStatusAction)
427
    {
428
        $this->stockStatusAction = $stockStatusAction;
429
    }
430
431
    /**
432
     * Return's the action with the stock status CRUD methods.
433
     *
434
     * @return \TechDivision\Import\Product\Actions\StockStatusAction The action instance
435
     */
436
    public function getStockStatusAction()
437
    {
438
        return $this->stockStatusAction;
439
    }
440
441
    /**
442
     * Set's the action with the URL rewrite CRUD methods.
443
     *
444
     * @param \TechDivision\Import\Product\Actions\UrlRewriteAction $urlRewriteAction The action with the URL rewrite CRUD methods
445
     *
446
     * @return void
447
     */
448
    public function setUrlRewriteAction($urlRewriteAction)
449
    {
450
        $this->urlRewriteAction = $urlRewriteAction;
451
    }
452
453
    /**
454
     * Return's the action with the stock status CRUD methods.
455
     *
456
     * @return \TechDivision\Import\Product\Actions\UrlRewriteAction The action instance
457
     */
458
    public function getUrlRewriteAction()
459
    {
460
        return $this->urlRewriteAction;
461
    }
462
463
    /**
464
     * Set's the repository to load the URL rewrites with.
465
     *
466
     * @param \TechDivision\Import\Product\Repositories\UrlRewriteRepository $urlRewriteRepository The repository instance
467
     *
468
     * @return void
469
     */
470
    public function setUrlRewriteRepository($urlRewriteRepository)
471
    {
472
        $this->urlRewriteRepository = $urlRewriteRepository;
473
    }
474
475
    /**
476
     * Return's the repository to load the URL rewrites with.
477
     *
478
     * @return \TechDivision\Import\Product\Repositories\UrlRewriteRepository The repository instance
479
     */
480
    public function getUrlRewriteRepository()
481
    {
482
        return $this->urlRewriteRepository;
483
    }
484
485
    /**
486
     * Return's the attribute option value with the passed value and store ID.
487
     *
488
     * @param mixed   $value   The option value
489
     * @param integer $storeId The ID of the store
490
     *
491
     * @return array|boolean The attribute option value instance
492
     */
493
    public function getEavAttributeOptionValueByOptionValueAndStoreId($value, $storeId)
494
    {
495
        return $this->getEavAttributeOptionValueRepository()->findEavAttributeOptionValueByOptionValueAndStoreId($value, $storeId);
496
    }
497
498
    /**
499
     * Return's the URL rewrites for the passed URL entity type and ID.
500
     *
501
     * @param string  $entityType The entity type to load the URL rewrites for
502
     * @param integer $entityId   The entity ID to laod the rewrites for
503
     *
504
     * @return array The URL rewrites
505
     */
506
    public function getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId)
507
    {
508
        return $this->getUrlRewriteRepository()->findAllByEntityTypeAndEntityId($entityType, $entityId);
509
    }
510
511
    /**
512
     * Persist's the passed product data and return's the ID.
513
     *
514
     * @param array       $product The product data to persist
515
     * @param string|null $name    The name of the prepared statement that has to be executed
516
     *
517
     * @return string The ID of the persisted entity
518
     */
519
    public function persistProduct($product, $name = null)
520
    {
521
        return $this->getProductAction()->persist($product, $name);
522
    }
523
524
    /**
525
     * Persist's the passed product varchar attribute.
526
     *
527
     * @param array       $attribute The attribute to persist
528
     * @param string|null $name      The name of the prepared statement that has to be executed
529
     *
530
     * @return void
531
     */
532
    public function persistProductVarcharAttribute($attribute, $name = null)
533
    {
534
        $this->getProductVarcharAction()->persist($attribute, $name);
535
    }
536
537
    /**
538
     * Persist's the passed product integer attribute.
539
     *
540
     * @param array       $attribute The attribute to persist
541
     * @param string|null $name      The name of the prepared statement that has to be executed
542
     *
543
     * @return void
544
     */
545
    public function persistProductIntAttribute($attribute, $name = null)
546
    {
547
        $this->getProductIntAction()->persist($attribute, $name);
548
    }
549
550
    /**
551
     * Persist's the passed product decimal attribute.
552
     *
553
     * @param array       $attribute The attribute to persist
554
     * @param string|null $name      The name of the prepared statement that has to be executed
555
     *
556
     * @return void
557
     */
558
    public function persistProductDecimalAttribute($attribute, $name = null)
559
    {
560
        $this->getProductDecimalAction()->persist($attribute, $name);
561
    }
562
563
    /**
564
     * Persist's the passed product datetime attribute.
565
     *
566
     * @param array       $attribute The attribute to persist
567
     * @param string|null $name      The name of the prepared statement that has to be executed
568
     *
569
     * @return void
570
     */
571
    public function persistProductDatetimeAttribute($attribute, $name = null)
572
    {
573
        $this->getProductDatetimeAction()->persist($attribute, $name);
574
    }
575
576
    /**
577
     * Persist's the passed product text attribute.
578
     *
579
     * @param array       $attribute The attribute to persist
580
     * @param string|null $name      The name of the prepared statement that has to be executed
581
     *
582
     * @return void
583
     */
584
    public function persistProductTextAttribute($attribute, $name = null)
585
    {
586
        $this->getProductTextAction()->persist($attribute, $name);
587
    }
588
589
    /**
590
     * Persist's the passed product website data and return's the ID.
591
     *
592
     * @param array       $productWebsite The product website data to persist
593
     * @param string|null $name           The name of the prepared statement that has to be executed
594
     *
595
     * @return void
596
     */
597
    public function persistProductWebsite($productWebsite, $name = null)
598
    {
599
        $this->getProductWebsiteAction()->persist($productWebsite, $name);
600
    }
601
602
    /**
603
     * Persist's the passed product category data and return's the ID.
604
     *
605
     * @param array       $productCategory The product category data to persist
606
     * @param string|null $name            The name of the prepared statement that has to be executed
607
     *
608
     * @return void
609
     */
610
    public function persistProductCategory($productCategory, $name = null)
611
    {
612
        $this->getProductCategoryAction()->persist($productCategory, $name);
613
    }
614
615
    /**
616
     * Persist's the passed stock item data and return's the ID.
617
     *
618
     * @param array       $stockItem The stock item data to persist
619
     * @param string|null $name      The name of the prepared statement that has to be executed
620
     *
621
     * @return void
622
     */
623
    public function persistStockItem($stockItem, $name = null)
624
    {
625
        $this->getStockItemAction()->persist($stockItem, $name);
626
    }
627
628
    /**
629
     * Persist's the passed stock status data and return's the ID.
630
     *
631
     * @param array       $stockStatus The stock status data to persist
632
     * @param string|null $name        The name of the prepared statement that has to be executed
633
     *
634
     * @return void
635
     */
636
    public function persistStockStatus($stockStatus, $name = null)
637
    {
638
        $this->getStockStatusAction()->persist($stockStatus, $name);
639
    }
640
641
    /**
642
     * Persist's the URL write with the passed data.
643
     *
644
     * @param array       $row  The URL rewrite to persist
645
     * @param string|null $name The name of the prepared statement that has to be executed
646
     *
647
     * @return void
648
     */
649
    public function persistUrlRewrite($row, $name = null)
650
    {
651
        $this->getUrlRewriteAction()->persist($row, $name);
652
    }
653
654
    /**
655
     * Remove's the entity with the passed attributes.
656
     *
657
     * @param array       $row  The attributes of the entity to remove
658
     * @param string|null $name The name of the prepared statement that has to be executed
659
     *
660
     * @return void
661
     */
662
    public function removeProduct($row, $name = null)
663
    {
664
        $this->getProductAction()->remove($row, $name);
665
    }
666
667
    /**
668
     * Delete's the URL rewrite with the passed attributes.
669
     *
670
     * @param array       $row  The attributes of the entity to remove
671
     * @param string|null $name The name of the prepared statement that has to be executed
672
     *
673
     * @return void
674
     */
675
    public function removeUrlRewrite($row, $name = null)
676
    {
677
        $this->getUrlRewriteAction()->remove($row, $name);
678
    }
679
680
    /**
681
     * Delete's the stock item(s) with the passed attributes.
682
     *
683
     * @param array       $row  The attributes of the entity to remove
684
     * @param string|null $name The name of the prepared statement that has to be executed
685
     *
686
     * @return void
687
     */
688
    public function removeStockItem($row, $name = null)
689
    {
690
        $this->getStockItemAction()->remove($row, $name);
691
    }
692
693
    /**
694
     * Delete's the stock status with the passed attributes.
695
     *
696
     * @param array       $row  The attributes of the entity to remove
697
     * @param string|null $name The name of the prepared statement that has to be executed
698
     *
699
     * @return void
700
     */
701
    public function removeStockStatus($row, $name = null)
702
    {
703
        $this->getStockStatusAction()->remove($row, $name);
704
    }
705
706
    /**
707
     * Delete's the product website relations with the passed attributes.
708
     *
709
     * @param array       $row  The attributes of the entity to remove
710
     * @param string|null $name The name of the prepared statement that has to be executed
711
     *
712
     * @return void
713
     */
714
    public function removeProductWebsite($row, $name = null)
715
    {
716
        $this->getProductWebsiteAction()->remove($row, $name);
717
    }
718
719
    /**
720
     * Delete's the product category relations with the passed attributes.
721
     *
722
     * @param array       $row  The attributes of the entity to remove
723
     * @param string|null $name The name of the prepared statement that has to be executed
724
     *
725
     * @return void
726
     */
727
    public function removeProductCategory($row, $name = null)
728
    {
729
        $this->getProductCategoryAction()->remove($row, $name);
730
    }
731
}
732