1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Cli\ConfigurationFactory |
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-cli-simple |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli; |
22
|
|
|
|
23
|
|
|
use Psr\Log\LogLevel; |
24
|
|
|
use Rhumsaa\Uuid\Uuid; |
25
|
|
|
use TechDivision\Import\App\Simple; |
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
27
|
|
|
use TechDivision\Import\Utils\EntityTypeCodes; |
28
|
|
|
use TechDivision\Import\Cli\Command\InputOptionKeys; |
29
|
|
|
use TechDivision\Import\Cli\Command\InputArgumentKeys; |
30
|
|
|
use TechDivision\Import\Cli\Command\ImportCommandInterface; |
31
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Database; |
32
|
|
|
use TechDivision\Import\Cli\Utils\MagentoConfigurationKeys; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The configuration factory implementation. |
36
|
|
|
* |
37
|
|
|
* @author Tim Wagner <[email protected]> |
38
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
39
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
40
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
41
|
|
|
* @link http://www.techdivision.com |
42
|
|
|
*/ |
43
|
|
|
class ConfigurationFactory extends \TechDivision\Import\Configuration\Jms\ConfigurationFactory |
44
|
|
|
{ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The composer name => Magento Edition mappings. |
48
|
|
|
* |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
protected static $editionMappings = array( |
52
|
|
|
'magento/magento2ce' => 'CE', |
53
|
|
|
'magento/project-communit-edition' => 'CE', |
54
|
|
|
'magento/magento2ee' => 'EE', |
55
|
|
|
'magento/project-enterprise-edition' => 'EE' |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The array with the default entity type code => import directory mappings. |
60
|
|
|
* |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected static $defaultDirectories = array( |
64
|
|
|
EntityTypeCodes::CATALOG_PRODUCT => 'products', |
65
|
|
|
EntityTypeCodes::CATALOG_CATEGORY => 'categories', |
66
|
|
|
EntityTypeCodes::EAV_ATTRIBUTE => 'attributes' |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* The array with the default entity type => configuration mapping. |
71
|
|
|
* |
72
|
|
|
* @var array |
73
|
|
|
*/ |
74
|
|
|
protected static $defaultConfigurations = array( |
75
|
|
|
'ce' => array( |
76
|
|
|
EntityTypeCodes::EAV_ATTRIBUTE => 'techdivision/import-attribute', |
77
|
|
|
EntityTypeCodes::CATALOG_PRODUCT => 'techdivision/import-product', |
78
|
|
|
EntityTypeCodes::CATALOG_CATEGORY => 'techdivision/import-category' |
79
|
|
|
), |
80
|
|
|
'ee' => array( |
81
|
|
|
EntityTypeCodes::EAV_ATTRIBUTE => 'techdivision/import-attribute', |
82
|
|
|
EntityTypeCodes::CATALOG_PRODUCT => 'techdivision/import-product-ee', |
83
|
|
|
EntityTypeCodes::CATALOG_CATEGORY => 'techdivision/import-category-ee' |
84
|
|
|
) |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* The Magento Edition specific default libraries. |
89
|
|
|
* |
90
|
|
|
* @var array |
91
|
|
|
*/ |
92
|
|
|
protected static $defaultLibraries = array( |
93
|
|
|
'ce' => array( |
94
|
|
|
'techdivision/import-app-simple', |
95
|
|
|
'techdivision/import', |
96
|
|
|
'techdivision/import-attribute', |
97
|
|
|
'techdivision/import-category', |
98
|
|
|
'techdivision/import-product', |
99
|
|
|
'techdivision/import-product-bundle', |
100
|
|
|
'techdivision/import-product-link', |
101
|
|
|
'techdivision/import-product-media', |
102
|
|
|
'techdivision/import-product-variant' |
103
|
|
|
), |
104
|
|
|
'ee' => array( |
105
|
|
|
'techdivision/import-app-simple', |
106
|
|
|
'techdivision/import', |
107
|
|
|
'techdivision/import-ee', |
108
|
|
|
'techdivision/import-attribute', |
109
|
|
|
'techdivision/import-category', |
110
|
|
|
'techdivision/import-category-ee', |
111
|
|
|
'techdivision/import-product', |
112
|
|
|
'techdivision/import-product-ee', |
113
|
|
|
'techdivision/import-product-bundle', |
114
|
|
|
'techdivision/import-product-bundle-ee', |
115
|
|
|
'techdivision/import-product-link', |
116
|
|
|
'techdivision/import-product-link-ee', |
117
|
|
|
'techdivision/import-product-media', |
118
|
|
|
'techdivision/import-product-media-ee', |
119
|
|
|
'techdivision/import-product-variant', |
120
|
|
|
'techdivision/import-product-variant-ee' |
121
|
|
|
) |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Factory implementation to create a new initialized configuration instance. |
126
|
|
|
* |
127
|
|
|
* If command line options are specified, they will always override the |
128
|
|
|
* values found in the configuration file. |
129
|
|
|
* |
130
|
|
|
* @param \TechDivision\Import\Cli\Command\ImportCommandInterface $command The command that tries to create the instance |
131
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input The Symfony console input instance |
132
|
|
|
* |
133
|
|
|
* @return \TechDivision\Import\Cli\Configuration The configuration instance |
134
|
|
|
* @throws \Exception Is thrown, if the specified configuration file doesn't exist or the mandatory arguments/options to run the requested operation are not available |
135
|
|
|
*/ |
136
|
|
|
public static function load(ImportCommandInterface $command, InputInterface $input) |
137
|
|
|
{ |
138
|
|
|
|
139
|
|
|
// query whether or not, a configuration file has been specified |
140
|
|
|
if ($configuration = $input->getOption(InputOptionKeys::CONFIGURATION)) { |
141
|
|
|
// load the configuration from the file with the given filename |
142
|
|
|
$instance = static::factory($configuration); |
143
|
|
|
|
|
|
|
|
144
|
|
|
} elseif ($input->hasOptionSpecified(InputOptionKeys::INSTALLATION_DIR) && |
|
|
|
|
145
|
|
|
$input->getOption(InputOptionKeys::INSTALLATION_DIR) |
146
|
|
|
) { |
147
|
|
|
// query whether or not, the specified installation directory is a valid Magento root directory |
148
|
|
|
if (!self::isMagentoRootDir($installationDir = $input->getOption(InputOptionKeys::INSTALLATION_DIR))) { |
149
|
|
|
throw new \Exception(sprintf('Directory %s specified by --installation-dir is not a Magento root directory', $installationDir)); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
// load the composer file from the Magento root directory |
153
|
|
|
$composer = json_decode(file_get_contents($composerFile = sprintf('%s/composer.json', $installationDir)), true); |
154
|
|
|
|
155
|
|
|
// try to locate Magento Edition/Version |
156
|
|
|
if (!isset(self::$editionMappings[$possibleEdition = $composer[MagentoConfigurationKeys::COMPOSER_EDITION_NAME_ATTRIBUTE]])) { |
157
|
|
|
throw new \Exception(sprintf('"%s" detected in "%s" is not a valid Magento Edition/Version', $possibleEdition, $composerFile)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
// if Magento Edition/Version are available, load them |
161
|
|
|
$magentoEdition = self::$editionMappings[$possibleEdition]; |
162
|
|
|
|
163
|
|
|
// use the Magento Edition that has been detected by the installation directory |
164
|
|
|
$instance = static::factory(self::getDefaultConfiguration($command, $magentoEdition)); |
165
|
|
|
|
|
|
|
|
166
|
|
|
} elseif ($magentoEdition = $input->getOption(InputOptionKeys::MAGENTO_EDITION)) { |
167
|
|
|
// use the Magento Edition that has been specified as option |
168
|
|
|
$instance = static::factory(self::getDefaultConfiguration($command, $magentoEdition)); |
169
|
|
|
|
|
|
|
|
170
|
|
|
} else { |
171
|
|
|
// throw an exception, if either no configuration file has been specified nor the Magento Edition can be detected |
172
|
|
|
throw new \Exception('At least one of "--configuration", "--installation-dir" or "--magento-edition" options has to be specified'); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
// query whether or not an operation name has been specified as command line |
176
|
|
|
// option, if yes override the value from the configuration file |
177
|
|
|
if ($operationName = $input->getArgument(InputArgumentKeys::OPERATION_NAME)) { |
178
|
|
|
$instance->setOperationName($operationName); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
// query whether or not a system name has been specified as command line |
182
|
|
|
// option, if yes override the value from the configuration file |
183
|
|
View Code Duplication |
if (($input->hasOptionSpecified(InputOptionKeys::SYSTEM_NAME) && $input->getOption(InputOptionKeys::SYSTEM_NAME)) || |
|
|
|
|
184
|
|
|
$instance->getSystemName() === null |
185
|
|
|
) { |
186
|
|
|
$instance->setSystemName($input->getOption(InputOptionKeys::SYSTEM_NAME)); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
// query whether or not a PID filename has been specified as command line |
190
|
|
|
// option, if yes override the value from the configuration file |
191
|
|
View Code Duplication |
if (($input->hasOptionSpecified(InputOptionKeys::PID_FILENAME) && $input->getOption(InputOptionKeys::PID_FILENAME)) || |
|
|
|
|
192
|
|
|
$instance->getPidFilename() === null |
193
|
|
|
) { |
194
|
|
|
$instance->setPidFilename($input->getOption(InputOptionKeys::PID_FILENAME)); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
// query whether or not a Magento installation directory has been specified as command line |
198
|
|
|
// option, if yes override the value from the configuration file |
199
|
|
View Code Duplication |
if (($input->hasOptionSpecified(InputOptionKeys::INSTALLATION_DIR) && $input->getOption(InputOptionKeys::INSTALLATION_DIR)) || |
|
|
|
|
200
|
|
|
$instance->getInstallationDir() === null |
201
|
|
|
) { |
202
|
|
|
$instance->setInstallationDir($input->getOption(InputOptionKeys::INSTALLATION_DIR)); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
// query whether or not a Magento edition has been specified as command line |
206
|
|
|
// option, if yes override the value from the configuration file |
207
|
|
|
if ($magentoEdition = $input->getOption(InputOptionKeys::MAGENTO_EDITION)) { |
208
|
|
|
$instance->setMagentoEdition($magentoEdition); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
// query whether or not a Magento version has been specified as command line |
212
|
|
|
// option, if yes override the value from the configuration file |
213
|
|
|
if ($magentoVersion = $input->getOption(InputOptionKeys::MAGENTO_VERSION)) { |
214
|
|
|
$instance->setMagentoVersion($magentoVersion); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// query whether or not a directory for the source files has been specified as command line |
218
|
|
|
// option, if yes override the value from the configuration file |
219
|
|
|
if ($sourceDir = $input->getOption(InputOptionKeys::SOURCE_DIR)) { |
220
|
|
|
$instance->setSourceDir($sourceDir); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
// query whether or not a directory containing the imported files has been specified as command line |
224
|
|
|
// option, if yes override the value from the configuration file |
225
|
|
|
if ($targetDir = $input->getOption(InputOptionKeys::TARGET_DIR)) { |
226
|
|
|
$instance->setTargetDir($targetDir); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
// query whether or not a source date format has been specified as command |
230
|
|
|
// line option, if yes override the value from the configuration file |
231
|
|
|
if ($sourceDateFormat = $input->getOption(InputOptionKeys::SOURCE_DATE_FORMAT)) { |
232
|
|
|
$instance->setSourceDateFormat($sourceDateFormat); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
// query whether or not the debug mode has been specified as command line |
236
|
|
|
// option, if yes override the value from the configuration file |
237
|
|
|
if ($debugMode = $input->getOption(InputOptionKeys::DEBUG_MODE)) { |
238
|
|
|
$instance->setDebugMode($instance->mapBoolean($debugMode)); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
// query whether or not the log level has been specified as command line |
242
|
|
|
// option, if yes override the value from the configuration file |
243
|
|
|
if ($logLevel = $input->getOption(InputOptionKeys::LOG_LEVEL)) { |
244
|
|
|
$instance->setLogLevel($logLevel); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
// query whether or not we've an valid Magento root directory specified |
248
|
|
|
if (self::isMagentoRootDir($installationDir = $instance->getInstallationDir())) { |
249
|
|
|
// if yes, add the database configuration |
250
|
|
|
$instance->addDatabase(self::getMagentoDbConnection($installationDir)); |
251
|
|
|
|
252
|
|
|
// add the source directory if NOT specified in the configuration file |
253
|
|
|
if ($instance->getSourceDir() === null) { |
254
|
|
|
$instance->setSourceDir($sourceDir = sprintf('%s/var/importexport', $installationDir)); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
// add the target directory if NOT specified in the configuration file |
258
|
|
|
if ($instance->getTargetDir() === null) { |
259
|
|
|
$instance->setTargetDir($sourceDir); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
// query whether or not a DB ID has been specified as command line |
264
|
|
|
// option, if yes override the value from the configuration file |
265
|
|
|
if ($useDbId = $input->getOption(InputOptionKeys::USE_DB_ID)) { |
266
|
|
|
$instance->setUseDbId($useDbId); |
267
|
|
|
} else { |
268
|
|
|
// query whether or not a PDO DSN has been specified as command line |
269
|
|
|
// option, if yes override the value from the configuration file |
270
|
|
|
if ($dsn = $input->getOption(InputOptionKeys::DB_PDO_DSN)) { |
271
|
|
|
// first REMOVE all other database configurations |
272
|
|
|
$instance->clearDatabases(); |
273
|
|
|
|
274
|
|
|
// add the database configuration |
275
|
|
|
$instance->addDatabase( |
276
|
|
|
self::newDatabaseConfiguration( |
277
|
|
|
$dsn, |
278
|
|
|
$input->getOption(InputOptionKeys::DB_USERNAME), |
279
|
|
|
$input->getOption(InputOptionKeys::DB_PASSWORD) |
280
|
|
|
) |
281
|
|
|
); |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
// extend the plugins with the main configuration instance |
286
|
|
|
/** @var \TechDivision\Import\Cli\Configuration\Subject $subject */ |
287
|
|
|
foreach ($instance->getPlugins() as $plugin) { |
288
|
|
|
// set the configuration instance on the plugin |
289
|
|
|
$plugin->setConfiguration($instance); |
290
|
|
|
|
291
|
|
|
// query whether or not the plugin has subjects configured |
292
|
|
|
if ($subjects = $plugin->getSubjects()) { |
293
|
|
|
// extend the plugin's subjects with the main configuration instance |
294
|
|
|
/** @var \TechDivision\Import\Cli\Configuration\Subject $subject */ |
295
|
|
|
foreach ($subjects as $subject) { |
296
|
|
|
// set the configuration instance on the subject |
297
|
|
|
$subject->setConfiguration($instance); |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
// query whether or not the debug mode is enabled and log level |
303
|
|
|
// has NOT been overwritten with a commandline option |
304
|
|
|
if ($instance->isDebugMode() && !$input->getOption(InputOptionKeys::LOG_LEVEL)) { |
305
|
|
|
// set debug log level, if log level has NOT been overwritten on command line |
306
|
|
|
$instance->setLogLevel(LogLevel::DEBUG); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
// prepend the array with the Magento Edition specific core libraries |
310
|
|
|
$instance->setExtensionLibraries( |
311
|
|
|
array_merge( |
312
|
|
|
ConfigurationFactory::getDefaultLibraries($instance->getMagentoEdition()), |
313
|
|
|
$instance->getExtensionLibraries() |
314
|
|
|
) |
315
|
|
|
); |
316
|
|
|
|
317
|
|
|
// return the initialized configuration instance |
318
|
|
|
return $instance; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Query whether or not, the passed directory is a Magento root directory. |
323
|
|
|
* |
324
|
|
|
* @param string $dir The directory to query |
325
|
|
|
* |
326
|
|
|
* @return boolean TRUE if the directory is a Magento root directory, else FALSE |
327
|
|
|
*/ |
328
|
|
|
public static function isMagentoRootDir($dir) |
329
|
|
|
{ |
330
|
|
|
return is_file(self::getMagentoEnv($dir)); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Return's the path to the Magento file with the environment configuration. |
335
|
|
|
* |
336
|
|
|
* @param string $dir The path to the Magento root directory |
337
|
|
|
* |
338
|
|
|
* @return string The path to the Magento file with the environment configuration |
339
|
|
|
*/ |
340
|
|
|
public static function getMagentoEnv($dir) |
341
|
|
|
{ |
342
|
|
|
return sprintf('%s/app/etc/env.php', $dir); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Return's the requested Magento DB connction data. |
347
|
|
|
* |
348
|
|
|
* @param string $dir The path to the Magento root directory |
349
|
|
|
* @param string $connectionName The connection name to return the data for |
350
|
|
|
* |
351
|
|
|
* @return array The connection data |
352
|
|
|
* @throws \Exception Is thrown, if the requested DB connection is not available |
353
|
|
|
*/ |
354
|
|
|
public static function getMagentoDbConnection($dir, $connectionName = 'default') |
355
|
|
|
{ |
356
|
|
|
|
357
|
|
|
// load the magento environment |
358
|
|
|
$env = require self::getMagentoEnv($dir); |
359
|
|
|
|
360
|
|
|
// query whether or not, the requested connection is available |
361
|
|
|
if (isset($env[MagentoConfigurationKeys::DB][MagentoConfigurationKeys::CONNECTION][$connectionName])) { |
362
|
|
|
// load the connection data |
363
|
|
|
$connection = $env[MagentoConfigurationKeys::DB][MagentoConfigurationKeys::CONNECTION][$connectionName]; |
364
|
|
|
|
365
|
|
|
// create and return a new database configuration |
366
|
|
|
return self::newDatabaseConfiguration( |
367
|
|
|
self::newDsn($connection[MagentoConfigurationKeys::HOST], $connection[MagentoConfigurationKeys::DBNAME]), |
368
|
|
|
$connection[MagentoConfigurationKeys::USERNAME], |
369
|
|
|
$connection[MagentoConfigurationKeys::PASSWORD], |
370
|
|
|
false |
371
|
|
|
); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
// throw an execption if not |
375
|
|
|
throw new \Exception(sprintf('Requested Magento DB connection "%s" not found in Magento "%s"', $connectionName, $dir)); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Create's and return's a new database configuration instance, initialized with |
380
|
|
|
* the passed values. |
381
|
|
|
* |
382
|
|
|
* @param string $dsn The DSN to use |
383
|
|
|
* @param string $username The username to use |
384
|
|
|
* @param string|null $password The passed to use |
385
|
|
|
* @param boolean $default TRUE if this should be the default connection |
386
|
|
|
* @param string $id The ID to use |
387
|
|
|
* |
388
|
|
|
* @return \TechDivision\Import\Configuration\Jms\Configuration\Database The database configuration instance |
389
|
|
|
*/ |
390
|
|
|
public static function newDatabaseConfiguration($dsn, $username = 'root', $password = null, $default = true, $id = null) |
391
|
|
|
{ |
392
|
|
|
|
393
|
|
|
// initialize a new database configuration |
394
|
|
|
$database = new Database(); |
395
|
|
|
$database->setDsn($dsn); |
396
|
|
|
$database->setDefault($default); |
397
|
|
|
$database->setUsername($username); |
398
|
|
|
|
399
|
|
|
// query whether or not an ID has been passed |
400
|
|
|
if ($id === null) { |
401
|
|
|
$id = Uuid::uuid4()->__toString(); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
// set the ID |
405
|
|
|
$database->setId($id); |
406
|
|
|
|
407
|
|
|
// query whether or not a password has been passed |
408
|
|
|
if ($password) { |
|
|
|
|
409
|
|
|
$database->setPassword($password); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
// return the database configuration |
413
|
|
|
return $database; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Create's and return's a new DSN from the passed values. |
418
|
|
|
* |
419
|
|
|
* @param string $host The host to use |
420
|
|
|
* @param string $dbName The database name to use |
421
|
|
|
* @param string $charset The charset to use |
422
|
|
|
* |
423
|
|
|
* @return string The DSN |
424
|
|
|
*/ |
425
|
|
|
public static function newDsn($host, $dbName, $charset = 'utf8') |
426
|
|
|
{ |
427
|
|
|
return sprintf('mysql:host=%s;dbname=%s;charset=%s', $host, $dbName, $charset); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* Return's the default configuration for the passed Magento Edition and the actual entity type. |
432
|
|
|
* |
433
|
|
|
* @param \TechDivision\Import\Cli\Command\ImportCommandInterface $command The command instance |
434
|
|
|
* @param string $magentoEdition The Magento Edition to return the configuration for |
435
|
|
|
* |
436
|
|
|
* @return string The path to the default configuration |
437
|
|
|
*/ |
438
|
|
|
public static function getDefaultConfiguration(ImportCommandInterface $command, $magentoEdition) |
439
|
|
|
{ |
440
|
|
|
return sprintf( |
441
|
|
|
'%s/%s/etc/techdivision-import.json', |
442
|
|
|
$command->getVendorDir(), |
443
|
|
|
ConfigurationFactory::getDefaultConfigurationLibrary( |
444
|
|
|
$magentoEdition, |
445
|
|
|
$command->getEntityTypeCode() |
446
|
|
|
) |
447
|
|
|
); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Return's the Magento Edition specific default libraries. Supported Magento Editions are CE or EE. |
452
|
|
|
* |
453
|
|
|
* @param string $magentoEdition The Magento Edition to return the libraries for |
454
|
|
|
* |
455
|
|
|
* @return array The Magento Edition specific default libraries |
456
|
|
|
* @throws \Exception Is thrown, if the passed Magento Edition is NOT supported |
457
|
|
|
*/ |
458
|
|
|
public static function getDefaultLibraries($magentoEdition) |
459
|
|
|
{ |
460
|
|
|
|
461
|
|
|
// query whether or not, default libraries for the passed edition are available |
462
|
|
|
if (isset(self::$defaultLibraries[$edition = strtolower($magentoEdition)])) { |
463
|
|
|
return self::$defaultLibraries[$edition]; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
// throw an exception, if the passed edition is not supported |
467
|
|
|
throw new \Exception( |
468
|
|
|
sprintf( |
469
|
|
|
'Default libraries for Magento \'%s\' not supported (MUST be one of CE or EE)', |
470
|
|
|
$magentoEdition |
471
|
|
|
) |
472
|
|
|
); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Return's the Magento Edition and entity type's specific default library that contains |
477
|
|
|
* the configuration file. |
478
|
|
|
* |
479
|
|
|
* @param string $magentoEdition The Magento Edition to return the default library for |
480
|
|
|
* @param string $entityTypeCode The entity type code to return the default library file for |
481
|
|
|
* |
482
|
|
|
* @return string The name of the library that contains the default configuration file for the passed Magento Edition and entity type code |
483
|
|
|
* @throws \Exception Is thrown, if no default configuration for the passed entity type code is available |
484
|
|
|
*/ |
485
|
|
|
public static function getDefaultConfigurationLibrary($magentoEdition, $entityTypeCode) |
486
|
|
|
{ |
487
|
|
|
|
488
|
|
|
// query whether or not, a default configuration file for the passed entity type is available |
489
|
|
|
if (isset(self::$defaultConfigurations[$edition = strtolower($magentoEdition)])) { |
490
|
|
|
if (isset(self::$defaultConfigurations[$edition][$entityTypeCode])) { |
491
|
|
|
return self::$defaultConfigurations[$edition][$entityTypeCode]; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
// throw an exception, if the passed entity type is not supported |
495
|
|
|
throw new \Exception( |
496
|
|
|
sprintf( |
497
|
|
|
'Entity Type Code \'%s\' not supported for Magento Edition \'%s\' (MUST be one of catalog_product, catalog_category or eav_attribute)', |
498
|
|
|
$edition, |
499
|
|
|
$entityTypeCode |
500
|
|
|
) |
501
|
|
|
); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
// throw an exception, if the passed edition is not supported |
505
|
|
|
throw new \Exception( |
506
|
|
|
sprintf( |
507
|
|
|
'Default configuration for Magento \'%s\' not supported (MUST be one of CE or EE)', |
508
|
|
|
$magentoEdition |
509
|
|
|
) |
510
|
|
|
); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* Return's the entity types specific default import directory. |
515
|
|
|
* |
516
|
|
|
* @param string $entityTypeCode The entity type code to return the default import directory for |
517
|
|
|
* |
518
|
|
|
* @return string The default default import directory |
519
|
|
|
* @throws \Exception Is thrown, if no default import directory for the passed entity type code is available |
520
|
|
|
*/ |
521
|
|
|
public static function getDefaultDirectory($entityTypeCode) |
522
|
|
|
{ |
523
|
|
|
|
524
|
|
|
// query whether or not, a default configuration file for the passed entity type is available |
525
|
|
|
if (isset(self::$defaultDirectories[$entityTypeCode])) { |
526
|
|
|
return self::$defaultDirectories[$entityTypeCode]; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
// throw an exception, if the passed entity type is not supported |
530
|
|
|
throw new \Exception( |
531
|
|
|
sprintf( |
532
|
|
|
'Entity Type Code \'%s\' not supported (MUST be one of catalog_product or catalog_category)', |
533
|
|
|
$entityTypeCode |
534
|
|
|
) |
535
|
|
|
); |
536
|
|
|
} |
537
|
|
|
} |
538
|
|
|
|