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 | {--action=migrate : Action name that should be executed, i.e. "migrate", "rollback", "clean"} |
||||||
34 | {--option= : Setup configuration, name and value are separated by ":" like "setup/default/demo:1"} |
||||||
35 | '; |
||||||
36 | |||||||
37 | /** |
||||||
38 | * The console command description. |
||||||
39 | * |
||||||
40 | * @var string |
||||||
41 | */ |
||||||
42 | protected $description = 'Initialize or update the Aimeos database tables'; |
||||||
43 | |||||||
44 | |||||||
45 | /** |
||||||
46 | * Execute the console command. |
||||||
47 | * |
||||||
48 | * @return mixed |
||||||
49 | */ |
||||||
50 | public function handle() |
||||||
51 | { |
||||||
52 | $ctx = $this->getLaravel()->make( 'aimeos.context' )->get( false, 'command' ); |
||||||
53 | $ctx->setEditor( 'aimeos:setup' ); |
||||||
54 | |||||||
55 | $config = $ctx->getConfig(); |
||||||
56 | $site = $this->argument( 'site' ); |
||||||
57 | $template = $this->argument( 'tplsite' ); |
||||||
58 | |||||||
59 | $config->set( 'setup/site', $site ); |
||||||
60 | $dbconfig = $this->getDbConfig( $config ); |
||||||
61 | $this->setOptions( $config ); |
||||||
62 | |||||||
63 | \Aimeos\MShop::cache( false ); |
||||||
64 | \Aimeos\MAdmin::cache( false ); |
||||||
65 | |||||||
66 | $taskPaths = $this->getLaravel()->make( 'aimeos' )->get()->getSetupPaths( $template ); |
||||||
67 | $manager = new \Aimeos\MW\Setup\Manager\Multiple( $ctx->getDatabaseManager(), $dbconfig, $taskPaths, $ctx ); |
||||||
68 | |||||||
69 | $this->info( sprintf( 'Initializing or updating the Aimeos database tables for site "%1$s"', $site ) ); |
||||||
70 | |||||||
71 | if( ( $task = $this->option( 'task' ) ) && is_array( $task ) ) { |
||||||
72 | $task = reset( $task ); |
||||||
73 | } |
||||||
74 | |||||||
75 | switch( $this->option( 'action' ) ) |
||||||
76 | { |
||||||
77 | case 'migrate': |
||||||
78 | $manager->migrate( $task ); |
||||||
79 | break; |
||||||
80 | case 'rollback': |
||||||
81 | $manager->rollback( $task ); |
||||||
0 ignored issues
–
show
|
|||||||
82 | break; |
||||||
83 | case 'clean': |
||||||
84 | $manager->clean( $task ); |
||||||
0 ignored issues
–
show
The method
clean() does not exist on Aimeos\MW\Setup\Manager\Multiple .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
85 | break; |
||||||
86 | default: |
||||||
87 | throw new \Exception( sprintf( 'Invalid setup action "%1$s"', $this->option( 'action' ) ) ); |
||||||
88 | } |
||||||
89 | } |
||||||
90 | |||||||
91 | |||||||
92 | /** |
||||||
93 | * Returns the database configuration from the config object. |
||||||
94 | * |
||||||
95 | * @param \Aimeos\MW\Config\Iface $conf Config object |
||||||
96 | * @return array Multi-dimensional associative list of database configuration parameters |
||||||
97 | */ |
||||||
98 | protected function getDbConfig( \Aimeos\MW\Config\Iface $conf ) |
||||||
99 | { |
||||||
100 | $dbconfig = $conf->get( 'resource', array() ); |
||||||
101 | |||||||
102 | foreach( $dbconfig as $rname => $dbconf ) |
||||||
103 | { |
||||||
104 | if( strncmp( $rname, 'db', 2 ) !== 0 ) { |
||||||
105 | unset( $dbconfig[$rname] ); |
||||||
106 | } |
||||||
107 | } |
||||||
108 | |||||||
109 | return $dbconfig; |
||||||
110 | } |
||||||
111 | |||||||
112 | |||||||
113 | /** |
||||||
114 | * Extracts the configuration options from the input object and updates the configuration values in the config object. |
||||||
115 | * |
||||||
116 | * @param \Aimeos\MW\Config\Iface $conf Configuration object |
||||||
117 | * @param array Associative list of database configurations |
||||||
118 | * @throws \RuntimeException If the format of the options is invalid |
||||||
119 | */ |
||||||
120 | protected function setOptions( \Aimeos\MW\Config\Iface $conf ) |
||||||
121 | { |
||||||
122 | foreach( (array) $this->option( 'option' ) as $option ) |
||||||
123 | { |
||||||
124 | list( $name, $value ) = explode( ':', $option ); |
||||||
125 | $conf->set( str_replace( '\\', '/', $name ), $value ); |
||||||
126 | } |
||||||
127 | } |
||||||
128 | } |
||||||
129 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.