|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Cli\Command\ImportCommandTrait |
|
5
|
|
|
* |
|
6
|
|
|
* PHP version 7 |
|
7
|
|
|
* |
|
8
|
|
|
* @author Tim Wagner <[email protected]> |
|
9
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
10
|
|
|
* @license https://opensource.org/licenses/MIT |
|
11
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
|
12
|
|
|
* @link http://www.techdivision.com |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Cli\Command; |
|
16
|
|
|
|
|
17
|
|
|
use Ramsey\Uuid\Uuid; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
19
|
|
|
use Symfony\Component\Console\Command\Command; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
22
|
|
|
use TechDivision\Import\Utils\InputOptionKeysInterface; |
|
23
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration; |
|
24
|
|
|
use TechDivision\Import\Cli\Utils\DependencyInjectionKeys; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The abstract import command implementation. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Tim Wagner <[email protected]> |
|
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license https://opensource.org/licenses/MIT |
|
32
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
|
33
|
|
|
* @link http://www.techdivision.com |
|
34
|
|
|
*/ |
|
35
|
|
|
abstract class AbstractImportCommand extends Command |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Configures the current command. |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
* @see \Symfony\Component\Console\Command\Command::configure() |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function configure() |
|
45
|
|
|
{ |
|
46
|
|
|
|
|
47
|
|
|
// configure the command |
|
48
|
|
|
$this->addOption(InputOptionKeysInterface::SERIAL, null, InputOption::VALUE_REQUIRED, 'The unique identifier of this import process', Uuid::uuid4()->__toString()) |
|
49
|
|
|
->addOption(InputOptionKeysInterface::INSTALLATION_DIR, null, InputOption::VALUE_REQUIRED, 'The Magento installation directory to which the files has to be imported', getcwd()) |
|
50
|
|
|
->addOption(InputOptionKeysInterface::CONFIGURATION_DIR, null, InputOption::VALUE_OPTIONAL, 'The Magento configuration') |
|
51
|
|
|
->addOption(InputOptionKeysInterface::SYSTEM_NAME, null, InputOption::VALUE_REQUIRED, 'Specify the system name to use', gethostname()) |
|
52
|
|
|
->addOption(InputOptionKeysInterface::PID_FILENAME, null, InputOption::VALUE_REQUIRED, 'The explicit PID filename to use', sprintf('%s/%s', sys_get_temp_dir(), Configuration::PID_FILENAME)) |
|
53
|
|
|
->addOption(InputOptionKeysInterface::CACHE_ENABLED, null, InputOption::VALUE_REQUIRED, 'Whether or not the cache functionality for the import should be enabled') |
|
54
|
|
|
->addOption(InputOptionKeysInterface::RENDER_VALIDATION_ISSUES, null, InputOption::VALUE_REQUIRED, 'The number of validation issues that has to be rendered on the CLI', 100) |
|
55
|
|
|
->addOption(InputOptionKeysInterface::MAGENTO_EDITION, null, InputOption::VALUE_REQUIRED, 'The Magento edition to be used, either one of "CE" or "EE" (will be autodetected if possible and not specified)') |
|
56
|
|
|
->addOption(InputOptionKeysInterface::MAGENTO_VERSION, null, InputOption::VALUE_REQUIRED, 'The Magento version to be used, e. g. "2.1.2"') |
|
57
|
|
|
->addOption(InputOptionKeysInterface::CONFIGURATION, null, InputOption::VALUE_REQUIRED, 'Specify the pathname to the configuration file to use') |
|
58
|
|
|
->addOption(InputOptionKeysInterface::CUSTOM_CONFIGURATION_DIR, null, InputOption::VALUE_REQUIRED, 'The path to the custom configuration directory') |
|
59
|
|
|
->addOption(InputOptionKeysInterface::CUSTOM_CONFIGURATION_PUBLIC_DIR, null, InputOption::VALUE_OPTIONAL, 'The path to the custom configuration public directory') |
|
60
|
|
|
->addOption(InputOptionKeysInterface::SOURCE_DIR, null, InputOption::VALUE_REQUIRED, 'The directory that has to be watched for new files') |
|
61
|
|
|
->addOption(InputOptionKeysInterface::TARGET_DIR, null, InputOption::VALUE_REQUIRED, 'The target directory with the files that has been imported') |
|
62
|
|
|
->addOption(InputOptionKeysInterface::ARCHIVE_DIR, null, InputOption::VALUE_REQUIRED, 'The directory the imported files will be archived in') |
|
63
|
|
|
->addOption(InputOptionKeysInterface::ARCHIVE_ARTEFACTS, null, InputOption::VALUE_REQUIRED, 'Whether or not files should be archived') |
|
64
|
|
|
->addOption(InputOptionKeysInterface::CLEAR_ARTEFACTS, null, InputOption::VALUE_REQUIRED, 'Whether or not artefacts should be cleared') |
|
65
|
|
|
->addOption(InputOptionKeysInterface::USE_DB_ID, null, InputOption::VALUE_REQUIRED, 'The explicit database ID used for the actual import process') |
|
66
|
|
|
->addOption(InputOptionKeysInterface::DB_PDO_DSN, null, InputOption::VALUE_REQUIRED, 'The DSN used to connect to the Magento database where the data has to be imported, e. g. mysql:host=127.0.0.1;dbname=magento;charset=utf8') |
|
67
|
|
|
->addOption(InputOptionKeysInterface::DB_USERNAME, null, InputOption::VALUE_REQUIRED, 'The username used to connect to the Magento database') |
|
68
|
|
|
->addOption(InputOptionKeysInterface::DB_PASSWORD, null, InputOption::VALUE_REQUIRED, 'The password used to connect to the Magento database') |
|
69
|
|
|
->addOption(InputOptionKeysInterface::DB_TABLE_PREFIX, null, InputOption::VALUE_REQUIRED, 'The table prefix used by the Magento database') |
|
70
|
|
|
->addOption(InputOptionKeysInterface::LOG_LEVEL, null, InputOption::VALUE_REQUIRED, 'The log level to use') |
|
71
|
|
|
->addOption(InputOptionKeysInterface::DEBUG_MODE, null, InputOption::VALUE_REQUIRED, 'Whether or not debug mode should be used') |
|
72
|
|
|
->addOption(InputOptionKeysInterface::SINGLE_TRANSACTION, null, InputOption::VALUE_REQUIRED, 'Whether or not the import should be wrapped within a single transaction') |
|
73
|
|
|
->addOption(InputOptionKeysInterface::PARAMS, null, InputOption::VALUE_REQUIRED, 'Additional options passed as a string (MUST have the same format as the used configuration file has)') |
|
74
|
|
|
->addOption(InputOptionKeysInterface::PARAMS_FILE, null, InputOption::VALUE_REQUIRED, 'Additional options passed as pathname') |
|
75
|
|
|
->addOption(InputOptionKeysInterface::MOVE_FILES_PREFIX, null, InputOption::VALUE_REQUIRED, 'Prefix of the files to move (defaults to the prefix of the first of the first plugin subject)') |
|
76
|
|
|
->addOption(InputOptionKeysInterface::EMPTY_ATTRIBUTE_VALUE_CONSTANT, null, InputOption::VALUE_REQUIRED, 'Value to define empty value to remove EAV attributes values in categories, products and customers') |
|
77
|
|
|
->addOption(InputOptionKeysInterface::STRICT_MODE, null, InputOption::VALUE_REQUIRED, 'Whether or not strict mode should be used') |
|
78
|
|
|
->addOption(InputOptionKeysInterface::LOG_FILE, null, InputOption::VALUE_REQUIRED, 'The log file to use'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Return's the container instance. |
|
83
|
|
|
* |
|
84
|
|
|
* @return \Symfony\Component\DependencyInjection\ContainerInterface The container instance |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function getContainer() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->getApplication()->getContainer(); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Executes the current command. |
|
93
|
|
|
* |
|
94
|
|
|
* This method is not abstract because you can use this class |
|
95
|
|
|
* as a concrete class. In this case, instead of defining the |
|
96
|
|
|
* execute() method, you set the code to execute by passing |
|
97
|
|
|
* a Closure to the setCode() method. |
|
98
|
|
|
* |
|
99
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input An InputInterface instance |
|
100
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output An OutputInterface instance |
|
101
|
|
|
* |
|
102
|
|
|
* @return null|int null or 0 if everything went fine, or an error code |
|
103
|
|
|
* @throws \LogicException When this abstract method is not implemented |
|
104
|
|
|
* @see \Symfony\Component\Console\Command\Command::execute() |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
107
|
|
|
{ |
|
108
|
|
|
|
|
109
|
|
|
// initialize the configuration instance |
|
110
|
|
|
$this->getContainer()->get(DependencyInjectionKeys::CONFIGURATION); |
|
111
|
|
|
|
|
112
|
|
|
// execute the appliation instance and return the exit code |
|
113
|
|
|
return $this->getContainer()->get(DependencyInjectionKeys::SIMPLE)->process($input->getOption(InputOptionKeysInterface::SERIAL)); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|