Issues (153)

Classes/Command/SetupCommand.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * @license GPLv3, http://www.gnu.org/copyleft/gpl.html
5
 * @copyright Aimeos (aimeos.org), 2018
6
 * @package TYPO3
7
 */
8
9
10
namespace Aimeos\Aimeos\Command;
11
12
13
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
20
/**
21
 * Performs the database initialization and update
22
 *
23
 * @package TYPO3
24
 */
25
class SetupCommand extends Command
26
{
27
    /**
28
     * Configures the command name and description.
29
     */
30
    protected function configure()
31
    {
32
        $this->setName('aimeos:setup');
33
        $this->setDescription('Initialize or update the Aimeos database tables');
34
        $this->addArgument('site', InputArgument::OPTIONAL, 'Site for updating database entries', 'default');
35
        $this->addArgument('tplsite', InputArgument::OPTIONAL, 'Template site for creating or updating database entries', 'default');
36
        $this->addOption('option', null, InputOption::VALUE_REQUIRED, 'Optional setup configuration, name and value are separated by ":" like "setup/default/demo:1"', []);
37
        $this->addOption('v', null, InputOption::VALUE_OPTIONAL, 'Verbosity level, "v", "vv" or "vvv"', 'vv');
38
        $this->addOption('q', null, InputOption::VALUE_NONE, 'Quiet mode without any output');
39
    }
40
41
42
    /**
43
     * Executes the database initialization and update.
44
     *
45
     * @param InputInterface $input Input object
46
     * @param OutputInterface $output Output object
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        \Aimeos\MShop::cache(false);
51
        \Aimeos\MAdmin::cache(false);
52
53
        $site = $input->getArgument('site');
54
        $template = $input->getArgument('tplsite');
55
56
        $config = \Aimeos\Aimeos\Base::config();
57
        $boostrap = \Aimeos\Aimeos\Base::aimeos();
58
        $ctx = \Aimeos\Aimeos\Base::context($config)->setEditor('aimeos:setup');
59
60
        $output->writeln(sprintf('Initializing or updating the Aimeos database tables for site <info>%1$s</info>', $site));
61
62
        \Aimeos\Setup::use($boostrap)
63
            ->context($this->addConfig($ctx->setEditor('aimeos:setup'), $input->getOption('option')))
64
            ->verbose($input->getOption('q') ? '' : $input->getOption('v'))
65
            ->up($site, $template);
66
67
        return 0;
68
    }
69
70
71
    /**
72
     * Adds the configuration options from the input object to the given context
73
     *
74
     * @param array|string $options Input object
75
     * @param \Aimeos\MShop\ContextIface $ctx Context object
76
     * @return array Associative list of key/value pairs of configuration options
77
     */
78
    protected function addConfig(\Aimeos\MShop\ContextIface $ctx, $options) : \Aimeos\MShop\ContextIface
79
    {
80
        $config = $ctx->config();
81
82
        foreach ((array) $options as $option) {
83
            list($name, $value) = explode(':', $option);
84
            $config->set($name, $value);
85
        }
86
87
        return $ctx;
88
    }
89
}
90