Completed
Push — 15.x ( 8474b2...5837a8 )
by Tim
01:31
created

Configuration::setSourceDateFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Configuration\Jms\Configuration
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-configuration-jms
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Configuration\Jms;
22
23
use Psr\Log\LogLevel;
24
use JMS\Serializer\Annotation\Type;
25
use JMS\Serializer\Annotation\Exclude;
26
use JMS\Serializer\Annotation\SerializedName;
27
use JMS\Serializer\Annotation\PostDeserialize;
28
use JMS\Serializer\Annotation\ExclusionPolicy;
29
use Doctrine\Common\Collections\ArrayCollection;
30
use TechDivision\Import\ConfigurationInterface;
31
use TechDivision\Import\Configuration\DatabaseConfigurationInterface;
32
use TechDivision\Import\Configuration\Jms\Configuration\Operation;
33
use TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait;
34
use TechDivision\Import\Configuration\Jms\Configuration\CsvTrait;
35
use TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait;
36
use TechDivision\Import\Configuration\ListenerAwareConfigurationInterface;
37
38
/**
39
 * A simple JMS based configuration implementation.
40
 *
41
 * @author    Tim Wagner <[email protected]>
42
 * @copyright 2016 TechDivision GmbH <[email protected]>
43
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
44
 * @link      https://github.com/techdivision/import-configuration-jms
45
 * @link      http://www.techdivision.com
46
 *
47
 * @ExclusionPolicy("none")
48
 */
49
class Configuration implements ConfigurationInterface, ListenerAwareConfigurationInterface
50
{
51
52
    /**
53
     * The default PID filename to use.
54
     *
55
     * @var string
56
     */
57
    const PID_FILENAME = 'importer.pid';
58
59
    /**
60
     * Trait that provides CSV configuration functionality.
61
     *
62
     * @var \TechDivision\Import\Configuration\Jms\Configuration\CsvTrait
63
     */
64
    use CsvTrait;
65
66
    /**
67
     * Trait that provides CSV configuration functionality.
68
     *
69
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait
70
     */
71
    use ParamsTrait;
72
73
    /**
74
     * Trait that provides CSV configuration functionality.
75
     *
76
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait
77
     */
78
    use ListenersTrait;
79
80
    /**
81
     * The array with the available database types.
82
     *
83
     * @var array
84
     * @Exclude
85
     */
86
    protected $availableDatabaseTypes = array(
87
        DatabaseConfigurationInterface::TYPE_MYSQL,
88
        DatabaseConfigurationInterface::TYPE_REDIS
89
    );
90
91
    /**
92
     * Mapping for boolean values passed on the console.
93
     *
94
     * @var array
95
     * @Exclude
96
     */
97
    protected $booleanMapping = array(
98
        'true'  => true,
99
        'false' => false,
100
        '1'     => true,
101
        '0'     => false,
102
        'on'    => true,
103
        'off'   => false
104
    );
105
106
    /**
107
     * The serial that will be passed as commandline option (can not be specified in configuration file).
108
     *
109
     * @var string
110
     * @Exclude
111
     */
112
    protected $serial;
113
114
    /**
115
     * The application's unique DI identifier.
116
     *
117
     * @var string
118
     * @Type("string")
119
     * @SerializedName("id")
120
     */
121
    protected $id;
122
123
    /**
124
     * The system name to use.
125
     *
126
     * @var string
127
     * @Type("string")
128
     * @SerializedName("system-name")
129
     */
130
    protected $systemName;
131
132
    /**
133
     * The operation name to use.
134
     *
135
     * @var string
136
     * @Type("string")
137
     * @SerializedName("operation-name")
138
     */
139
    protected $operationName;
140
141
    /**
142
     * The entity type code to use.
143
     *
144
     * @var string
145
     * @Type("string")
146
     * @SerializedName("entity-type-code")
147
     */
148
    protected $entityTypeCode;
149
150
    /**
151
     * The Magento installation directory.
152
     *
153
     * @var string
154
     * @Type("string")
155
     * @SerializedName("installation-dir")
156
     */
157
    protected $installationDir;
158
159
    /**
160
     * The source directory that has to be watched for new files.
161
     *
162
     * @var string
163
     * @Type("string")
164
     * @SerializedName("source-dir")
165
     */
166
    protected $sourceDir;
167
168
    /**
169
     * The target directory with the files that has been imported.
170
     *
171
     * @var string
172
     * @Type("string")
173
     * @SerializedName("target-dir")
174
     */
175
    protected $targetDir;
176
177
    /**
178
     * The Magento edition, EE or CE.
179
     *
180
     * @var string
181
     * @Type("string")
182
     * @SerializedName("magento-edition")
183
     */
184
    protected $magentoEdition = 'CE';
185
186
    /**
187
     * The Magento version, e. g. 2.1.0.
188
     *
189
     * @var string
190
     * @Type("string")
191
     * @SerializedName("magento-version")
192
     */
193
    protected $magentoVersion = '2.1.2';
194
195
    /**
196
     * ArrayCollection with the information of the configured databases.
197
     *
198
     * @var \Doctrine\Common\Collections\ArrayCollection
199
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Database>")
200
     */
201
    protected $databases;
202
203
    /**
204
     * ArrayCollection with the information of the configured loggers.
205
     *
206
     * @var \Doctrine\Common\Collections\ArrayCollection
207
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Logger>")
208
     */
209
    protected $loggers;
210
211
    /**
212
     * ArrayCollection with the information of the configured operations.
213
     *
214
     * @var \Doctrine\Common\Collections\ArrayCollection
215
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Operation>")
216
     */
217
    protected $operations;
218
219
    /**
220
     * The subject's multiple field delimiter character for fields with multiple values, defaults to (,).
221
     *
222
     * @var string
223
     * @Type("string")
224
     * @SerializedName("multiple-field-delimiter")
225
     */
226
    protected $multipleFieldDelimiter = ',';
227
228
    /**
229
     * The subject's multiple value delimiter character for fields with multiple values, defaults to (|).
230
     *
231
     * @var string
232
     * @Type("string")
233
     * @SerializedName("multiple-value-delimiter")
234
     */
235
    protected $multipleValueDelimiter = '|';
236
237
    /**
238
     * The flag to signal that the subject has to use the strict mode or not.
239
     *
240
     * @var boolean
241
     * @Type("boolean")
242
     * @SerializedName("strict-mode")
243
     */
244
    protected $strictMode;
245
246
    /**
247
     * The flag whether or not the import artefacts have to be archived.
248
     *
249
     * @var boolean
250
     * @Type("boolean")
251
     * @SerializedName("archive-artefacts")
252
     */
253
    protected $archiveArtefacts;
254
255
    /**
256
     * The directory where the archives will be stored.
257
     *
258
     * @var string
259
     * @Type("string")
260
     * @SerializedName("archive-dir")
261
     */
262
    protected $archiveDir;
263
264
    /**
265
     * The flag to signal that the subject has to use the debug mode or not.
266
     *
267
     * @var boolean
268
     * @Type("boolean")
269
     * @SerializedName("debug-mode")
270
     */
271
    protected $debugMode = false;
272
273
    /**
274
     * The log level to use (see Monolog documentation).
275
     *
276
     * @var string
277
     * @Type("string")
278
     * @SerializedName("log-level")
279
     */
280
    protected $logLevel = LogLevel::INFO;
281
282
    /**
283
     * The explicit DB ID to use.
284
     *
285
     * @var string
286
     * @Type("string")
287
     * @SerializedName("use-db-id")
288
     */
289
    protected $useDbId;
290
291
    /**
292
     * The explicit PID filename to use.
293
     *
294
     * @var string
295
     * @Type("string")
296
     * @SerializedName("pid-filename")
297
     */
298
    protected $pidFilename;
299
300
    /**
301
     * The collection with the paths to additional vendor directories.
302
     *
303
     * @var \Doctrine\Common\Collections\ArrayCollection
304
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\VendorDir>")
305
     * @SerializedName("additional-vendor-dirs")
306
     */
307
    protected $additionalVendorDirs;
308
309
    /**
310
     * The array with the Magento Edition specific extension libraries.
311
     *
312
     * @var array
313
     * @Type("array")
314
     * @SerializedName("extension-libraries")
315
     */
316
    protected $extensionLibraries = array();
317
318
    /**
319
     * The array with the custom header mappings.
320
     *
321
     * @var array
322
     * @Type("array")
323
     * @SerializedName("header-mappings")
324
     */
325
    protected $headerMappings = array();
326
327
    /**
328
     * The array with the custom image types.
329
     *
330
     * @var array
331
     * @Type("array")
332
     * @SerializedName("image-types")
333
     */
334
    protected $imageTypes = array();
335
336
    /**
337
     * The flag to signal that the import should be wrapped within a single transation or not.
338
     *
339
     * @var boolean
340
     * @Type("boolean")
341
     * @SerializedName("single-transaction")
342
     */
343
    protected $singleTransaction = false;
344
345
    /**
346
     * The flag to signal that the cache should be enabled or not.
347
     *
348
     * @var boolean
349
     * @Type("boolean")
350
     * @SerializedName("cache-enabled")
351
     */
352
    protected $cacheEnabled = true;
353
354
    /**
355
     * ArrayCollection with the information of the configured aliases.
356
     *
357
     * @var \Doctrine\Common\Collections\ArrayCollection
358
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Alias>")
359
     */
360
    protected $aliases;
361
362
    /**
363
     * ArrayCollection with the information of the configured caches.
364
     *
365
     * @var \Doctrine\Common\Collections\ArrayCollection
366
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Cache>")
367
     */
368
    protected $caches;
369
370
    /**
371
     * Return's the array with the plugins of the operation to use.
372
     *
373
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the plugins
374
     * @throws \Exception Is thrown, if no plugins are available for the actual operation
375
     */
376
    public function getPlugins()
377
    {
378
379
        // iterate over the operations and return the subjects of the actual one
380
        /** @var TechDivision\Import\Configuration\OperationInterface $operation */
381
        foreach ($this->getOperations() as $operation) {
382
            if ($this->getOperation()->equals($operation)) {
383
                return $operation->getPlugins();
384
            }
385
        }
386
387
        // throw an exception if no plugins are available
388
        throw new \Exception(sprintf('Can\'t find any plugins for operation %s', $this->getOperation()));
389
    }
390
391
    /**
392
     * Map's the passed value to a boolean.
393
     *
394
     * @param string $value The value to map
395
     *
396
     * @return boolean The mapped value
397
     * @throws \Exception Is thrown, if the value can't be mapped
398
     */
399
    public function mapBoolean($value)
400
    {
401
402
        // try to map the passed value to a boolean
403
        if (isset($this->booleanMapping[$val = strtolower($value)])) {
404
            return $this->booleanMapping[$val];
405
        }
406
407
        // throw an exception if we can't convert the passed value
408
        throw new \Exception(sprintf('Can\'t convert %s to boolean', $value));
409
    }
410
411
    /**
412
     * Return's the operation, initialize from the actual operation name.
413
     *
414
     * @return \TechDivision\Import\Configuration\OperationConfigurationInterface The operation instance
415
     */
416
    public function getOperation()
417
    {
418
        return new Operation($this->getOperationName());
419
    }
420
421
    /**
422
     * Return's the application's unique DI identifier.
423
     *
424
     * @return string The application's unique DI identifier
425
     */
426
    public function getId()
427
    {
428
        return $this->id;
429
    }
430
431
    /**
432
     * Return's the operation name that has to be used.
433
     *
434
     * @param string $operationName The operation name that has to be used
435
     *
436
     * @return void
437
     */
438
    public function setOperationName($operationName)
439
    {
440
        return $this->operationName = $operationName;
441
    }
442
443
    /**
444
     * Return's the operation name that has to be used.
445
     *
446
     * @return string The operation name that has to be used
447
     */
448
    public function getOperationName()
449
    {
450
        return $this->operationName;
451
    }
452
453
    /**
454
     * Set's the Magento installation directory.
455
     *
456
     * @param string $installationDir The Magento installation directory
457
     *
458
     * @return void
459
     */
460
    public function setInstallationDir($installationDir)
461
    {
462
        $this->installationDir = $installationDir;
463
    }
464
465
    /**
466
     * Return's the Magento installation directory.
467
     *
468
     * @return string The Magento installation directory
469
     */
470
    public function getInstallationDir()
471
    {
472
        return $this->installationDir;
473
    }
474
475
    /**
476
     * Set's the source directory that has to be watched for new files.
477
     *
478
     * @param string $sourceDir The source directory
479
     *
480
     * @return void
481
     */
482
    public function setSourceDir($sourceDir)
483
    {
484
        $this->sourceDir = $sourceDir;
485
    }
486
487
    /**
488
     * Return's the source directory that has to be watched for new files.
489
     *
490
     * @return string The source directory
491
     */
492
    public function getSourceDir()
493
    {
494
        return $this->sourceDir;
495
    }
496
497
    /**
498
     * Set's the target directory with the files that has been imported.
499
     *
500
     * @param string $targetDir The target directory
501
     *
502
     * @return void
503
     */
504
    public function setTargetDir($targetDir)
505
    {
506
        $this->targetDir = $targetDir;
507
    }
508
509
    /**
510
     * Return's the target directory with the files that has been imported.
511
     *
512
     * @return string The target directory
513
     */
514
    public function getTargetDir()
515
    {
516
        return $this->targetDir;
517
    }
518
519
    /**
520
     * Set's the Magento edition, EE or CE.
521
     *
522
     * @param string $magentoEdition The Magento edition
523
     *
524
     * @return void
525
     */
526
    public function setMagentoEdition($magentoEdition)
527
    {
528
        $this->magentoEdition = $magentoEdition;
529
    }
530
531
    /**
532
     * Return's the Magento edition, EE or CE.
533
     *
534
     * @return string The Magento edition
535
     */
536
    public function getMagentoEdition()
537
    {
538
        return $this->magentoEdition;
539
    }
540
541
    /**
542
     * Return's the Magento version, e. g. 2.1.0.
543
     *
544
     * @param string $magentoVersion The Magento version
545
     *
546
     * @return void
547
     */
548
    public function setMagentoVersion($magentoVersion)
549
    {
550
        $this->magentoVersion = $magentoVersion;
551
    }
552
553
    /**
554
     * Return's the Magento version, e. g. 2.1.0.
555
     *
556
     * @return string The Magento version
557
     */
558
    public function getMagentoVersion()
559
    {
560
        return $this->magentoVersion;
561
    }
562
563
    /**
564
     * Return's the entity type code to be used.
565
     *
566
     * @return string The entity type code to be used
567
     */
568
    public function getEntityTypeCode()
569
    {
570
        return $this->entityTypeCode;
571
    }
572
573
    /**
574
     * Set's the entity type code to be used.
575
     *
576
     * @param string $entityTypeCode The entity type code
577
     *
578
     * @return void
579
     */
580
    public function setEntityTypeCode($entityTypeCode)
581
    {
582
        $this->entityTypeCode = $entityTypeCode;
583
    }
584
585
    /**
586
     * Return's the multiple field delimiter character to use, default value is comma (,).
587
     *
588
     * @return string The multiple field delimiter character
589
     */
590
    public function getMultipleFieldDelimiter()
591
    {
592
        return $this->multipleFieldDelimiter;
593
    }
594
595
    /**
596
     * Return's the multiple value delimiter character to use, default value is comma (|).
597
     *
598
     * @return string The multiple value delimiter character
599
     */
600
    public function getMultipleValueDelimiter()
601
    {
602
        return $this->multipleValueDelimiter;
603
    }
604
605
    /**
606
     * Queries whether or not strict mode is enabled or not, default is TRUE.
607
     *
608
     * @return boolean TRUE if strict mode is enabled, else FALSE
609
     */
610
    public function isStrictMode()
611
    {
612
        return $this->strictMode;
613
    }
614
615
    /**
616
     * Remove's all configured database configuration.
617
     *
618
     * @return void
619
     */
620
    public function clearDatabases()
621
    {
622
        $this->databases->clear();
623
    }
624
625
    /**
626
     * Add's the passed database configuration.
627
     *
628
     * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration
629
     *
630
     * @return void
631
     */
632
    public function addDatabase(DatabaseConfigurationInterface $database)
633
    {
634
        $this->databases->add($database);
635
    }
636
637
    /**
638
     * Return's the number database configurations.
639
     *
640
     * @return integer The number of database configurations
641
     */
642
    public function countDatabases()
643
    {
644
        return $this->databases->count();
645
    }
646
647
    /**
648
     * Return's the database configuration with the passed ID.
649
     *
650
     * @param string $id The ID of the database connection to return
651
     *
652
     * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration
653
     * @throws \Exception Is thrown, if no database configuration is available
654
     */
655
    public function getDatabaseById($id)
656
    {
657
658
        // iterate over the configured databases and return the one with the passed ID
659
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
660
        foreach ($this->databases as $database) {
661
            if ($database->getId() === $id && $this->isValidDatabaseType($database)) {
662
                return $database;
663
            }
664
        }
665
666
        // throw an exception, if the database with the passed ID is NOT configured
667
        throw new \Exception(sprintf('Database with ID %s can not be found or has an invalid type', $id));
668
    }
669
670
    /**
671
     * Return's the databases for the given type.
672
     *
673
     * @param string $type The database type to return the configurations for
674
     *
675
     * @return \Doctrine\Common\Collections\Collection The collection with the database configurations
676
     */
677
    public function getDatabasesByType($type)
678
    {
679
680
        // initialize the collection for the database configurations
681
        $databases = new ArrayCollection();
682
683
        // iterate over the configured databases and return the one with the passed ID
684
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
685
        foreach ($this->databases as $database) {
686
            if ($database->getType() === $type && $this->isValidDatabaseType($database)) {
687
                $databases->add($database);
688
            }
689
        }
690
691
        // return the database configurations
692
        return $databases;
693
    }
694
695
    /**
696
     * Query's whether or not the passed database configuration has a valid type.
697
     *
698
     * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration
699
     *
700
     * @return boolean TRUE if the passed database configuration has a valid type, else FALSE
701
     */
702
    protected function isValidDatabaseType(DatabaseConfigurationInterface $database)
703
    {
704
        return in_array(strtolower($database->getType()), $this->availableDatabaseTypes);
705
    }
706
707
    /**
708
     * Return's the database configuration.
709
     *
710
     * If an explicit DB ID is specified, the method tries to return the database with this ID. If
711
     * the database configuration is NOT available, an execption is thrown.
712
     *
713
     * If no explicit DB ID is specified, the method tries to return the default database configuration,
714
     * if not available the first one.
715
     *
716
     * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration
717
     * @throws \Exception Is thrown, if no database configuration is available
718
     */
719
    public function getDatabase()
720
    {
721
722
        // if a DB ID has been set, try to load the database
723
        if ($useDbId = $this->getUseDbId()) {
724
            return $this->getDatabaseById($useDbId);
725
        }
726
727
        // iterate over the configured databases and try return the default database
728
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
729
        foreach ($this->databases as $database) {
730
            if ($database->isDefault() && $this->isValidDatabaseType($database)) {
731
                return $database;
732
            }
733
        }
734
735
        // try to return the first database configurtion
736
        if ($this->databases->count() > 0) {
737
            return $this->databases->first();
738
        }
739
740
        // throw an exception, if no database configuration is available
741
        throw new \Exception('There is no database configuration available');
742
    }
743
744
    /**
745
     * Return's the ArrayCollection with the configured operations.
746
     *
747
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations
748
     */
749
    public function getOperations()
750
    {
751
        return $this->operations;
752
    }
753
754
    /**
755
     * Return's the ArrayCollection with the configured loggers.
756
     *
757
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the loggers
758
     */
759
    public function getLoggers()
760
    {
761
        return $this->loggers;
762
    }
763
764
    /**
765
     * Set's the flag that import artefacts have to be archived or not.
766
     *
767
     * @param boolean $archiveArtefacts TRUE if artefacts have to be archived, else FALSE
768
     *
769
     * @return void
770
     */
771
    public function setArchiveArtefacts($archiveArtefacts)
772
    {
773
        $this->archiveArtefacts = $archiveArtefacts;
774
    }
775
776
    /**
777
     * Return's the TRUE if the import artefacts have to be archived.
778
     *
779
     * @return boolean TRUE if the import artefacts have to be archived
780
     */
781
    public function haveArchiveArtefacts()
782
    {
783
        return $this->archiveArtefacts;
784
    }
785
786
    /**
787
     * The directory where the archives will be stored.
788
     *
789
     * @param string $archiveDir The archive directory
790
     *
791
     * @return void
792
     */
793
    public function setArchiveDir($archiveDir)
794
    {
795
        $this->archiveDir = $archiveDir;
796
    }
797
798
    /**
799
     * The directory where the archives will be stored.
800
     *
801
     * @return string The archive directory
802
     */
803
    public function getArchiveDir()
804
    {
805
        return $this->archiveDir;
806
    }
807
808
    /**
809
     * Set's the debug mode.
810
     *
811
     * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE
812
     *
813
     * @return void
814
     */
815
    public function setDebugMode($debugMode)
816
    {
817
        $this->debugMode = $debugMode;
818
    }
819
820
    /**
821
     * Queries whether or not debug mode is enabled or not, default is TRUE.
822
     *
823
     * @return boolean TRUE if debug mode is enabled, else FALSE
824
     */
825
    public function isDebugMode()
826
    {
827
        return $this->debugMode;
828
    }
829
830
    /**
831
     * Set's the log level to use.
832
     *
833
     * @param string $logLevel The log level to use
834
     *
835
     * @return void
836
     */
837
    public function setLogLevel($logLevel)
838
    {
839
        $this->logLevel = $logLevel;
840
    }
841
842
    /**
843
     * Return's the log level to use.
844
     *
845
     * @return string The log level to use
846
     */
847
    public function getLogLevel()
848
    {
849
        return $this->logLevel;
850
    }
851
852
    /**
853
     * Set's the explicit DB ID to use.
854
     *
855
     * @param string $useDbId The explicit DB ID to use
856
     *
857
     * @return void
858
     */
859
    public function setUseDbId($useDbId)
860
    {
861
        $this->useDbId = $useDbId;
862
    }
863
864
    /**
865
     * Return's the explicit DB ID to use.
866
     *
867
     * @return string The explicit DB ID to use
868
     */
869
    public function getUseDbId()
870
    {
871
        return $this->useDbId;
872
    }
873
874
    /**
875
     * Set's the PID filename to use.
876
     *
877
     * @param string $pidFilename The PID filename to use
878
     *
879
     * @return void
880
     */
881
    public function setPidFilename($pidFilename)
882
    {
883
        $this->pidFilename = $pidFilename;
884
    }
885
886
    /**
887
     * Return's the PID filename to use.
888
     *
889
     * @return string The PID filename to use
890
     */
891
    public function getPidFilename()
892
    {
893
        return $this->pidFilename;
894
    }
895
896
    /**
897
     * Set's the systemm name to be used.
898
     *
899
     * @param string $systemName The system name to be used
900
     *
901
     * @return void
902
     */
903
    public function setSystemName($systemName)
904
    {
905
        $this->systemName = $systemName;
906
    }
907
908
    /**
909
     * Return's the systemm name to be used.
910
     *
911
     * @return string The system name to be used
912
     */
913
    public function getSystemName()
914
    {
915
        return $this->systemName;
916
    }
917
918
    /**
919
     * Set's the collection with the path of the Magento Edition specific extension libraries.
920
     *
921
     * @param array $extensionLibraries The paths of the Magento Edition specific extension libraries
922
     *
923
     * @return void
924
     */
925
    public function setExtensionLibraries(array $extensionLibraries)
926
    {
927
        $this->extensionLibraries = $extensionLibraries;
928
    }
929
930
    /**
931
     * Return's an array with the path of the Magento Edition specific extension libraries.
932
     *
933
     * @return array The paths of the Magento Edition specific extension libraries
934
     */
935
    public function getExtensionLibraries()
936
    {
937
        return $this->extensionLibraries;
938
    }
939
940
    /**
941
     * Return's a collection with the path to additional vendor directories.
942
     *
943
     * @return \Doctrine\Common\Collections\ArrayCollection The paths to additional vendor directories
944
     */
945
    public function getAdditionalVendorDirs()
946
    {
947
        return $this->additionalVendorDirs;
948
    }
949
950
    /**
951
     * Lifecycle callback that will be invoked after deserialization.
952
     *
953
     * @return void
954
     * @PostDeserialize
955
     */
956
    public function postDeserialize()
957
    {
958
959
        // create an empty collection if no loggers has been specified
960
        if ($this->loggers === null) {
961
            $this->loggers = new ArrayCollection();
962
        }
963
964
        // create an empty collection if no operations has been specified
965
        if ($this->operations === null) {
966
            $this->operations = new ArrayCollection();
967
        }
968
969
        // create an empty collection if no additional venor directories has been specified
970
        if ($this->additionalVendorDirs === null) {
971
            $this->additionalVendorDirs = new ArrayCollection();
972
        }
973
974
        // create an empty collection if no caches has been specified
975
        if ($this->caches === null) {
976
            $this->caches = new ArrayCollection();
977
        }
978
979
        // create an empty collection if no aliases has been specified
980
        if ($this->aliases === null) {
981
            $this->aliases = new ArrayCollection();
982
        }
983
    }
984
985
    /**
986
     * The array with the subject's custom header mappings.
987
     *
988
     * @return array The custom header mappings
989
     */
990
    public function getHeaderMappings()
991
    {
992
993
        // initialize the array for the custom header mappings
994
        $headerMappings = array();
995
996
        // try to load the configured header mappings
997
        if ($headerMappingsAvailable = reset($this->headerMappings)) {
998
            $headerMappings = $headerMappingsAvailable;
999
        }
1000
1001
        // return the custom header mappings
1002
        return $headerMappings;
1003
    }
1004
1005
    /**
1006
     * The array with the subject's custom image types.
1007
     *
1008
     * @return array The custom image types
1009
     */
1010
    public function getImageTypes()
1011
    {
1012
1013
        // initialize the array for the custom image types
1014
        $imageTypes = array();
1015
1016
        // try to load the configured image types
1017
        if ($imageTypesAvailable = reset($this->imageTypes)) {
1018
            $imageTypes = $imageTypesAvailable;
1019
        }
1020
1021
        // return the custom image types
1022
        return $imageTypes;
1023
    }
1024
1025
    /**
1026
     * Set's the flag that decides whether or not the import should be wrapped within a single transaction.
1027
     *
1028
     * @param boolean $singleTransaction TRUE if the import should be wrapped in a single transation, else FALSE
1029
     *
1030
     * @return void
1031
     */
1032
    public function setSingleTransaction($singleTransaction)
1033
    {
1034
        $this->singleTransaction = $singleTransaction;
1035
    }
1036
1037
    /**
1038
     * Whether or not the import should be wrapped within a single transation.
1039
     *
1040
     * @return boolean TRUE if the import should be wrapped in a single transation, else FALSE
1041
     */
1042
    public function isSingleTransaction()
1043
    {
1044
        return $this->singleTransaction;
1045
    }
1046
1047
    /**
1048
     * Set's the flag that decides whether or not the the cache has been enabled.
1049
     *
1050
     * @param boolean $cacheEnabled TRUE if the cache has been enabled, else FALSE
1051
     *
1052
     * @return void
1053
     */
1054
    public function setCacheEnabled($cacheEnabled)
1055
    {
1056
        $this->cacheEnabled = $cacheEnabled;
1057
    }
1058
1059
    /**
1060
     * Whether or not the cache functionality should be enabled.
1061
     *
1062
     * @return boolean TRUE if the cache has to be enabled, else FALSE
1063
     */
1064
    public function isCacheEnabled()
1065
    {
1066
        return $this->cacheEnabled;
1067
    }
1068
1069
    /**
1070
     * Set's the passed serial from the commandline to the configuration.
1071
     *
1072
     * @param string $serial The serial from the commandline
1073
     *
1074
     * @return void
1075
     */
1076
    public function setSerial($serial)
1077
    {
1078
        $this->serial = $serial;
1079
    }
1080
1081
    /**
1082
     * Return's the serial from the commandline.
1083
     *
1084
     * @return string The serial
1085
     */
1086
    public function getSerial()
1087
    {
1088
        return $this->serial;
1089
    }
1090
1091
    /**
1092
     * Return's the configuration for the caches.
1093
     *
1094
     * @return \Doctrine\Common\Collections\ArrayCollection The cache configurations
1095
     */
1096
    public function getCaches()
1097
    {
1098
1099
        // iterate over the caches and set the parent configuration instance
1100
        foreach ($this->caches as $cache) {
1101
            $cache->setConfiguration($this);
1102
        }
1103
1104
        // return the array with the caches
1105
        return $this->caches;
1106
    }
1107
1108
    /**
1109
     * Return's the cache configuration for the passed type.
1110
     *
1111
     * @param string $type The cache type to return the configuation for
1112
     *
1113
     * @return \TechDivision\Import\Configuration\CacheConfigurationInterface The cache configuration
1114
     */
1115
    public function getCacheByType($type)
1116
    {
1117
1118
        // load the available cache configurations
1119
        $caches = $this->getCaches();
1120
1121
        // try to load the cache for the passed type
1122
        /** @var \TechDivision\Import\Configuration\CacheConfigurationInterface $cache */
1123
        foreach ($caches as $cache) {
1124
            if ($cache->getType() === $type) {
1125
                return $cache;
1126
            }
1127
        }
1128
    }
1129
1130
    /**
1131
     * Return's the alias configuration.
1132
     *
1133
     * @return \Doctrine\Common\Collections\ArrayCollection The alias configuration
1134
     */
1135
    public function getAliases()
1136
    {
1137
        return $this->aliases;
1138
    }
1139
}
1140