ImportProductsCommand::configure()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.8571
c 0
b 0
f 0
ccs 0
cts 28
cp 0
cc 1
eloc 25
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Command\ImportProductsCommand
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-magento
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Command;
22
23
use Symfony\Component\Console\Command\Command;
24
use Symfony\Component\Console\Input\InputOption;
25
use Symfony\Component\Console\Input\InputArgument;
26
use Symfony\Component\Console\Input\InputInterface;
27
use Symfony\Component\Console\Output\OutputInterface;
28
use TechDivision\Import\App\Magento;
29
use TechDivision\Import\Utils\CommandNames;
30
use TechDivision\Import\Configuration\Jms\Configuration;
31
32
/**
33
 * The command implementation to import products.
34
 *
35
 * @author    Tim Wagner <[email protected]>
36
 * @copyright 2016 TechDivision GmbH <[email protected]>
37
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
38
 * @link      https://github.com/techdivision/import-cli-magento
39
 * @link      http://www.techdivision.com
40
 */
41
class ImportProductsCommand extends Command
42
{
43
44
    /**
45
     * The application instance.
46
     *
47
     * @var \TechDivision\Import\App\Magento
48
     */
49
    private $app;
50
51
    /**
52
     * Constructor to initialize the command.
53
     *
54
     * @param \TechDivision\Import\App\Magento $app The import application instance
55
     */
56
    public function __construct(agento $app) {
57
58
        // set passed instances
59
        $this->app = $app;
0 ignored issues
show
Documentation Bug introduced by
It seems like $app of type object<TechDivision\Import\Command\agento> is incompatible with the declared type object<TechDivision\Import\App\Magento> of property $app.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
61
        // call parent constructor
62
        parent::__construct();
63
    }
64
65
    /**
66
     * Configures the current command.
67
     *
68
     * @return void
69
     */
70
    protected function configure()
71
    {
72
73
        // initialize the array for the options
74
        $options = [
75
            new InputArgument(InputArgumentKeys::OPERATION_NAME, InputArgument::OPTIONAL, 'Operation that has to be executed', InputArgumentKeys::OPERATION_NAME_ARG_ADD_UPDATE),
76
            new InputOption(InputOptionKeys::INSTALLATION_DIR, null, InputOption::VALUE_REQUIRED, 'The magento installation directors to use', getcwd()),
77
            new InputOption(InputOptionKeys::CONFIGURATION, null, InputOption::VALUE_REQUIRED, 'Path to the configuration file'),
78
            new InputOption(InputOptionKeys::SYSTEM_NAME, null, InputOption::VALUE_REQUIRED,'Specify the system name to use', gethostname()),
79
            new InputOption(InputOptionKeys::PID_FILENAME, null,InputOption::VALUE_REQUIRED, 'The explicit PID filename to use', sprintf('%s/%s', sys_get_temp_dir(), Configuration::PID_FILENAME)),
80
            new InputOption(InputOptionKeys::MAGENTO_EDITION, null, InputOption::VALUE_REQUIRED, 'The Magento edition to be used, either one of "CE" or "EE"'),
81
            new InputOption(InputOptionKeys::MAGENTO_VERSION,  null, InputOption::VALUE_REQUIRED,  'The Magento version to be used, e. g. "2.1.2"'),
82
            new InputOption(InputOptionKeys::CONFIGURATION, null, InputOption::VALUE_REQUIRED, 'Specify the pathname to the configuration file to use'),
83
            new InputOption(InputOptionKeys::ENTITY_TYPE_CODE, null, InputOption::VALUE_REQUIRED, 'Specify the entity type code to use, either one of "catalog_product", "catalog_category" or "eav_attribute"'),
84
            new InputOption(InputOptionKeys::SOURCE_DIR, null, InputOption::VALUE_REQUIRED, 'The directory that has to be watched for new files'),
85
            new InputOption(InputOptionKeys::TARGET_DIR, null, InputOption::VALUE_REQUIRED, 'The target directory with the files that has been imported'),
86
            new InputOption(InputOptionKeys::ARCHIVE_DIR, null, InputOption::VALUE_REQUIRED, 'The directory the imported files will be archived in'),
87
            new InputOption(InputOptionKeys::SOURCE_DATE_FORMAT, null, InputOption::VALUE_REQUIRED, 'The date format used in the CSV file(s)'),
88
            new InputOption(InputOptionKeys::USE_DB_ID, null, InputOption::VALUE_REQUIRED, 'The explicit database ID used for the actual import process'),
89
            new InputOption(InputOptionKeys::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'),
90
            new InputOption(InputOptionKeys::DB_USERNAME, null, InputOption::VALUE_REQUIRED, 'The username used to connect to the Magento database'),
91
            new InputOption(InputOptionKeys::DB_PASSWORD, null, InputOption::VALUE_REQUIRED, 'The password used to connect to the Magento database'),
92
            new InputOption(InputOptionKeys::LOG_LEVEL, null, InputOption::VALUE_REQUIRED, 'The log level to use'),
93
            new InputOption(InputOptionKeys::DEBUG_MODE, null, InputOption::VALUE_REQUIRED, 'Whether use the debug mode or not')
94
        ];
95
96
        // initialize the command
97
        $this->setName(CommandNames::IMPORT_PRODUCTS)
98
             ->setDescription('Imports products in the configured Magento 2 instance')
99
             ->setDefinition($options);
100
101
        // call parent method
102
        parent::configure();
103
    }
104
105
    /**
106
     * Executes the current command.
107
     *
108
     * This method is not abstract because you can use this class
109
     * as a concrete class. In this case, instead of defining the
110
     * execute() method, you set the code to execute by passing
111
     * a Closure to the setCode() method.
112
     *
113
     * @param \Symfony\Component\Console\Input\InputInterface   $input  An InputInterface instance
114
     * @param \Symfony\Component\Console\Output\OutputInterface $output An OutputInterface instance
115
     *
116
     * @return null|int null or 0 if everything went fine, or an error code
117
     * @throws \Symfony\Component\Console\Exception\LogicException When this abstract method is not implemented
118
     * @see setCode()
119
     */
120
    protected function execute(InputInterface $input, OutputInterface $output)
121
    {
122
123
        $this->app->process();
124
125
        $output->writeln('<info>Finished import!</info>');
126
    }
127
}
128