Issues (145)

src/Command/SetupCommand.php (1 issue)

1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 */
7
8
9
namespace Aimeos\Shop\Command;
10
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Input\InputArgument;
13
14
15
/**
16
 * Command for initializing or updating the Aimeos database tables
17
 */
18
class SetupCommand extends AbstractCommand
19
{
20
	/**
21
	 * The name and signature of the console command.
22
	 *
23
	 * @var string
24
	 */
25
	protected $signature = 'aimeos:setup
26
		{site? : Site for updating database entries}
27
		{tplsite=default : Site used as template for creating the new one}
28
		{--q : Quiet}
29
		{--v=v : Verbosity level}
30
		{--option= : Setup configuration, name and value are separated by colon like "setup/default/demo:1"}
31
	';
32
33
	/**
34
	 * The console command description.
35
	 *
36
	 * @var string
37
	 */
38
	protected $description = 'Initialize or update the Aimeos database tables';
39
40
41
	/**
42
	 * Execute the console command.
43
	 *
44
	 * @return mixed
45
	 */
46
	public function handle()
47
	{
48
		\Aimeos\MShop::cache( false );
49
		\Aimeos\MAdmin::cache( false );
50
51
		$template = $this->argument( 'tplsite' );
52
53
		if( ( $site = $this->argument( 'site' ) ) === null ) {
54
			$site = config( 'shop.mshop.locale.site', 'default' );
0 ignored issues
show
The call to config() has too many arguments starting with 'default'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
			$site = /** @scrutinizer ignore-call */ config( 'shop.mshop.locale.site', 'default' );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
55
		}
56
57
		$boostrap = $this->getLaravel()->make( 'aimeos' )->get();
58
		$ctx = $this->getLaravel()->make( 'aimeos.context' )->get( false, 'command' );
59
60
		$this->info( sprintf( 'Initializing or updating the Aimeos database tables for site "%1$s"', $site ) );
61
62
		\Aimeos\Setup::use( $boostrap )
63
			->verbose( $this->option( 'q' ) ? '' : $this->option( 'v' ) )
64
			->context( $this->addConfig( $ctx->setEditor( 'aimeos:setup' ) ) )
65
			->up( $site, $template );
66
	}
67
68
69
	/**
70
	 * Adds the configuration options from the input object to the given context
71
	 *
72
	 * @param \Aimeos\MShop\ContextIface $ctx Context object
73
	 */
74
	protected function addConfig( \Aimeos\MShop\ContextIface $ctx ) : \Aimeos\MShop\ContextIface
75
	{
76
		$config = $ctx->config();
77
78
		foreach( (array) $this->option( 'option' ) as $option )
79
		{
80
			list( $name, $value ) = explode( ':', $option );
81
			$config->set( $name, $value );
82
		}
83
84
		return $ctx;
85
	}
86
}
87