|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bdf\Prime\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Bdf\Prime\ConnectionManager; |
|
6
|
|
|
use Bdf\Prime\Console\ConnectionProvider\DoctrineConnectionProviderAdapter; |
|
7
|
|
|
use Bdf\Util\Console\BdfStyle; |
|
8
|
|
|
use Doctrine\DBAL\Connection as DoctrineConnection; |
|
9
|
|
|
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand as DoctrineRunSqlCommand; |
|
10
|
|
|
use Doctrine\DBAL\Tools\Console\ConnectionProvider; |
|
11
|
|
|
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Run SQL on a doctrine connection. This will display a dbal result. |
|
17
|
|
|
*/ |
|
18
|
|
|
class RunSqlCommand extends DoctrineRunSqlCommand |
|
19
|
|
|
{ |
|
20
|
|
|
protected static $defaultName = 'prime:run:sql'; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var ConnectionManager |
|
24
|
|
|
*/ |
|
25
|
|
|
private $connectionManager; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param ConnectionManager $connectionManager |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(ConnectionManager $connectionManager) |
|
31
|
|
|
{ |
|
32
|
|
|
if (interface_exists(ConnectionProvider::class)) { |
|
33
|
|
|
parent::__construct(new DoctrineConnectionProviderAdapter($connectionManager)); |
|
34
|
|
|
$this->connectionManager = null; |
|
35
|
|
|
} else { |
|
36
|
|
|
parent::__construct(); |
|
37
|
|
|
$this->connectionManager = $connectionManager; |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
|
|
|
|
|
42
|
|
|
* |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function configure() |
|
45
|
|
|
{ |
|
46
|
|
|
parent::configure(); |
|
47
|
|
|
|
|
48
|
|
|
// Override the doctrine name to set the prime namespace. |
|
49
|
|
|
$this->setName(self::$defaultName); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
|
|
|
|
|
53
|
|
|
* {@inheritDoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
56
|
|
|
{ |
|
57
|
|
|
if ($this->connectionManager !== null) { |
|
58
|
|
|
$connection = $this->connectionManager->getConnection($input->getOption('connection')); |
|
59
|
|
|
|
|
60
|
|
|
if (!$connection instanceof DoctrineConnection) { |
|
61
|
|
|
$io = new BdfStyle($input, $output); |
|
62
|
|
|
$io->line('Connection <comment>%s</comment> is ignored: only doctrine connection can be managed', $connection->getName()); |
|
63
|
|
|
return 1; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$helperSet = $this->getHelperSet(); |
|
67
|
|
|
$helperSet->set(new ConnectionHelper($connection), 'db'); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return parent::execute($input, $output); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|