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