1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2016 |
6
|
|
|
* @package symfony |
7
|
|
|
* @subpackage Command |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\ShopBundle\Command; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Performs the database initialization and update. |
21
|
|
|
* |
22
|
|
|
* @package symfony |
23
|
|
|
* @subpackage Command |
24
|
|
|
*/ |
25
|
|
|
class SetupCommand extends Command |
26
|
|
|
{ |
27
|
|
|
protected static $defaultName = 'aimeos:setup'; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Configures the command name and description. |
32
|
|
|
*/ |
33
|
|
|
protected function configure() |
34
|
|
|
{ |
35
|
|
|
$this->setName( self::$defaultName ); |
36
|
|
|
$this->setDescription( 'Initialize or update the Aimeos database tables' ); |
37
|
|
|
$this->addArgument( 'site', InputArgument::OPTIONAL, 'Site for updating database entries', 'default' ); |
38
|
|
|
$this->addArgument( 'tplsite', InputArgument::OPTIONAL, 'Template site for creating or updating database entries', 'default' ); |
39
|
|
|
$this->addOption( 'option', null, InputOption::VALUE_REQUIRED, 'Optional setup configuration, name and value are separated by ":" like "setup/default/demo:1"', array() ); |
40
|
|
|
$this->addOption( 'action', null, InputOption::VALUE_REQUIRED, 'Action name that should be executed, i.e. "migrate", "rollback", "clean"', 'migrate' ); |
41
|
|
|
$this->addOption( 'task', null, InputOption::VALUE_REQUIRED, 'Name of the setup task that should be executed', null ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Executes the database initialization and update. |
47
|
|
|
* |
48
|
|
|
* @param InputInterface $input Input object |
49
|
|
|
* @param OutputInterface $output Output object |
50
|
|
|
*/ |
51
|
|
|
protected function execute( InputInterface $input, OutputInterface $output ) |
52
|
|
|
{ |
53
|
|
|
$ctx = $this->getContainer()->get( 'aimeos.context' )->get( false, 'command' ); |
54
|
|
|
$ctx->setEditor( 'aimeos:setup' ); |
55
|
|
|
|
56
|
|
|
$config = $ctx->getConfig(); |
57
|
|
|
$site = $input->getArgument( 'site' ); |
58
|
|
|
$tplsite = $input->getArgument( 'tplsite' ); |
59
|
|
|
|
60
|
|
|
$config->set( 'setup/site', $site ); |
61
|
|
|
$dbconfig = $this->getDbConfig( $config ); |
62
|
|
|
$this->setOptions( $config, $input ); |
63
|
|
|
|
64
|
|
|
\Aimeos\MShop::cache( false ); |
65
|
|
|
\Aimeos\MAdmin::cache( false ); |
66
|
|
|
|
67
|
|
|
$taskPaths = $this->getContainer()->get( 'aimeos' )->get()->getSetupPaths( $tplsite ); |
68
|
|
|
$manager = new \Aimeos\MW\Setup\Manager\Multiple( $ctx->getDatabaseManager(), $dbconfig, $taskPaths, $ctx ); |
69
|
|
|
|
70
|
|
|
$output->writeln( sprintf( 'Initializing or updating the Aimeos database tables for site <info>%1$s</info>', $site ) ); |
|
|
|
|
71
|
|
|
|
72
|
|
|
if( ( $task = $input->getOption( 'task' ) ) && is_array( $task ) ) { |
73
|
|
|
$task = reset( $task ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
switch( $input->getOption( 'action' ) ) |
77
|
|
|
{ |
78
|
|
|
case 'migrate': |
79
|
|
|
$manager->migrate( $task ); |
80
|
|
|
break; |
81
|
|
|
case 'rollback': |
82
|
|
|
$manager->rollback( $task ); |
|
|
|
|
83
|
|
|
break; |
84
|
|
|
case 'clean': |
85
|
|
|
$manager->clean( $task ); |
|
|
|
|
86
|
|
|
break; |
87
|
|
|
default: |
88
|
|
|
throw new \Exception( sprintf( 'Invalid setup action "%1$s"', $input->getOption( 'action' ) ) ); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the database configuration from the config object. |
95
|
|
|
* |
96
|
|
|
* @param \Aimeos\MW\Config\Iface $conf Config object |
97
|
|
|
* @return array Multi-dimensional associative list of database configuration parameters |
98
|
|
|
*/ |
99
|
|
|
protected function getDbConfig( \Aimeos\MW\Config\Iface $conf ) : array |
100
|
|
|
{ |
101
|
|
|
$dbconfig = $conf->get( 'resource', array() ); |
102
|
|
|
|
103
|
|
|
foreach( $dbconfig as $rname => $dbconf ) |
104
|
|
|
{ |
105
|
|
|
if( strncmp( $rname, 'db', 2 ) !== 0 ) { |
106
|
|
|
unset( $dbconfig[$rname] ); |
107
|
|
|
} else { |
108
|
|
|
$conf->set( 'resource/' . $rname . '/limit', 5 ); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $dbconfig; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Extracts the configuration options from the input object and updates the configuration values in the config object. |
118
|
|
|
* |
119
|
|
|
* @param \Aimeos\MW\Config\Iface $conf Configuration object |
120
|
|
|
* @param InputInterface $input Input object |
121
|
|
|
*/ |
122
|
|
|
protected function setOptions( \Aimeos\MW\Config\Iface $conf, InputInterface $input ) |
123
|
|
|
{ |
124
|
|
|
foreach( (array) $input->getOption( 'option' ) as $option ) |
125
|
|
|
{ |
126
|
|
|
list( $name, $value ) = explode( ':', $option ); |
127
|
|
|
$conf->set( str_replace( '\\', '/', $name ), $value ); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|