1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Gerrie package. |
4
|
|
|
* |
5
|
|
|
* (c) Andreas Grunwald <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Gerrie\Command; |
12
|
|
|
|
13
|
|
|
use Gerrie\Component\Configuration\ConfigurationFactory; |
14
|
|
|
use Gerrie\Component\Configuration\CommandConfiguration; |
15
|
|
|
use Gerrie\Component\Database\Database; |
16
|
|
|
use Gerrie\Service\DatabaseService; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
class SetupDatabaseCommand extends GerrieBaseCommand |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Command name |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
const COMMAND_NAME = 'Setup Database'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Database object |
32
|
|
|
* |
33
|
|
|
* @var \Gerrie\Service\DatabaseService |
34
|
|
|
*/ |
35
|
|
|
protected $databaseService = null; |
36
|
|
|
|
37
|
|
|
protected function configure() |
38
|
|
|
{ |
39
|
|
|
$this |
40
|
|
|
->setName('gerrie:setup-database') |
41
|
|
|
->setDescription('Setup / Creates the required database scheme (tables only)'); |
42
|
|
|
|
43
|
|
|
$this->addConfigFileOption(); |
44
|
|
|
$this->addDatabaseOptions(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
48
|
|
|
{ |
49
|
|
|
/** @var InputExtendedInterface $input */ |
50
|
|
|
|
51
|
|
|
$configFile = $input->getOption('config-file'); |
52
|
|
|
$configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $input); |
53
|
|
|
|
54
|
|
|
$databaseConfig = $configuration->getConfigurationValue('Database'); |
55
|
|
|
$database = new Database($databaseConfig); |
56
|
|
|
|
57
|
|
|
$this->databaseService = new DatabaseService($database, $output); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
61
|
|
|
{ |
62
|
|
|
$output->writeln(''); |
63
|
|
|
$output->writeln('<comment>Starting application "' . self::COMMAND_NAME . '"</comment>'); |
64
|
|
|
$output->writeln(''); |
65
|
|
|
|
66
|
|
|
$this->databaseService->setupDatabaseTables(); |
67
|
|
|
|
68
|
|
|
$output->writeln(''); |
69
|
|
|
$output->writeln('<comment>Application "' . self::COMMAND_NAME . '" finished</comment>'); |
70
|
|
|
$output->writeln(''); |
71
|
|
|
} |
72
|
|
|
} |