SetupCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 2
A __construct() 0 4 1
A configure() 0 9 1
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2014-2023
6
 * @package symfony
7
 * @subpackage Command
8
 */
9
10
11
namespace Aimeos\ShopBundle\Command;
12
13
use Symfony\Component\Console\Attribute\AsCommand;
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
use Symfony\Component\DependencyInjection\Container;
19
20
21
/**
22
 * Performs the database initialization and update.
23
 *
24
 * @package symfony
25
 * @subpackage Command
26
 */
27
#[AsCommand(name: 'aimeos:setup', description: 'Initialize or update the Aimeos database tables')]
28
class SetupCommand extends Command
29
{
30
	private $container;
31
	protected static $defaultName = 'aimeos:setup';
32
33
34
	public function __construct( Container $container )
35
	{
36
		parent::__construct();
37
		$this->container = $container;
38
	}
39
40
41
	/**
42
	 * Configures the command name and description.
43
	 */
44
	protected function configure()
45
	{
46
		$this->setName( self::$defaultName );
47
		$this->setDescription( 'Initialize or update the Aimeos database tables' );
48
		$this->addArgument( 'site', InputArgument::OPTIONAL, 'Site for updating database entries', 'default' );
49
		$this->addArgument( 'tplsite', InputArgument::OPTIONAL, 'Template site for creating or updating database entries', 'default' );
50
		$this->addOption( 'option', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Optional setup configuration, name and value are separated by ":" like "setup/default/demo:1"', [] );
51
		$this->addOption( 'q', null, InputOption::VALUE_NONE, 'Quiet (suppress output)', null );
52
		$this->addOption( 'v', null, InputOption::VALUE_OPTIONAL, 'Verbosity level', 'v' );
53
	}
54
55
56
	/**
57
	 * Executes the database initialization and update.
58
	 *
59
	 * @param InputInterface $input Input object
60
	 * @param OutputInterface $output Output object
61
	 */
62
	protected function execute( InputInterface $input, OutputInterface $output )
63
	{
64
		$site = $input->getArgument( 'site' );
65
		$tplsite = $input->getArgument( 'tplsite' );
66
67
		\Aimeos\MShop::cache( false );
68
		\Aimeos\MAdmin::cache( false );
69
70
		$boostrap = $this->container->get( 'aimeos' )->get();
71
		$ctx = $this->container->get( 'aimeos.context' )->get( false, 'command' );
72
73
		$output->writeln( sprintf( 'Initializing or updating the Aimeos database tables for site <info>%1$s</info>', $site ) );
74
75
		\Aimeos\Setup::use( $boostrap )
76
			->verbose( $input->getOption( 'q' ) ? '' : $input->getOption( 'v' ) )
77
			->context( $this->addConfig( $ctx->setEditor( 'aimeos:setup' ), $input ) )
78
			->up( $site, $tplsite );
79
80
		return 0;
81
	}
82
}
83