Completed
Push — 15.x ( a8a0e5...d73106 )
by Tim
01:34
created

Configuration   F

Complexity

Total Complexity 106

Size/Duplication

Total Lines 1334
Duplicated Lines 0 %

Coupling/Cohesion

Components 5
Dependencies 7

Importance

Changes 0
Metric Value
wmc 106
lcom 5
cbo 7
dl 0
loc 1334
rs 0.8
c 0
b 0
f 0

68 Methods

Rating   Name   Duplication   Size   Complexity  
B getOperationsToExecute() 0 41 7
B getPlugins() 0 39 6
A mapEntityTypeToMagentoEdition() 0 14 2
A mapBoolean() 0 11 2
A getId() 0 4 1
A addOperationName() 0 11 3
A setOperationNames() 0 4 1
A getOperationNames() 0 4 1
A inOperationNames() 0 4 1
A setInstallationDir() 0 4 1
A getInstallationDir() 0 4 1
A setSourceDir() 0 4 1
A getSourceDir() 0 4 1
A setTargetDir() 0 4 1
A getTargetDir() 0 4 1
A setMagentoEdition() 0 4 1
A getMagentoEdition() 0 4 1
A setMagentoVersion() 0 4 1
A getMagentoVersion() 0 4 1
A getEntityTypeCode() 0 4 1
A setEntityTypeCode() 0 4 1
A getMultipleFieldDelimiter() 0 4 1
A getMultipleValueDelimiter() 0 4 1
A isStrictMode() 0 4 1
A clearDatabases() 0 4 1
A addDatabase() 0 4 1
A countDatabases() 0 4 1
A getDatabaseById() 0 14 4
A getDatabasesByType() 0 17 4
A isValidDatabaseType() 0 4 1
B getDatabase() 0 24 6
A getOperations() 0 4 1
A getLoggers() 0 4 1
A setArchiveArtefacts() 0 4 1
A haveArchiveArtefacts() 0 4 1
A setArchiveDir() 0 4 1
A getArchiveDir() 0 4 1
A setDebugMode() 0 4 1
A isDebugMode() 0 4 1
A setLogLevel() 0 4 1
A getLogLevel() 0 4 1
A setUseDbId() 0 4 1
A getUseDbId() 0 4 1
A setPidFilename() 0 4 1
A getPidFilename() 0 4 1
A setSystemName() 0 4 1
A getSystemName() 0 4 1
A setExtensionLibraries() 0 4 1
A getExtensionLibraries() 0 4 1
A getAdditionalVendorDirs() 0 4 1
B postDeserialize() 0 34 8
A getHeaderMappings() 0 14 2
A getImageTypes() 0 14 2
A setSingleTransaction() 0 4 1
A isSingleTransaction() 0 4 1
A setCacheEnabled() 0 4 1
A isCacheEnabled() 0 4 1
A setSerial() 0 4 1
A getSerial() 0 4 1
A getCaches() 0 11 2
A getCacheByType() 0 14 3
A getAliases() 0 4 1
A setMoveFilesPrefix() 0 4 1
A getMoveFilesPrefix() 0 4 1
A setMoveFiles() 0 4 1
A shouldMoveFiles() 0 4 1
A setCompile() 0 4 1
A shouldCompile() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Configuration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Configuration, and based on these observations, apply Extract Interface, too.

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 Doctrine\Common\Collections\ArrayCollection;
25
use JMS\Serializer\Annotation\Type;
26
use JMS\Serializer\Annotation\Exclude;
27
use JMS\Serializer\Annotation\SerializedName;
28
use JMS\Serializer\Annotation\PostDeserialize;
29
use JMS\Serializer\Annotation\ExclusionPolicy;
30
use TechDivision\Import\Utils\OperationKeys;
31
use TechDivision\Import\ConfigurationInterface;
32
use TechDivision\Import\Configuration\DatabaseConfigurationInterface;
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
use TechDivision\Import\Configuration\OperationConfigurationInterface;
38
use TechDivision\Import\Configuration\Jms\Configuration\ExecutionContext;
39
use TechDivision;
40
41
/**
42
 * A simple JMS based configuration implementation.
43
 *
44
 * @author    Tim Wagner <[email protected]>
45
 * @copyright 2016 TechDivision GmbH <[email protected]>
46
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
47
 * @link      https://github.com/techdivision/import-configuration-jms
48
 * @link      http://www.techdivision.com
49
 *
50
 * @ExclusionPolicy("none")
51
 */
52
class Configuration implements ConfigurationInterface, ListenerAwareConfigurationInterface
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: getOperation, getOperationName
Loading history...
53
{
54
55
    /**
56
     * The default PID filename to use.
57
     *
58
     * @var string
59
     */
60
    const PID_FILENAME = 'importer.pid';
61
62
    /**
63
     * Trait that provides CSV configuration functionality.
64
     *
65
     * @var \TechDivision\Import\Configuration\Jms\Configuration\CsvTrait
66
     */
67
    use CsvTrait;
68
69
    /**
70
     * Trait that provides CSV configuration functionality.
71
     *
72
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait
73
     */
74
    use ParamsTrait;
75
76
    /**
77
     * Trait that provides CSV configuration functionality.
78
     *
79
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait
80
     */
81
    use ListenersTrait;
82
83
    /**
84
     * The array with the available database types.
85
     *
86
     * @var array
87
     * @Exclude
88
     */
89
    protected $availableDatabaseTypes = array(
90
        DatabaseConfigurationInterface::TYPE_MYSQL,
91
        DatabaseConfigurationInterface::TYPE_REDIS
92
    );
93
94
    /**
95
     * Mapping for boolean values passed on the console.
96
     *
97
     * @var array
98
     * @Exclude
99
     */
100
    protected $booleanMapping = array(
101
        'true'  => true,
102
        'false' => false,
103
        '1'     => true,
104
        '0'     => false,
105
        'on'    => true,
106
        'off'   => false
107
    );
108
109
    /**
110
     * Mapping for entity type to edition mapping (for configuration purposes only).
111
     *
112
     * @var array
113
     * @Exclude
114
     */
115
    protected $entityTypeToEditionMapping = array(/*
116
        'eav_attribute'                 => 'general',
117
        'eav_attribte_set'              => 'general',
118
        'catalog_product_inventory_msi' => 'general',
119
        'catalog_product_tier_price'    => 'general',
120
        'customer_address'              => 'general',
121
        'customer'                      => 'general'
122
    */);
123
124
    /**
125
     * The serial that will be passed as commandline option (can not be specified in configuration file).
126
     *
127
     * @var string
128
     * @Exclude
129
     */
130
    protected $serial;
131
132
    /**
133
     * The application's unique DI identifier.
134
     *
135
     * @var string
136
     * @Type("string")
137
     * @SerializedName("id")
138
     */
139
    protected $id;
140
141
    /**
142
     * The system name to use.
143
     *
144
     * @var string
145
     * @Type("string")
146
     * @SerializedName("system-name")
147
     */
148
    protected $systemName;
149
150
    /**
151
     * The operation names to be executed.
152
     *
153
     * @var array
154
     * @Type("array<string>")
155
     * @SerializedName("operation-names")
156
     */
157
    protected $operationNames = array();
158
159
    /**
160
     * The entity type code to use.
161
     *
162
     * @var string
163
     * @Type("string")
164
     * @SerializedName("entity-type-code")
165
     */
166
    protected $entityTypeCode;
167
168
    /**
169
     * The Magento installation directory.
170
     *
171
     * @var string
172
     * @Type("string")
173
     * @SerializedName("installation-dir")
174
     */
175
    protected $installationDir;
176
177
    /**
178
     * The source directory that has to be watched for new files.
179
     *
180
     * @var string
181
     * @Type("string")
182
     * @SerializedName("source-dir")
183
     */
184
    protected $sourceDir;
185
186
    /**
187
     * The target directory with the files that has been imported.
188
     *
189
     * @var string
190
     * @Type("string")
191
     * @SerializedName("target-dir")
192
     */
193
    protected $targetDir;
194
195
    /**
196
     * The Magento edition, EE or CE.
197
     *
198
     * @var string
199
     * @Type("string")
200
     * @SerializedName("magento-edition")
201
     */
202
    protected $magentoEdition = 'CE';
203
204
    /**
205
     * The Magento version, e. g. 2.2.0.
206
     *
207
     * @var string
208
     * @Type("string")
209
     * @SerializedName("magento-version")
210
     */
211
    protected $magentoVersion = '2.2.0';
212
213
    /**
214
     * ArrayCollection with the information of the configured databases.
215
     *
216
     * @var \Doctrine\Common\Collections\ArrayCollection
217
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Database>")
218
     */
219
    protected $databases;
220
221
    /**
222
     * ArrayCollection with the information of the configured loggers.
223
     *
224
     * @var \Doctrine\Common\Collections\ArrayCollection
225
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Logger>")
226
     */
227
    protected $loggers;
228
229
    /**
230
     * ArrayCollection with the information of the configured operations.
231
     *
232
     * @var \Doctrine\Common\Collections\ArrayCollection
233
     * @Type("array<string, array<string, ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Operation>>>")
234
     */
235
    protected $operations;
236
237
    /**
238
     * The subject's multiple field delimiter character for fields with multiple values, defaults to (,).
239
     *
240
     * @var string
241
     * @Type("string")
242
     * @SerializedName("multiple-field-delimiter")
243
     */
244
    protected $multipleFieldDelimiter = ',';
245
246
    /**
247
     * The subject's multiple value delimiter character for fields with multiple values, defaults to (|).
248
     *
249
     * @var string
250
     * @Type("string")
251
     * @SerializedName("multiple-value-delimiter")
252
     */
253
    protected $multipleValueDelimiter = '|';
254
255
    /**
256
     * The flag to signal that the subject has to use the strict mode or not.
257
     *
258
     * @var boolean
259
     * @Type("boolean")
260
     * @SerializedName("strict-mode")
261
     */
262
    protected $strictMode;
263
264
    /**
265
     * The flag whether or not the import artefacts have to be archived.
266
     *
267
     * @var boolean
268
     * @Type("boolean")
269
     * @SerializedName("archive-artefacts")
270
     */
271
    protected $archiveArtefacts;
272
273
    /**
274
     * The directory where the archives will be stored.
275
     *
276
     * @var string
277
     * @Type("string")
278
     * @SerializedName("archive-dir")
279
     */
280
    protected $archiveDir;
281
282
    /**
283
     * The flag to signal that the subject has to use the debug mode or not.
284
     *
285
     * @var boolean
286
     * @Type("boolean")
287
     * @SerializedName("debug-mode")
288
     */
289
    protected $debugMode = false;
290
291
    /**
292
     * The log level to use (see Monolog documentation).
293
     *
294
     * @var string
295
     * @Type("string")
296
     * @SerializedName("log-level")
297
     */
298
    protected $logLevel = LogLevel::INFO;
299
300
    /**
301
     * The explicit DB ID to use.
302
     *
303
     * @var string
304
     * @Type("string")
305
     * @SerializedName("use-db-id")
306
     */
307
    protected $useDbId;
308
309
    /**
310
     * The explicit PID filename to use.
311
     *
312
     * @var string
313
     * @Type("string")
314
     * @SerializedName("pid-filename")
315
     */
316
    protected $pidFilename;
317
318
    /**
319
     * The collection with the paths to additional vendor directories.
320
     *
321
     * @var \Doctrine\Common\Collections\ArrayCollection
322
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\VendorDir>")
323
     * @SerializedName("additional-vendor-dirs")
324
     */
325
    protected $additionalVendorDirs;
326
327
    /**
328
     * The array with the Magento Edition specific extension libraries.
329
     *
330
     * @var array
331
     * @Type("array")
332
     * @SerializedName("extension-libraries")
333
     */
334
    protected $extensionLibraries = array();
335
336
    /**
337
     * The array with the custom header mappings.
338
     *
339
     * @var array
340
     * @Type("array")
341
     * @SerializedName("header-mappings")
342
     */
343
    protected $headerMappings = array();
344
345
    /**
346
     * The array with the custom image types.
347
     *
348
     * @var array
349
     * @Type("array")
350
     * @SerializedName("image-types")
351
     */
352
    protected $imageTypes = array();
353
354
    /**
355
     * The flag to signal that the import should be wrapped within a single transation or not.
356
     *
357
     * @var boolean
358
     * @Type("boolean")
359
     * @SerializedName("single-transaction")
360
     */
361
    protected $singleTransaction = false;
362
363
    /**
364
     * The flag to signal that the cache should be enabled or not.
365
     *
366
     * @var boolean
367
     * @Type("boolean")
368
     * @SerializedName("cache-enabled")
369
     */
370
    protected $cacheEnabled = true;
371
372
    /**
373
     * ArrayCollection with the information of the configured aliases.
374
     *
375
     * @var \Doctrine\Common\Collections\ArrayCollection
376
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Alias>")
377
     */
378
    protected $aliases;
379
380
    /**
381
     * ArrayCollection with the information of the configured caches.
382
     *
383
     * @var \Doctrine\Common\Collections\ArrayCollection
384
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Cache>")
385
     */
386
    protected $caches;
387
388
    /**
389
     * The flag to signal that the files should be move from the source to the target directory or not.
390
     *
391
     * @var boolean
392
     * @Type("boolean")
393
     * @SerializedName("move-files")
394
     */
395
    protected $moveFiles = true;
396
397
    /**
398
     * The prefix for the move files subject.
399
     *
400
     * @var string
401
     * @Type("string")
402
     * @SerializedName("move-files-prefix")
403
     */
404
    protected $moveFilesPrefix;
405
406
    /**
407
     * The flag to signal that the configuration files have to be loaded, merged and compiled.
408
     *
409
     * @var boolean
410
     * @Type("boolean")
411
     * @SerializedName("compile")
412
     */
413
    protected $compile = true;
414
415
    /**
416
     * The array with the shortcuts.
417
     *
418
     * @var array
419
     * @Type("array<string, array<string, array>>")
420
     * @SerializedName("shortcuts")
421
     */
422
    protected $shortcuts = array();
423
424
    /**
425
     * Return's an array with the configurations of the operations that has to be executed.
426
     *
427
     * @return \TechDivision\Import\Configuration\OperationConfigurationInterface[] The operations
428
     */
429
    public function getOperationsToExecute()
430
    {
431
432
        // prepend the operation to move the files from the source to the target directory
433
        if ($this->shouldMoveFiles()) {
434
            $this->addOperationName(OperationKeys::MOVE_FILES, true);
435
        }
436
437
        // initialize the array for the operations that has to be executed
438
        $operations = array();
439
440
        // load the mapped Magento Edition
441
        $magentoEdition = $this->mapEntityTypeToMagentoEdition($entityTypeCode = $this->getEntityTypeCode());
442
443
        // load the operation names from the shorcuts
444
        foreach ($this->shortcuts[$magentoEdition][$entityTypeCode] as $operationName => $ops) {
445
            // query whether or not the operation has to be executed or nt
446
            if (in_array($operationName, $this->operationNames)) {
447
                // if yes, extract the operation data from the shortcut
448
                foreach ($ops as $op) {
449
                    // explode the shortcut to get Magento Edition, Entity Type Code and Operation Name
450
                    list($edition, $type, $name) = explode('/', $op);
451
                    // initialize the execution context with the Magento Edition + Entity Type Code
452
                    $executionContext = new ExecutionContext($edition, $type);
453
                    // load the operations we want to execute
454
                    foreach ($this->operations[$edition][$type] as $operation) {
455
                        // query whether or not the operation is in the array of operation that has to be executed
456
                        if ($operation->getName() === $name) {
457
                            // pass the execution context to the operation configuration
458
                            $operation->setExecutionContext($executionContext);
459
                            // finally add the operation to the array
460
                            $operations[] = $operation;
461
                        }
462
                    }
463
                }
464
            }
465
        }
466
467
        // return the array with the operations
468
        return $operations;
469
    }
470
471
    /**
472
     * Return's the array with the plugins of the operation to use.
473
     *
474
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the plugins
475
     * @throws \Exception Is thrown, if no plugins are available for the actual operation
476
     */
477
    public function getPlugins()
478
    {
479
480
        // initialize the array with the plugins that have to be executed
481
        $plugins = array();
482
483
        // load the operations that has to be executed
484
        $operations = $this->getOperationsToExecute();
485
486
        // initialize the plugin configurations of the selected operations
487
        foreach ($operations as $operation) {
488
            // iterate over the operation's plugins and initialize their configuration
489
            /** @var \TechDivision\Import\Configuration\PluginConfigurationInterface $plugin */
490
            foreach ($operation->getPlugins() as $plugin) {
491
                // pass the operation configuration instance to the plugin configuration
492
                $plugin->setOperationConfiguration($operation);
493
                // if NO prefix for the move files subject has been set, we use the prefix from the first plugin's subject
494
                if ($this->getMoveFilesPrefix() === null) {
495
                    // use the prefix of the first subject
496
                    /** @var \TechDivision\Import\Configuration\SubjectConfigurationInterface $subject */
497
                    foreach ($plugin->getSubjects() as $subject) {
498
                        $this->setMoveFilesPrefix($subject->getFileResolver()->getPrefix());
499
                        break;
500
                    }
501
                }
502
503
                // finally append the plugin
504
                $plugins[] = $plugin;
505
            }
506
        }
507
508
        // query whether or not we've at least ONE plugin to be executed
509
        if (sizeof($plugins) > 0) {
510
            return $plugins;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $plugins; (array) is incompatible with the return type declared by the interface TechDivision\Import\Conf...onInterface::getPlugins of type Doctrine\Common\Collections\ArrayCollection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
511
        }
512
513
        // throw an exception if no plugins are available
514
        throw new \Exception(sprintf('Can\'t find any plugins for operation(s) %s', implode(' > ', $this->getOperationNames())));
515
    }
516
517
    /**
518
     * Return's the Entity Type to the configuration specific Magento Edition.
519
     *
520
     * @param string $entityType The Entity Type fot map
521
     *
522
     * @return string The mapped configuration specific Magento Edition
523
     */
524
    protected function mapEntityTypeToMagentoEdition($entityType)
525
    {
526
527
        // load the actual Magento Edition
528
        $magentoEdition = strtolower($this->getMagentoEdition());
529
530
        // map the Entity Type to the configuration specific Magento Edition
531
        if (isset($this->entityTypeToEditionMapping[$entityType])) {
532
            $magentoEdition = $this->entityTypeToEditionMapping[$entityType];
533
        }
534
535
        // return the Magento Edition
536
        return $magentoEdition;
537
    }
538
539
    /**
540
     * Map's the passed value to a boolean.
541
     *
542
     * @param string $value The value to map
543
     *
544
     * @return boolean The mapped value
545
     * @throws \Exception Is thrown, if the value can't be mapped
546
     */
547
    public function mapBoolean($value)
548
    {
549
550
        // try to map the passed value to a boolean
551
        if (isset($this->booleanMapping[$val = strtolower($value)])) {
552
            return $this->booleanMapping[$val];
553
        }
554
555
        // throw an exception if we can't convert the passed value
556
        throw new \Exception(sprintf('Can\'t convert %s to boolean', $value));
557
    }
558
559
    /**
560
     * Return's the application's unique DI identifier.
561
     *
562
     * @return string The application's unique DI identifier
563
     */
564
    public function getId()
565
    {
566
        return $this->id;
567
    }
568
569
    /**
570
     * Add's the operation with the passed name ot the operations that has to be executed.
571
     *
572
     * If the operation name has already been added, it'll not be added again.
573
     *
574
     * @param string  $operationName The operation to be executed
575
     * @param boolean $prepend       TRUE if the operation name should be prepended, else FALSE
576
     *
577
     * @return void
578
     */
579
    public function addOperationName($operationName, $prepend = false)
580
    {
581
582
        // do nothing if the operation has already been added
583
        if (in_array($operationName, $this->operationNames)) {
584
            return;
585
        }
586
587
        // add the operation otherwise
588
        $prepend ? array_unshift($this->operationNames, $operationName) : array_push($this->operationNames, $operationName);
589
    }
590
591
    /**
592
     * Return's the operation names that has to be executed.
593
     *
594
     * @param array $operationNames The operation names that has to be executed
595
     *
596
     * @return void
597
     */
598
    public function setOperationNames(array $operationNames)
599
    {
600
        return $this->operationNames = $operationNames;
601
    }
602
603
    /**
604
     * Return's the operation names that has to be executed.
605
     *
606
     * @return array The operation names that has to be executed
607
     */
608
    public function getOperationNames()
609
    {
610
        return $this->operationNames;
611
    }
612
613
    /**
614
     * Queries whether or not the passed operation has to be exceuted or not.
615
     *
616
     * @param \TechDivision\Import\Configuration\OperationConfigurationInterface $operation The operation to query for
617
     *
618
     * @return boolean TRUE if the operation has to be executed, else FALSE
619
     */
620
    public function inOperationNames(OperationConfigurationInterface $operation)
621
    {
622
        return in_array($operation->getName(), $this->getOperationNames());
623
    }
624
625
    /**
626
     * Set's the Magento installation directory.
627
     *
628
     * @param string $installationDir The Magento installation directory
629
     *
630
     * @return void
631
     */
632
    public function setInstallationDir($installationDir)
633
    {
634
        $this->installationDir = $installationDir;
635
    }
636
637
    /**
638
     * Return's the Magento installation directory.
639
     *
640
     * @return string The Magento installation directory
641
     */
642
    public function getInstallationDir()
643
    {
644
        return $this->installationDir;
645
    }
646
647
    /**
648
     * Set's the source directory that has to be watched for new files.
649
     *
650
     * @param string $sourceDir The source directory
651
     *
652
     * @return void
653
     */
654
    public function setSourceDir($sourceDir)
655
    {
656
        $this->sourceDir = $sourceDir;
657
    }
658
659
    /**
660
     * Return's the source directory that has to be watched for new files.
661
     *
662
     * @return string The source directory
663
     */
664
    public function getSourceDir()
665
    {
666
        return $this->sourceDir;
667
    }
668
669
    /**
670
     * Set's the target directory with the files that has been imported.
671
     *
672
     * @param string $targetDir The target directory
673
     *
674
     * @return void
675
     */
676
    public function setTargetDir($targetDir)
677
    {
678
        $this->targetDir = $targetDir;
679
    }
680
681
    /**
682
     * Return's the target directory with the files that has been imported.
683
     *
684
     * @return string The target directory
685
     */
686
    public function getTargetDir()
687
    {
688
        return $this->targetDir;
689
    }
690
691
    /**
692
     * Set's the Magento edition, EE or CE.
693
     *
694
     * @param string $magentoEdition The Magento edition
695
     *
696
     * @return void
697
     */
698
    public function setMagentoEdition($magentoEdition)
699
    {
700
        $this->magentoEdition = $magentoEdition;
701
    }
702
703
    /**
704
     * Return's the Magento edition, EE or CE.
705
     *
706
     * @return string The Magento edition
707
     */
708
    public function getMagentoEdition()
709
    {
710
        return $this->magentoEdition;
711
    }
712
713
    /**
714
     * Return's the Magento version, e. g. 2.1.0.
715
     *
716
     * @param string $magentoVersion The Magento version
717
     *
718
     * @return void
719
     */
720
    public function setMagentoVersion($magentoVersion)
721
    {
722
        $this->magentoVersion = $magentoVersion;
723
    }
724
725
    /**
726
     * Return's the Magento version, e. g. 2.1.0.
727
     *
728
     * @return string The Magento version
729
     */
730
    public function getMagentoVersion()
731
    {
732
        return $this->magentoVersion;
733
    }
734
735
    /**
736
     * Return's the entity type code to be used.
737
     *
738
     * @return string The entity type code to be used
739
     */
740
    public function getEntityTypeCode()
741
    {
742
        return $this->entityTypeCode;
743
    }
744
745
    /**
746
     * Set's the entity type code to be used.
747
     *
748
     * @param string $entityTypeCode The entity type code
749
     *
750
     * @return void
751
     */
752
    public function setEntityTypeCode($entityTypeCode)
753
    {
754
        $this->entityTypeCode = $entityTypeCode;
755
    }
756
757
    /**
758
     * Return's the multiple field delimiter character to use, default value is comma (,).
759
     *
760
     * @return string The multiple field delimiter character
761
     */
762
    public function getMultipleFieldDelimiter()
763
    {
764
        return $this->multipleFieldDelimiter;
765
    }
766
767
    /**
768
     * Return's the multiple value delimiter character to use, default value is comma (|).
769
     *
770
     * @return string The multiple value delimiter character
771
     */
772
    public function getMultipleValueDelimiter()
773
    {
774
        return $this->multipleValueDelimiter;
775
    }
776
777
    /**
778
     * Queries whether or not strict mode is enabled or not, default is TRUE.
779
     *
780
     * @return boolean TRUE if strict mode is enabled, else FALSE
781
     */
782
    public function isStrictMode()
783
    {
784
        return $this->strictMode;
785
    }
786
787
    /**
788
     * Remove's all configured database configuration.
789
     *
790
     * @return void
791
     */
792
    public function clearDatabases()
793
    {
794
        $this->databases->clear();
795
    }
796
797
    /**
798
     * Add's the passed database configuration.
799
     *
800
     * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration
801
     *
802
     * @return void
803
     */
804
    public function addDatabase(DatabaseConfigurationInterface $database)
805
    {
806
        $this->databases->add($database);
807
    }
808
809
    /**
810
     * Return's the number database configurations.
811
     *
812
     * @return integer The number of database configurations
813
     */
814
    public function countDatabases()
815
    {
816
        return $this->databases->count();
817
    }
818
819
    /**
820
     * Return's the database configuration with the passed ID.
821
     *
822
     * @param string $id The ID of the database connection to return
823
     *
824
     * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration
825
     * @throws \Exception Is thrown, if no database configuration is available
826
     */
827
    public function getDatabaseById($id)
828
    {
829
830
        // iterate over the configured databases and return the one with the passed ID
831
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
832
        foreach ($this->databases as $database) {
833
            if ($database->getId() === $id && $this->isValidDatabaseType($database)) {
834
                return $database;
835
            }
836
        }
837
838
        // throw an exception, if the database with the passed ID is NOT configured
839
        throw new \Exception(sprintf('Database with ID %s can not be found or has an invalid type', $id));
840
    }
841
842
    /**
843
     * Return's the databases for the given type.
844
     *
845
     * @param string $type The database type to return the configurations for
846
     *
847
     * @return \Doctrine\Common\Collections\Collection The collection with the database configurations
848
     */
849
    public function getDatabasesByType($type)
850
    {
851
852
        // initialize the collection for the database configurations
853
        $databases = new ArrayCollection();
854
855
        // iterate over the configured databases and return the one with the passed ID
856
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
857
        foreach ($this->databases as $database) {
858
            if ($database->getType() === $type && $this->isValidDatabaseType($database)) {
859
                $databases->add($database);
860
            }
861
        }
862
863
        // return the database configurations
864
        return $databases;
865
    }
866
867
    /**
868
     * Query's whether or not the passed database configuration has a valid type.
869
     *
870
     * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration
871
     *
872
     * @return boolean TRUE if the passed database configuration has a valid type, else FALSE
873
     */
874
    protected function isValidDatabaseType(DatabaseConfigurationInterface $database)
875
    {
876
        return in_array(strtolower($database->getType()), $this->availableDatabaseTypes);
877
    }
878
879
    /**
880
     * Return's the database configuration.
881
     *
882
     * If an explicit DB ID is specified, the method tries to return the database with this ID. If
883
     * the database configuration is NOT available, an execption is thrown.
884
     *
885
     * If no explicit DB ID is specified, the method tries to return the default database configuration,
886
     * if not available the first one.
887
     *
888
     * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration
889
     * @throws \Exception Is thrown, if no database configuration is available
890
     */
891
    public function getDatabase()
892
    {
893
894
        // if a DB ID has been set, try to load the database
895
        if ($useDbId = $this->getUseDbId()) {
896
            return $this->getDatabaseById($useDbId);
897
        }
898
899
        // iterate over the configured databases and try return the default database
900
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
901
        foreach ($this->databases as $database) {
902
            if ($database->isDefault() && $this->isValidDatabaseType($database)) {
903
                return $database;
904
            }
905
        }
906
907
        // try to return the first database configurtion
908
        if ($this->databases->count() > 0) {
909
            return $this->databases->first();
910
        }
911
912
        // throw an exception, if no database configuration is available
913
        throw new \Exception('There is no database configuration available');
914
    }
915
916
    /**
917
     * Return's the ArrayCollection with the configured operations.
918
     *
919
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations
920
     */
921
    public function getOperations()
922
    {
923
        return $this->operations;
924
    }
925
926
    /**
927
     * Return's the ArrayCollection with the configured loggers.
928
     *
929
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the loggers
930
     */
931
    public function getLoggers()
932
    {
933
        return $this->loggers;
934
    }
935
936
    /**
937
     * Set's the flag that import artefacts have to be archived or not.
938
     *
939
     * @param boolean $archiveArtefacts TRUE if artefacts have to be archived, else FALSE
940
     *
941
     * @return void
942
     */
943
    public function setArchiveArtefacts($archiveArtefacts)
944
    {
945
        $this->archiveArtefacts = $archiveArtefacts;
946
    }
947
948
    /**
949
     * Return's the TRUE if the import artefacts have to be archived.
950
     *
951
     * @return boolean TRUE if the import artefacts have to be archived
952
     */
953
    public function haveArchiveArtefacts()
954
    {
955
        return $this->archiveArtefacts;
956
    }
957
958
    /**
959
     * The directory where the archives will be stored.
960
     *
961
     * @param string $archiveDir The archive directory
962
     *
963
     * @return void
964
     */
965
    public function setArchiveDir($archiveDir)
966
    {
967
        $this->archiveDir = $archiveDir;
968
    }
969
970
    /**
971
     * The directory where the archives will be stored.
972
     *
973
     * @return string The archive directory
974
     */
975
    public function getArchiveDir()
976
    {
977
        return $this->archiveDir;
978
    }
979
980
    /**
981
     * Set's the debug mode.
982
     *
983
     * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE
984
     *
985
     * @return void
986
     */
987
    public function setDebugMode($debugMode)
988
    {
989
        $this->debugMode = $debugMode;
990
    }
991
992
    /**
993
     * Queries whether or not debug mode is enabled or not, default is TRUE.
994
     *
995
     * @return boolean TRUE if debug mode is enabled, else FALSE
996
     */
997
    public function isDebugMode()
998
    {
999
        return $this->debugMode;
1000
    }
1001
1002
    /**
1003
     * Set's the log level to use.
1004
     *
1005
     * @param string $logLevel The log level to use
1006
     *
1007
     * @return void
1008
     */
1009
    public function setLogLevel($logLevel)
1010
    {
1011
        $this->logLevel = $logLevel;
1012
    }
1013
1014
    /**
1015
     * Return's the log level to use.
1016
     *
1017
     * @return string The log level to use
1018
     */
1019
    public function getLogLevel()
1020
    {
1021
        return $this->logLevel;
1022
    }
1023
1024
    /**
1025
     * Set's the explicit DB ID to use.
1026
     *
1027
     * @param string $useDbId The explicit DB ID to use
1028
     *
1029
     * @return void
1030
     */
1031
    public function setUseDbId($useDbId)
1032
    {
1033
        $this->useDbId = $useDbId;
1034
    }
1035
1036
    /**
1037
     * Return's the explicit DB ID to use.
1038
     *
1039
     * @return string The explicit DB ID to use
1040
     */
1041
    public function getUseDbId()
1042
    {
1043
        return $this->useDbId;
1044
    }
1045
1046
    /**
1047
     * Set's the PID filename to use.
1048
     *
1049
     * @param string $pidFilename The PID filename to use
1050
     *
1051
     * @return void
1052
     */
1053
    public function setPidFilename($pidFilename)
1054
    {
1055
        $this->pidFilename = $pidFilename;
1056
    }
1057
1058
    /**
1059
     * Return's the PID filename to use.
1060
     *
1061
     * @return string The PID filename to use
1062
     */
1063
    public function getPidFilename()
1064
    {
1065
        return $this->pidFilename;
1066
    }
1067
1068
    /**
1069
     * Set's the systemm name to be used.
1070
     *
1071
     * @param string $systemName The system name to be used
1072
     *
1073
     * @return void
1074
     */
1075
    public function setSystemName($systemName)
1076
    {
1077
        $this->systemName = $systemName;
1078
    }
1079
1080
    /**
1081
     * Return's the systemm name to be used.
1082
     *
1083
     * @return string The system name to be used
1084
     */
1085
    public function getSystemName()
1086
    {
1087
        return $this->systemName;
1088
    }
1089
1090
    /**
1091
     * Set's the collection with the path of the Magento Edition specific extension libraries.
1092
     *
1093
     * @param array $extensionLibraries The paths of the Magento Edition specific extension libraries
1094
     *
1095
     * @return void
1096
     */
1097
    public function setExtensionLibraries(array $extensionLibraries)
1098
    {
1099
        $this->extensionLibraries = $extensionLibraries;
1100
    }
1101
1102
    /**
1103
     * Return's an array with the path of the Magento Edition specific extension libraries.
1104
     *
1105
     * @return array The paths of the Magento Edition specific extension libraries
1106
     */
1107
    public function getExtensionLibraries()
1108
    {
1109
        return $this->extensionLibraries;
1110
    }
1111
1112
    /**
1113
     * Return's a collection with the path to additional vendor directories.
1114
     *
1115
     * @return \Doctrine\Common\Collections\ArrayCollection The paths to additional vendor directories
1116
     */
1117
    public function getAdditionalVendorDirs()
1118
    {
1119
        return $this->additionalVendorDirs;
1120
    }
1121
1122
    /**
1123
     * Lifecycle callback that will be invoked after deserialization.
1124
     *
1125
     * @return void
1126
     * @PostDeserialize
1127
     */
1128
    public function postDeserialize()
1129
    {
1130
1131
        // create an empty collection if no loggers has been specified
1132
        if ($this->loggers === null) {
1133
            $this->loggers = new ArrayCollection();
1134
        }
1135
1136
        // create an empty collection if no operations has been specified
1137
        if ($this->operations === null) {
1138
            $this->operations = new ArrayCollection();
1139
        }
1140
1141
        // create an empty collection if no additional venor directories has been specified
1142
        if ($this->additionalVendorDirs === null) {
1143
            $this->additionalVendorDirs = new ArrayCollection();
1144
        }
1145
1146
        // create an empty collection if no caches has been specified
1147
        if ($this->caches === null) {
1148
            $this->caches = new ArrayCollection();
1149
        }
1150
1151
        // create an empty collection if no aliases has been specified
1152
        if ($this->aliases === null) {
1153
            $this->aliases = new ArrayCollection();
1154
        }
1155
1156
        foreach ($this->shortcuts as $edition => $shortcuts) {
1157
            foreach (array_keys($shortcuts) as $entityType) {
1158
                $this->entityTypeToEditionMapping[$entityType] = $edition;
1159
            }
1160
        }
1161
    }
1162
1163
    /**
1164
     * The array with the subject's custom header mappings.
1165
     *
1166
     * @return array The custom header mappings
1167
     */
1168
    public function getHeaderMappings()
1169
    {
1170
1171
        // initialize the array for the custom header mappings
1172
        $headerMappings = array();
1173
1174
        // try to load the configured header mappings
1175
        if ($headerMappingsAvailable = reset($this->headerMappings)) {
1176
            $headerMappings = $headerMappingsAvailable;
1177
        }
1178
1179
        // return the custom header mappings
1180
        return $headerMappings;
1181
    }
1182
1183
    /**
1184
     * The array with the subject's custom image types.
1185
     *
1186
     * @return array The custom image types
1187
     */
1188
    public function getImageTypes()
1189
    {
1190
1191
        // initialize the array for the custom image types
1192
        $imageTypes = array();
1193
1194
        // try to load the configured image types
1195
        if ($imageTypesAvailable = reset($this->imageTypes)) {
1196
            $imageTypes = $imageTypesAvailable;
1197
        }
1198
1199
        // return the custom image types
1200
        return $imageTypes;
1201
    }
1202
1203
    /**
1204
     * Set's the flag that decides whether or not the import should be wrapped within a single transaction.
1205
     *
1206
     * @param boolean $singleTransaction TRUE if the import should be wrapped in a single transation, else FALSE
1207
     *
1208
     * @return void
1209
     */
1210
    public function setSingleTransaction($singleTransaction)
1211
    {
1212
        $this->singleTransaction = $singleTransaction;
1213
    }
1214
1215
    /**
1216
     * Whether or not the import should be wrapped within a single transation.
1217
     *
1218
     * @return boolean TRUE if the import should be wrapped in a single transation, else FALSE
1219
     */
1220
    public function isSingleTransaction()
1221
    {
1222
        return $this->singleTransaction;
1223
    }
1224
1225
    /**
1226
     * Set's the flag that decides whether or not the the cache has been enabled.
1227
     *
1228
     * @param boolean $cacheEnabled TRUE if the cache has been enabled, else FALSE
1229
     *
1230
     * @return void
1231
     */
1232
    public function setCacheEnabled($cacheEnabled)
1233
    {
1234
        $this->cacheEnabled = $cacheEnabled;
1235
    }
1236
1237
    /**
1238
     * Whether or not the cache functionality should be enabled.
1239
     *
1240
     * @return boolean TRUE if the cache has to be enabled, else FALSE
1241
     */
1242
    public function isCacheEnabled()
1243
    {
1244
        return $this->cacheEnabled;
1245
    }
1246
1247
    /**
1248
     * Set's the passed serial from the commandline to the configuration.
1249
     *
1250
     * @param string $serial The serial from the commandline
1251
     *
1252
     * @return void
1253
     */
1254
    public function setSerial($serial)
1255
    {
1256
        $this->serial = $serial;
1257
    }
1258
1259
    /**
1260
     * Return's the serial from the commandline.
1261
     *
1262
     * @return string The serial
1263
     */
1264
    public function getSerial()
1265
    {
1266
        return $this->serial;
1267
    }
1268
1269
    /**
1270
     * Return's the configuration for the caches.
1271
     *
1272
     * @return \Doctrine\Common\Collections\ArrayCollection The cache configurations
1273
     */
1274
    public function getCaches()
1275
    {
1276
1277
        // iterate over the caches and set the parent configuration instance
1278
        foreach ($this->caches as $cache) {
1279
            $cache->setConfiguration($this);
1280
        }
1281
1282
        // return the array with the caches
1283
        return $this->caches;
1284
    }
1285
1286
    /**
1287
     * Return's the cache configuration for the passed type.
1288
     *
1289
     * @param string $type The cache type to return the configuation for
1290
     *
1291
     * @return \TechDivision\Import\Configuration\CacheConfigurationInterface The cache configuration
1292
     */
1293
    public function getCacheByType($type)
1294
    {
1295
1296
        // load the available cache configurations
1297
        $caches = $this->getCaches();
1298
1299
        // try to load the cache for the passed type
1300
        /** @var \TechDivision\Import\Configuration\CacheConfigurationInterface $cache */
1301
        foreach ($caches as $cache) {
1302
            if ($cache->getType() === $type) {
1303
                return $cache;
1304
            }
1305
        }
1306
    }
1307
1308
    /**
1309
     * Return's the alias configuration.
1310
     *
1311
     * @return \Doctrine\Common\Collections\ArrayCollection The alias configuration
1312
     */
1313
    public function getAliases()
1314
    {
1315
        return $this->aliases;
1316
    }
1317
1318
    /**
1319
     * Set's the prefix for the move files subject.
1320
     *
1321
     * @param string $moveFilesPrefix The prefix for the move files subject
1322
     *
1323
     * @return void
1324
     */
1325
    public function setMoveFilesPrefix($moveFilesPrefix)
1326
    {
1327
        $this->moveFilesPrefix = $moveFilesPrefix;
1328
    }
1329
1330
    /**
1331
     * Return's the prefix for the move files subject.
1332
     *
1333
     * @return string The prefix for the move files subject
1334
     *
1335
     * @return string The prefix for the move files subject
1336
     */
1337
    public function getMoveFilesPrefix()
1338
    {
1339
        return $this->moveFilesPrefix;
1340
    }
1341
1342
    /**
1343
     * Set's the flag that whether the files have to be moved from the source to the target directory or not.
1344
     *
1345
     * @param boolean $moveFiles TRUE if the files should be moved, else FALSE
1346
     *
1347
     * return void
1348
     */
1349
    public function setMoveFiles($moveFiles)
1350
    {
1351
        $this->moveFiles = $moveFiles;
1352
    }
1353
1354
    /**
1355
     * Whether or not the files should be moved from the source to the target directory.
1356
     *
1357
     * @return TRUE if the files should be moved, FALSE otherwise
1358
     */
1359
    public function shouldMoveFiles()
1360
    {
1361
        return $this->moveFiles;
1362
    }
1363
1364
    /**
1365
     * Set's the flag that whether the configuration files have to be compiled or not.
1366
     *
1367
     * @param boolean $compile TRUE if the configuration files have to be compiled, else FALSE
1368
     *
1369
     * return void
1370
     */
1371
    public function setCompile($compile)
1372
    {
1373
        $this->compile = $compile;
1374
    }
1375
1376
    /**
1377
     * Whether or not the configuration files have to be compiled or not.
1378
     *
1379
     * @return TRUE if the configuration files have to be compiled, FALSE otherwise
1380
     */
1381
    public function shouldCompile()
1382
    {
1383
        return $this->compile;
1384
    }
1385
}
1386