Completed
Push — master ( c81eb6...40934a )
by Tim
10s
created

ImportProcessor::getDefaultStore()   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
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Services\ImportProcessor
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Services;
22
23
/**
24
 * Processor implementation to load global data.
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
30
 * @link      http://www.techdivision.com
31
 */
32
class ImportProcessor implements ImportProcessorInterface
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 categories.
44
     *
45
     * @var \TechDivision\Import\Repositories\CategoryRepository
46
     */
47
    protected $categoryRepository;
48
49
    /**
50
     * The repository to access category varchar values.
51
     *
52
     * @var \TechDivision\Import\Repositories\CategoryVarcharRepository
53
     */
54
    protected $categoryVarcharRepository;
55
56
    /**
57
     * The repository to access EAV attributes.
58
     *
59
     * @var \TechDivision\Import\Repositories\EavAttributeRepository
60
     */
61
    protected $eavAttributeRepository;
62
63
    /**
64
     * The repository to access EAV attribute set.
65
     *
66
     * @var \TechDivision\Import\Repositories\EavAttributeSetRepository
67
     */
68
    protected $eavAttributeSetRepository;
69
70
    /**
71
     * The repository to access stores.
72
     *
73
     * @var \TechDivision\Import\Repositories\StoreRepository
74
     */
75
    protected $storeRepository;
76
77
    /**
78
     * The repository to access store websites.
79
     *
80
     * @var \TechDivision\Import\Repositories\StoreWebsiteRepository
81
     */
82
    protected $storeWebsiteRepository;
83
84
    /**
85
     * The repository to access tax classes.
86
     *
87
     * @var \TechDivision\Import\Repositories\TaxClassRepository
88
     */
89
    protected $taxClassRepository;
90
91
    /**
92
     * The repository to access link types.
93
     *
94
     * @var \TechDivision\Import\Repositories\LinkTypeRepository
95
     */
96
    protected $linkTypeRepository;
97
98
    /**
99
     * The repository to access link attributes.
100
     *
101
     * @var \TechDivision\Import\Repositories\LinkAttributeRepository
102
     */
103
    protected $linkAttributeRepository;
104
105
    /**
106
     * The repository to access the configuration.
107
     *
108
     * @var \TechDivision\Import\Repositories\CoreConfigDataRepository
109
     */
110
    protected $coreConfigDataRepository;
111
112
    /**
113
     * Set's the passed connection.
114
     *
115
     * @param \PDO $connection The connection to set
116
     *
117
     * @return void
118
     */
119
    public function setConnection(\PDO $connection)
120
    {
121
        $this->connection = $connection;
122
    }
123
124
    /**
125
     * Return's the connection.
126
     *
127
     * @return \PDO The connection instance
128
     */
129
    public function getConnection()
130
    {
131
        return $this->connection;
132
    }
133
134
    /**
135
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
136
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
137
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
138
     * to autocommit mode.
139
     *
140
     * @return boolean Returns TRUE on success or FALSE on failure
141
     * @link http://php.net/manual/en/pdo.begintransaction.php
142
     */
143
    public function beginTransaction()
144
    {
145
        return $this->connection->beginTransaction();
146
    }
147
148
    /**
149
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
150
     * ProductProcessor::beginTransaction() starts a new transaction.
151
     *
152
     * @return boolean Returns TRUE on success or FALSE on failure
153
     * @link http://php.net/manual/en/pdo.commit.php
154
     */
155
    public function commit()
156
    {
157
        return $this->connection->commit();
158
    }
159
160
    /**
161
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
162
     *
163
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
164
     * rolled back the transaction.
165
     *
166
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
167
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
168
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
169
     *
170
     * @return boolean Returns TRUE on success or FALSE on failure
171
     * @link http://php.net/manual/en/pdo.rollback.php
172
     */
173
    public function rollBack()
174
    {
175
        return $this->connection->rollBack();
176
    }
177
178
    /**
179
     * Set's the repository to access categories.
180
     *
181
     * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories
182
     *
183
     * @return void
184
     */
185
    public function setCategoryRepository($categoryRepository)
186
    {
187
        $this->categoryRepository = $categoryRepository;
188
    }
189
190
    /**
191
     * Return's the repository to access categories.
192
     *
193
     * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance
194
     */
195
    public function getCategoryRepository()
196
    {
197
        return $this->categoryRepository;
198
    }
199
200
    /**
201
     * Return's the repository to access category varchar values.
202
     *
203
     * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance
204
     *
205
     * @return void
206
     */
207
    public function setCategoryVarcharRepository($categoryVarcharRepository)
208
    {
209
        $this->categoryVarcharRepository = $categoryVarcharRepository;
210
    }
211
212
    /**
213
     * Return's the repository to access category varchar values.
214
     *
215
     * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance
216
     */
217
    public function getCategoryVarcharRepository()
218
    {
219
        return $this->categoryVarcharRepository;
220
    }
221
222
    /**
223
     * Set's the repository to access EAV attributes.
224
     *
225
     * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes
226
     *
227
     * @return void
228
     */
229
    public function setEavAttributeRepository($eavAttributeRepository)
230
    {
231
        $this->eavAttributeRepository = $eavAttributeRepository;
232
    }
233
234
    /**
235
     * Return's the repository to access EAV attributes.
236
     *
237
     * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance
238
     */
239
    public function getEavAttributeRepository()
240
    {
241
        return $this->eavAttributeRepository;
242
    }
243
244
    /**
245
     * Set's the repository to access EAV attribute sets.
246
     *
247
     * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets
248
     *
249
     * @return void
250
     */
251
    public function setEavAttributeSetRepository($eavAttributeSetRepository)
252
    {
253
        $this->eavAttributeSetRepository = $eavAttributeSetRepository;
254
    }
255
256
    /**
257
     * Return's the repository to access EAV attribute sets.
258
     *
259
     * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance
260
     */
261
    public function getEavAttributeSetRepository()
262
    {
263
        return $this->eavAttributeSetRepository;
264
    }
265
266
    /**
267
     * Set's the repository to access stores.
268
     *
269
     * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores
270
     *
271
     * @return void
272
     */
273
    public function setStoreRepository($storeRepository)
274
    {
275
        $this->storeRepository = $storeRepository;
276
    }
277
278
    /**
279
     * Return's the repository to access stores.
280
     *
281
     * @return \TechDivision\Import\Repositories\StoreRepository The repository instance
282
     */
283
    public function getStoreRepository()
284
    {
285
        return $this->storeRepository;
286
    }
287
288
    /**
289
     * Set's the repository to access store websites.
290
     *
291
     * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites
292
     *
293
     * @return void
294
     */
295
    public function setStoreWebsiteRepository($storeWebsiteRepository)
296
    {
297
        $this->storeWebsiteRepository = $storeWebsiteRepository;
298
    }
299
300
    /**
301
     * Return's the repository to access store websites.
302
     *
303
     * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance
304
     */
305
    public function getStoreWebsiteRepository()
306
    {
307
        return $this->storeWebsiteRepository;
308
    }
309
310
    /**
311
     * Set's the repository to access tax classes.
312
     *
313
     * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores
314
     *
315
     * @return void
316
     */
317
    public function setTaxClassRepository($taxClassRepository)
318
    {
319
        $this->taxClassRepository = $taxClassRepository;
320
    }
321
322
    /**
323
     * Return's the repository to access tax classes.
324
     *
325
     * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance
326
     */
327
    public function getTaxClassRepository()
328
    {
329
        return $this->taxClassRepository;
330
    }
331
332
    /**
333
     * Set's the repository to access link types.
334
     *
335
     * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types
336
     *
337
     * @return void
338
     */
339
    public function setLinkTypeRepository($linkTypeRepository)
340
    {
341
        $this->linkTypeRepository = $linkTypeRepository;
342
    }
343
344
    /**
345
     * Return's the repository to access link types.
346
     *
347
     * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance
348
     */
349
    public function getLinkTypeRepository()
350
    {
351
        return $this->linkTypeRepository;
352
    }
353
354
    /**
355
     * Set's the repository to access link attributes.
356
     *
357
     * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkAttributeRepository The repository to access link attributes
358
     *
359
     * @return void
360
     */
361
    public function setLinkAttributeRepository($linkAttributeRepository)
362
    {
363
        $this->linkAttributeRepository = $linkAttributeRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $linkAttributeRepository of type object<TechDivision\Impo...ies\LinkTypeRepository> is incompatible with the declared type object<TechDivision\Impo...inkAttributeRepository> of property $linkAttributeRepository.

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..

Loading history...
364
    }
365
366
    /**
367
     * Return's the repository to access link attributes.
368
     *
369
     * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance
370
     */
371
    public function getLinkAttributeRepository()
372
    {
373
        return $this->linkAttributeRepository;
374
    }
375
376
    /**
377
     * Set's the repository to access the Magento 2 configuration.
378
     *
379
     * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the Magento 2 configuration
380
     *
381
     * @return void
382
     */
383
    public function setCoreConfigDataRepository($coreConfigDataRepository)
384
    {
385
        $this->coreConfigDataRepository = $coreConfigDataRepository;
386
    }
387
388
    /**
389
     * Return's the repository to access the Magento 2 configuration.
390
     *
391
     * @return \TechDivision\Import\Repositories\CoreConfigDataRepository The repository instance
392
     */
393
    public function getCoreConfigDataRepository()
394
    {
395
        return $this->coreConfigDataRepository;
396
    }
397
398
    /**
399
     * Return's the EAV attribute set with the passed ID.
400
     *
401
     * @param integer $id The ID of the EAV attribute set to load
402
     *
403
     * @return array The EAV attribute set
404
     */
405
    public function getEavAttributeSet($id)
406
    {
407
        return $this->getEavAttributeSetRepository()->load($id);
408
    }
409
410
    /**
411
     * Return's the attribute sets for the passed entity type ID.
412
     *
413
     * @param mixed $entityTypeId The entity type ID to return the attribute sets for
414
     *
415
     * @return array|boolean The attribute sets for the passed entity type ID
416
     */
417
    public function getEavAttributeSetsByEntityTypeId($entityTypeId)
418
    {
419
        return $this->getEavAttributeSetRepository()->findAllByEntityTypeId($entityTypeId);
420
    }
421
422
    /**
423
     * Return's an array with the EAV attributes for the passed entity type ID and attribute set name.
424
     *
425
     * @param integer $entityTypeId     The entity type ID of the EAV attributes to return
426
     * @param string  $attributeSetName The attribute set name of the EAV attributes to return
427
     *
428
     * @return array The
429
     */
430
    public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
431
    {
432
        return $this->getEavAttributeRepository()->findAllByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName);
433
    }
434
435
    /**
436
     * Return's an array with the available EAV attributes for the passed option value and store ID.
437
     *
438
     * @param string $optionValue The option value of the EAV attributes
439
     * @param string $storeId     The store ID of the EAV attribues
440
     *
441
     * @return array The array with all available EAV attributes
442
     */
443
    public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId)
444
    {
445
        return $this->getEavAttributeRepository()->findAllByOptionValueAndStoreId($optionValue, $storeId);
446
    }
447
448
    /**
449
     * Return's the first EAV attribute for the passed option value and store ID.
450
     *
451
     * @param string $optionValue The option value of the EAV attributes
452
     * @param string $storeId     The store ID of the EAV attribues
453
     *
454
     * @return array The array with the EAV attribute
455
     */
456
    public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId)
457
    {
458
        return $this->getEavAttributeRepository()->findOneByOptionValueAndStoreId($optionValue, $storeId);
459
    }
460
461
    /**
462
     * Return's an array with the available stores.
463
     *
464
     * @return array The array with the available stores
465
     */
466
    public function getStores()
467
    {
468
        return $this->getStoreRepository()->findAll();
469
    }
470
471
    /**
472
     * Return's the default store.
473
     *
474
     * @return array The default store
475
     */
476
    public function getDefaultStore()
477
    {
478
        return $this->getStoreRepository()->findOneByDefault();
479
    }
480
481
    /**
482
     * Return's an array with the available store websites.
483
     *
484
     * @return array The array with the available store websites
485
     */
486
    public function getStoreWebsites()
487
    {
488
        return $this->getStoreWebsiteRepository()->findAll();
489
    }
490
491
    /**
492
     * Return's an array with the available tax classes.
493
     *
494
     * @return array The array with the available tax classes
495
     */
496
    public function getTaxClasses()
497
    {
498
        return $this->getTaxClassRepository()->findAll();
499
    }
500
501
    /**
502
     * Return's an array with all available categories.
503
     *
504
     * @return array The available categories
505
     */
506
    public function getCategories()
507
    {
508
        return $this->getCategoryRepository()->findAll();
509
    }
510
511
    /**
512
     * Return's an array with the root categories with the store code as key.
513
     *
514
     * @return array The root categories
515
     */
516
    public function getRootCategories()
517
    {
518
        return $this->getCategoryRepository()->findAllRootCategories();
519
    }
520
521
    /**
522
     * Returns the category varchar values for the categories with
523
     * the passed with the passed entity IDs.
524
     *
525
     * @param array $entityIds The array with the category IDs
526
     *
527
     * @return mixed The category varchar values
528
     */
529
    public function getCategoryVarcharsByEntityIds(array $entityIds)
530
    {
531
        return $this->getCategoryVarcharRepository()->findAllByEntityIds($entityIds);
532
    }
533
534
    /**
535
     * Return's an array with all available link types.
536
     *
537
     * @return array The available link types
538
     */
539
    public function getLinkTypes()
540
    {
541
        return $this->getLinkTypeRepository()->findAll();
542
    }
543
544
    /**
545
     * Return's an array with all available link attributes.
546
     *
547
     * @return array The available link attributes
548
     */
549
    public function getLinkAttributes()
550
    {
551
        return $this->getLinkAttributeRepository()->findAll();
552
    }
553
554
    /**
555
     * Return's an array with the Magento 2 configuration.
556
     *
557
     * @return array The Magento 2 configuration
558
     */
559
    public function getCoreConfigData()
560
    {
561
        return $this->getCoreConfigDataRepository()->findAll();
562
    }
563
}
564