1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace agoalofalife\Commands; |
4
|
|
|
|
5
|
|
|
use agoalofalife\CapsuleSettings; |
6
|
|
|
use agoalofalife\database\migrations\CitiesMigration; |
7
|
|
|
use agoalofalife\database\migrations\CountryMigration; |
8
|
|
|
use agoalofalife\database\migrations\RegionsMigration; |
9
|
|
|
use agoalofalife\database\seeds\CitiesTableSeeder; |
10
|
|
|
use agoalofalife\database\seeds\CountryTableSeeder; |
11
|
|
|
use agoalofalife\database\seeds\RegionsTableSeeder; |
12
|
|
|
use agoalofalife\ManagerMigrations; |
13
|
|
|
use agoalofalife\ManagerSeeder; |
14
|
|
|
use agoalofalife\Support\Local; |
15
|
|
|
use Illuminate\Database\Capsule\Manager; |
16
|
|
|
use Symfony\Component\Console\Command\Command; |
17
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
18
|
|
|
use Symfony\Component\Console\Helper\Table; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
22
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
23
|
|
|
use Symfony\Component\Console\Question\Question; |
24
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class InstallCommand extends Command |
28
|
|
|
{ |
29
|
|
|
protected $settings; |
30
|
|
|
|
31
|
1 |
|
protected function configure() : void |
32
|
|
|
{ |
33
|
1 |
|
$this->setName('install')->setHelp('Sets up tables with the regions, cities and so on..'); |
34
|
1 |
|
} |
35
|
|
|
|
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
$style = new OutputFormatterStyle('black', 'yellow', array('bold', 'blink')); |
40
|
|
|
$output->getFormatter()->setStyle('fire', $style); |
41
|
|
|
|
42
|
|
|
$output->writeln([ |
|
|
|
|
43
|
|
|
'<fire>Hi let\'s start to do the migration!</fire>', |
44
|
|
|
'======================================' |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
$helper = $this->getHelper('question'); |
48
|
|
|
$question = new ChoiceQuestion( |
49
|
|
|
'Please choose your database type :', |
50
|
|
|
array('mysql', 'postgres'), |
51
|
|
|
0 |
52
|
|
|
); |
53
|
|
|
$question->setErrorMessage('Database %s is invalid.'); |
54
|
|
|
// get type database |
55
|
|
|
$this->settings['databaseType'] = $helper->ask($input, $output, $question); |
56
|
|
|
|
57
|
|
|
$output->writeln(''); |
58
|
|
|
$output->writeln( " You have just selected: <info>{$this->settings['databaseType']}</info>"); |
59
|
|
|
|
60
|
|
|
$helper = $this->getHelper('question'); |
61
|
|
|
$question = new Question("Enter <info>host</info> for database , please : ", 'localhost'); |
62
|
|
|
|
63
|
|
|
// get host |
64
|
|
|
$this->settings['host'] = $helper->ask($input, $output, $question); |
65
|
|
|
$output->writeln( " You have just selected: <info>{$this->settings['host']} </info>"); |
66
|
|
|
|
67
|
|
|
$output->writeln(''); |
68
|
|
|
$helper = $this->getHelper('question'); |
69
|
|
|
$question = new Question("Enter <info>database name</info>, please : "); |
70
|
|
|
|
71
|
|
|
// get name database |
72
|
|
|
$this->settings['databaseName'] = $helper->ask($input, $output, $question); |
73
|
|
|
$output->writeln( " You have just selected: <info>{$this->settings['databaseName']} </info>"); |
74
|
|
|
|
75
|
|
|
$output->writeln(''); |
76
|
|
|
$helper = $this->getHelper('question'); |
77
|
|
|
$question = new Question("Enter <info>database username</info>, please : "); |
78
|
|
|
|
79
|
|
|
//get username in database |
80
|
|
|
$this->settings['databaseUsername'] = $helper->ask($input, $output, $question); |
81
|
|
|
$output->writeln( " You have just selected: <info>{$this->settings['databaseUsername']} </info>"); |
82
|
|
|
|
83
|
|
|
$output->writeln(''); |
84
|
|
|
$helper = $this->getHelper('question'); |
85
|
|
|
$question = new Question("Enter <info>database password</info>, please : "); |
86
|
|
|
$question->setHidden(true); |
87
|
|
|
$question->setHiddenFallback(false); |
88
|
|
|
|
89
|
|
|
// get password |
90
|
|
|
$this->settings['databasePassword'] = $helper->ask($input, $output, $question); |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
$table = new Table($output); |
94
|
|
|
$table->setHeaders(array('name', 'value')) |
95
|
|
|
->setRows(array( |
96
|
|
|
array('Type database', $this->settings['databaseType']), |
97
|
|
|
array('Host database', $this->settings['host']), |
98
|
|
|
array('Name database', $this->settings['databaseName']), |
99
|
|
|
array('Username database', $this->settings['databaseUsername']) |
100
|
|
|
)); |
101
|
|
|
|
102
|
|
|
$table->render(); |
103
|
|
|
|
104
|
|
|
$helper = $this->getHelper('question'); |
105
|
|
|
$question = new ConfirmationQuestion("<question>Are you sure?? y/n</question>", false); |
106
|
|
|
|
107
|
|
|
if (!$helper->ask($input, $output, $question)) { |
108
|
|
|
return; |
109
|
|
|
} |
110
|
|
|
// connection database |
111
|
|
|
$capsule = new CapsuleSettings(new Manager()); |
112
|
|
|
$capsule->settings( $this->settings ); |
113
|
|
|
$capsule->checkConnection(); |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
$output->writeln(['','', '<info>Then go ahead!</info>']); |
|
|
|
|
117
|
|
|
|
118
|
|
|
$helper = $this->getHelper('question'); |
119
|
|
|
$question = new ChoiceQuestion( |
120
|
|
|
'Please select your native language :', |
121
|
|
|
array(0 => 'ru', 'en', 'ua', 'be', 'es', 'fi', 'de', 'it'), |
122
|
|
|
0 |
123
|
|
|
); |
124
|
|
|
$question->setErrorMessage('Local %s is invalid.'); |
125
|
|
|
|
126
|
|
|
// get native language |
127
|
|
|
$this->settings['localization'] = $helper->ask($input, $output, $question); |
128
|
|
|
(new Local())->setLocal($this->settings['localization']); |
129
|
|
|
|
130
|
|
|
$helper = $this->getHelper('question'); |
131
|
|
|
$question = new Question("Enter <info> the country you wish to migrate</info>, please : "); |
132
|
|
|
$output->writeln('<comment>the list of countries you can see here 3166-1 alpha-2</comment>'); |
133
|
|
|
$output->writeln('<comment>you can specify multiple countries separated by commas</comment>'); |
134
|
|
|
$output->writeln('<comment>example EN, RU</comment>'); |
135
|
|
|
|
136
|
|
|
// the list of countries that need to migrate |
137
|
|
|
$this->settings['country'] = $helper->ask($input, $output, $question); |
138
|
|
|
$output->writeln( " You have just selected: <info>{$this->settings['country']} </info>"); |
139
|
|
|
config(['geography.country' => $this->settings['country'] ]); |
140
|
|
|
|
141
|
|
|
$io = new SymfonyStyle($input, $output); |
142
|
|
|
$io->progressStart(3); |
143
|
|
|
|
144
|
|
|
// migrate table |
145
|
|
|
(new ManagerMigrations([ |
146
|
|
|
new CountryMigration, |
147
|
|
|
new RegionsMigration, |
148
|
|
|
new CitiesMigration |
149
|
|
|
]))->builder(); |
150
|
|
|
$io->progressAdvance(2); |
151
|
|
|
|
152
|
|
|
// seed data |
153
|
|
|
(new ManagerSeeder(array( |
154
|
|
|
new CountryTableSeeder, |
155
|
|
|
new RegionsTableSeeder, |
156
|
|
|
new CitiesTableSeeder |
157
|
|
|
)))->run(); |
158
|
|
|
|
159
|
|
|
$io->progressFinish(); |
160
|
|
|
$output->writeln('<info>Successfully created all!</info>'); |
161
|
|
|
} |
162
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: