1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Norsys\LogsBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class SchemaCreateCommand |
11
|
|
|
*/ |
12
|
|
|
class SchemaCreateCommand extends ContainerAwareCommand |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Configure command |
16
|
|
|
*/ |
17
|
|
|
protected function configure() |
18
|
|
|
{ |
19
|
|
|
$this |
20
|
1 |
|
->setName('norsys:logs:schema-create') |
21
|
1 |
|
->setDescription('Create schema to log Monolog entries') |
22
|
1 |
|
->addOption('force', 'f', null, 'Execute queries'); |
23
|
1 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param InputInterface $input |
27
|
|
|
* @param OutputInterface $output |
28
|
|
|
* |
29
|
|
|
* @return integer |
30
|
|
|
*/ |
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
32
|
|
|
{ |
33
|
1 |
|
$loggerClosure = function ($message) use ($output) { |
34
|
|
|
$output->writeln($message); |
35
|
1 |
|
}; |
36
|
|
|
|
37
|
1 |
|
$tableName = $this->getContainer()->getParameter('norsys_logs.doctrine.table_name'); |
38
|
|
|
|
39
|
1 |
|
$schemaBuilder = $this->getContainer()->get('norsys_logs.model.log_schema_builder'); |
40
|
|
|
|
41
|
1 |
|
if ($input->getOption('force') === true) { |
42
|
|
|
try { |
43
|
1 |
|
$schemaBuilder->drop($loggerClosure); |
44
|
1 |
|
$output->writeln(sprintf( |
45
|
1 |
|
'<info>Dropped table <comment>%s</comment> for Doctrine Monolog connection.</info>', |
46
|
1 |
|
$tableName |
47
|
|
|
)); |
48
|
1 |
|
} catch (\Exception $e) { |
49
|
1 |
|
$output->writeln(sprintf( |
50
|
1 |
|
'<info>Dropped table ignored for Doctrine Monolog connection (not necessary).</info>', |
51
|
1 |
|
$tableName |
52
|
|
|
)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
try { |
57
|
1 |
|
$schemaBuilder->create($loggerClosure); |
58
|
1 |
|
$output->writeln(sprintf( |
59
|
1 |
|
'<info>Created table <comment>%s</comment> for Doctrine Monolog connection.</info>', |
60
|
1 |
|
$tableName |
61
|
|
|
)); |
62
|
1 |
|
} catch (\Exception $e) { |
63
|
1 |
|
$output->writeln(sprintf( |
64
|
1 |
|
'<error>Could not create table <comment>%s</comment> for Doctrine Monolog connection.</error>', |
65
|
1 |
|
$tableName |
66
|
|
|
)); |
67
|
1 |
|
$output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
68
|
|
|
|
69
|
1 |
|
return 1; |
70
|
|
|
} |
71
|
|
|
|
72
|
1 |
|
return 0; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|