|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
10
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
11
|
|
|
|
|
12
|
|
|
class BiCoreBundleDropdatabaseCommand extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
protected static $defaultName = 'bicorebundle:dropdatabase'; |
|
16
|
|
|
|
|
17
|
1 |
|
public function __construct(ObjectManager $em) |
|
18
|
|
|
{ |
|
19
|
1 |
|
$this->em = $em; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
// you *must* call the parent constructor |
|
22
|
1 |
|
parent::__construct(); |
|
23
|
1 |
|
} |
|
24
|
1 |
|
protected function configure() |
|
25
|
|
|
{ |
|
26
|
|
|
$this |
|
27
|
1 |
|
->setDescription('Cancellazione database bicorebundle') |
|
28
|
1 |
|
->setHelp('Cancella il database e tutti i dati di bicorebundle') |
|
29
|
1 |
|
->addOption('force', null, InputOption::VALUE_NONE, 'Se non impostato, il comando non avrà effetto'); |
|
30
|
1 |
|
} |
|
31
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
1 |
|
$force = $input->getOption('force'); |
|
34
|
|
|
|
|
35
|
1 |
|
if (!$force) { |
|
36
|
|
|
echo "Specificare l'opzione --force per eseguire il comando"; |
|
37
|
|
|
|
|
38
|
|
|
return 1; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
42
|
1 |
|
$em = $this->em; |
|
43
|
1 |
|
$driver = $em->getConnection()->getDatabasePlatform()->getName(); |
|
44
|
1 |
|
switch ($driver) { |
|
45
|
1 |
|
case 'sqlite': |
|
46
|
|
|
$command = $this->getApplication()->find('doctrine:database:drop'); |
|
47
|
|
|
$arguments = array('command' => 'doctrine:database:drop', '--force' => true/*, '--if-exists' => true*/); |
|
48
|
|
|
$inputcmd = new ArrayInput($arguments); |
|
49
|
|
|
$command->run($inputcmd, $output); |
|
50
|
|
|
break; |
|
51
|
|
|
default: |
|
52
|
1 |
|
$command = $this->getApplication()->find('doctrine:schema:drop'); |
|
53
|
1 |
|
$arguments = array('command' => 'doctrine:schema:drop', '--force' => true, '--full-database' => true); |
|
54
|
1 |
|
$inputcmd = new ArrayInput($arguments); |
|
55
|
1 |
|
$command->run($inputcmd, $output); |
|
56
|
1 |
|
break; |
|
57
|
|
|
} |
|
58
|
1 |
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|