1 | <?php |
||
51 | abstract class AbstractImportCommand extends Command implements ImportCommandInterface |
||
52 | { |
||
53 | |||
54 | /** |
||
55 | * Configures the current command. |
||
56 | * |
||
57 | * @return void |
||
58 | * @see \Symfony\Component\Console\Command\Command::configure() |
||
59 | */ |
||
60 | protected function configure() |
||
61 | { |
||
62 | |||
63 | // initialize the command with the required/optional options |
||
64 | $this->addArgument( |
||
65 | InputArgumentKeys::OPERATION_NAME, |
||
66 | InputArgument::OPTIONAL, |
||
67 | 'The operation that has to be used for the import, one of "add-update", "replace" or "delete"', |
||
68 | OperationKeys::ADD_UPDATE |
||
69 | ) |
||
70 | ->addOption( |
||
71 | InputOptionKeys::INSTALLATION_DIR, |
||
72 | null, |
||
73 | InputOption::VALUE_REQUIRED, |
||
74 | 'The Magento installation directory to which the files has to be imported', |
||
75 | getcwd() |
||
76 | ) |
||
77 | ->addOption( |
||
78 | InputOptionKeys::SYSTEM_NAME, |
||
79 | null, |
||
80 | InputOption::VALUE_REQUIRED, |
||
81 | 'Specify the system name to use', |
||
82 | gethostname() |
||
83 | ) |
||
84 | ->addOption( |
||
85 | InputOptionKeys::PID_FILENAME, |
||
86 | null, |
||
87 | InputOption::VALUE_REQUIRED, |
||
88 | 'The explicit PID filename to use', |
||
89 | sprintf('%s/%s', sys_get_temp_dir(), Configuration::PID_FILENAME) |
||
90 | ) |
||
91 | ->addOption( |
||
92 | InputOptionKeys::MAGENTO_EDITION, |
||
93 | null, |
||
94 | InputOption::VALUE_REQUIRED, |
||
95 | 'The Magento edition to be used, either one of "CE" or "EE"' |
||
96 | ) |
||
97 | ->addOption( |
||
98 | InputOptionKeys::MAGENTO_VERSION, |
||
99 | null, |
||
100 | InputOption::VALUE_REQUIRED, |
||
101 | 'The Magento version to be used, e. g. "2.1.2"' |
||
102 | ) |
||
103 | ->addOption( |
||
104 | InputOptionKeys::CONFIGURATION, |
||
105 | null, |
||
106 | InputOption::VALUE_REQUIRED, |
||
107 | 'Specify the pathname to the configuration file to use' |
||
108 | ) |
||
109 | ->addOption( |
||
110 | InputOptionKeys::ENTITY_TYPE_CODE, |
||
111 | null, |
||
112 | InputOption::VALUE_REQUIRED, |
||
113 | 'Specify the entity type code to use, either one of "catalog_product", "catalog_category" or "eav_attribute"' |
||
114 | ) |
||
115 | ->addOption( |
||
116 | InputOptionKeys::SOURCE_DIR, |
||
117 | null, |
||
118 | InputOption::VALUE_REQUIRED, |
||
119 | 'The directory that has to be watched for new files' |
||
120 | ) |
||
121 | ->addOption( |
||
122 | InputOptionKeys::TARGET_DIR, |
||
123 | null, |
||
124 | InputOption::VALUE_REQUIRED, |
||
125 | 'The target directory with the files that has been imported' |
||
126 | ) |
||
127 | ->addOption( |
||
128 | InputOptionKeys::SOURCE_DATE_FORMAT, |
||
129 | null, |
||
130 | InputOption::VALUE_REQUIRED, |
||
131 | 'The date format used in the CSV file(s)' |
||
132 | ) |
||
133 | ->addOption( |
||
134 | InputOptionKeys::USE_DB_ID, |
||
135 | null, |
||
136 | InputOption::VALUE_REQUIRED, |
||
137 | 'The explicit database ID used for the actual import process' |
||
138 | ) |
||
139 | ->addOption( |
||
140 | InputOptionKeys::DB_PDO_DSN, |
||
141 | null, |
||
142 | InputOption::VALUE_REQUIRED, |
||
143 | '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' |
||
144 | ) |
||
145 | ->addOption( |
||
146 | InputOptionKeys::DB_USERNAME, |
||
147 | null, |
||
148 | InputOption::VALUE_REQUIRED, |
||
149 | 'The username used to connect to the Magento database' |
||
150 | ) |
||
151 | ->addOption( |
||
152 | InputOptionKeys::DB_PASSWORD, |
||
153 | null, |
||
154 | InputOption::VALUE_REQUIRED, |
||
155 | 'The password used to connect to the Magento database' |
||
156 | ) |
||
157 | ->addOption( |
||
158 | InputOptionKeys::LOG_LEVEL, |
||
159 | null, |
||
160 | InputOption::VALUE_REQUIRED, |
||
161 | 'The log level to use' |
||
162 | ) |
||
163 | ->addOption( |
||
164 | InputOptionKeys::DEBUG_MODE, |
||
165 | null, |
||
166 | InputOption::VALUE_REQUIRED, |
||
167 | 'Whether use the debug mode or not' |
||
168 | ); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Executes the current command. |
||
173 | * |
||
174 | * This method is not abstract because you can use this class |
||
175 | * as a concrete class. In this case, instead of defining the |
||
176 | * execute() method, you set the code to execute by passing |
||
177 | * a Closure to the setCode() method. |
||
178 | * |
||
179 | * @param \Symfony\Component\Console\Input\InputInterface $input An InputInterface instance |
||
180 | * @param \Symfony\Component\Console\Output\OutputInterface $output An OutputInterface instance |
||
181 | * |
||
182 | * @return null|int null or 0 if everything went fine, or an error code |
||
183 | * @throws \LogicException When this abstract method is not implemented |
||
184 | * @see \Symfony\Component\Console\Command\Command::execute() |
||
185 | */ |
||
186 | protected function execute(InputInterface $input, OutputInterface $output) |
||
313 | |||
314 | /** |
||
315 | * Return's the absolute path to the actual vendor directory. |
||
316 | * |
||
317 | * @return string The absolute path to the actual vendor directory |
||
318 | * @throws \Exception Is thrown, if none of the possible vendor directories can be found |
||
319 | */ |
||
320 | public function getVendorDir() |
||
345 | } |
||
346 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: