@@ 152-188 (lines=37) @@ | ||
149 | * |
|
150 | * @return int |
|
151 | */ |
|
152 | private function createDatabase( |
|
153 | OutputInterface $output, |
|
154 | string $connectionName, |
|
155 | Connection $tmpConnection, |
|
156 | string $dbName, |
|
157 | bool $shouldNotCreateDatabase |
|
158 | ): int { |
|
159 | try { |
|
160 | if ($shouldNotCreateDatabase) { |
|
161 | $output->writeln( |
|
162 | sprintf( |
|
163 | '<info>Database <comment>%s</comment> for connection named <comment>%s</comment>' |
|
164 | .' already exists. Skipped.</info>', |
|
165 | $dbName, |
|
166 | $connectionName |
|
167 | ) |
|
168 | ); |
|
169 | } else { |
|
170 | $tmpConnection->getSchemaManager()->createDatabase($dbName); |
|
171 | $output->writeln( |
|
172 | sprintf( |
|
173 | '<info>Created database <comment>%s</comment>' |
|
174 | .' for connection named <comment>%s</comment>.</info>', |
|
175 | $dbName, |
|
176 | $connectionName |
|
177 | ) |
|
178 | ); |
|
179 | } |
|
180 | ||
181 | return 0; |
|
182 | } catch (\Exception $e) { |
|
183 | $output->writeln(sprintf('<error>Could not create database <comment>%s</comment>.</error>', $dbName)); |
|
184 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
|
185 | ||
186 | return 1; |
|
187 | } |
|
188 | } |
|
189 | } |
|
190 |
@@ 191-234 (lines=44) @@ | ||
188 | * |
|
189 | * @return int |
|
190 | */ |
|
191 | private function dropDatabase( |
|
192 | OutputInterface $output, |
|
193 | string $connectionName, |
|
194 | Connection $connection, |
|
195 | string $dbName, |
|
196 | bool $shouldDropDatabase |
|
197 | ): int { |
|
198 | try { |
|
199 | if ($shouldDropDatabase) { |
|
200 | $connection->getSchemaManager()->dropDatabase($dbName); |
|
201 | $output->writeln( |
|
202 | sprintf( |
|
203 | '<info>Dropped database <comment>%s</comment> for connection' |
|
204 | .' named <comment>%s</comment>.</info>', |
|
205 | $dbName, |
|
206 | $connectionName |
|
207 | ) |
|
208 | ); |
|
209 | } else { |
|
210 | $output->writeln( |
|
211 | sprintf( |
|
212 | '<info>Database <comment>%s</comment> for connection named <comment>%s</comment>' |
|
213 | .' doesn\'t exist. Skipped.</info>', |
|
214 | $dbName, |
|
215 | $connectionName |
|
216 | ) |
|
217 | ); |
|
218 | } |
|
219 | } catch (\Exception $e) { |
|
220 | $output->writeln( |
|
221 | sprintf( |
|
222 | '<error>Could not drop database <comment>%s</comment> for connection' |
|
223 | .' named <comment>%s</comment>.</error>', |
|
224 | $dbName, |
|
225 | $connectionName |
|
226 | ) |
|
227 | ); |
|
228 | $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
|
229 | ||
230 | return self::RETURN_CODE_NOT_DROP; |
|
231 | } |
|
232 | ||
233 | return 0; |
|
234 | } |
|
235 | } |
|
236 |