Passed
Push — master ( 105c69...b68509 )
by Aimeos
05:51
created

src/Aimeos/Shop/Command/SetupCommand.php (3 issues)

Labels
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Command
8
 */
9
10
11
namespace Aimeos\Shop\Command;
12
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Input\InputArgument;
15
16
17
/**
18
 * Command for initializing or updating the Aimeos database tables
19
 * @package laravel
20
 * @subpackage Command
21
 */
22
class SetupCommand extends AbstractCommand
23
{
24
	/**
25
	 * The name and signature of the console command.
26
	 *
27
	 * @var string
28
	 */
29
	protected $signature = 'aimeos:setup
30
		{site=default : Site for updating database entries}
31
		{tplsite=default : Site used as template for creating the new one}
32
		{--task= : Name of the setup task that should be executed}
33
		{--option= : Setup configuration, name and value are separated by ":" like "setup/default/demo:1"}
34
	';
35
36
	/**
37
	 * The console command description.
38
	 *
39
	 * @var string
40
	 */
41
	protected $description = 'Initialize or update the Aimeos database tables';
42
43
44
	/**
45
	 * Execute the console command.
46
	 *
47
	 * @return mixed
48
	 */
49
	public function handle()
50
	{
51
		$ctx = $this->getLaravel()->make( 'aimeos.context' )->get( false, 'command' );
52
		$ctx->setEditor( 'aimeos:setup' );
53
54
		$config = $ctx->getConfig();
55
		$site = $this->argument( 'site' );
56
		$template = $this->argument( 'tplsite' );
57
58
		$task = $this->option( 'task' );
59
60
		$config->set( 'setup/site', $site );
61
		$dbconfig = $this->getDbConfig( $config );
62
		$this->setOptions( $config );
63
64
		\Aimeos\MShop::cache( false );
65
		\Aimeos\MAdmin::cache( false );
66
67
		$taskPaths = $this->getLaravel()->make( 'aimeos' )->get()->getSetupPaths( $template );
0 ignored issues
show
It seems like $template can also be of type string[]; however, parameter $site of Aimeos\Bootstrap::getSetupPaths() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

67
		$taskPaths = $this->getLaravel()->make( 'aimeos' )->get()->getSetupPaths( /** @scrutinizer ignore-type */ $template );
Loading history...
68
		$manager = new \Aimeos\MW\Setup\Manager\Multiple( $ctx->getDatabaseManager(), $dbconfig, $taskPaths, $ctx );
69
70
		$this->info( sprintf( 'Initializing or updating the Aimeos database tables for site "%1$s"', $site ) );
0 ignored issues
show
It seems like $site can also be of type string[]; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

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

70
		$this->info( sprintf( 'Initializing or updating the Aimeos database tables for site "%1$s"', /** @scrutinizer ignore-type */ $site ) );
Loading history...
71
72
		$manager->migrate( $task );
73
	}
74
75
76
	/**
77
	 * Returns the database configuration from the config object.
78
	 *
79
	 * @param \Aimeos\MW\Config\Iface $conf Config object
80
	 * @return array Multi-dimensional associative list of database configuration parameters
81
	 */
82
	protected function getDbConfig( \Aimeos\MW\Config\Iface $conf ) : array
83
	{
84
		$dbconfig = $conf->get( 'resource', array() );
85
86
		foreach( $dbconfig as $rname => $dbconf )
87
		{
88
			if( strncmp( $rname, 'db', 2 ) !== 0 ) {
89
				unset( $dbconfig[$rname] );
90
			} else {
91
				$conf->set( 'resource/' . $rname . '/limit', 5 );
92
			}
93
		}
94
95
		return $dbconfig;
96
	}
97
98
99
	/**
100
	 * Extracts the configuration options from the input object and updates the configuration values in the config object.
101
	 *
102
	 * @param \Aimeos\MW\Config\Iface $conf Configuration object
103
	 * @param array Associative list of database configurations
0 ignored issues
show
The type Aimeos\Shop\Command\Associative 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...
104
	 * @throws \RuntimeException If the format of the options is invalid
105
	 */
106
	protected function setOptions( \Aimeos\MW\Config\Iface $conf )
107
	{
108
		foreach( (array) $this->option( 'option' ) as $option )
109
		{
110
			list( $name, $value ) = explode( ':', $option );
111
			$conf->set( str_replace( '\\', '/', $name ), $value );
112
		}
113
	}
114
}
115