1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Database; |
4
|
|
|
|
5
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
6
|
|
|
use N98\Magento\Command\Database\Compressor\AbstractCompressor; |
7
|
|
|
use N98\Util\Console\Helper\DatabaseHelper; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
abstract class AbstractDatabaseCommand extends AbstractMagentoCommand |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
protected $dbSettings; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $isSocketConnect = false; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Common configuration for all DB commands |
26
|
|
|
*/ |
27
|
|
|
protected function configure() |
28
|
|
|
{ |
29
|
|
|
$this->addOption( |
30
|
|
|
'connection', |
31
|
|
|
null, |
32
|
|
|
InputOption::VALUE_REQUIRED, |
33
|
|
|
'Select DB connection type for Magento configurations with several databases', |
34
|
|
|
'default' |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Initialize db connection settings |
40
|
|
|
* |
41
|
|
|
* @param InputInterface $input |
42
|
|
|
* @param OutputInterface $output |
43
|
|
|
*/ |
44
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
45
|
|
|
{ |
46
|
|
|
parent::initialize($input, $output); |
47
|
|
|
$dbHelper = $this->getDatabaseHelper(); |
48
|
|
|
$dbHelper->setConnectionType($input->getOption('connection')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
53
|
|
|
*/ |
54
|
|
|
protected function detectDbSettings(OutputInterface $output) |
55
|
|
|
{ |
56
|
|
|
$database = $this->getDatabaseHelper(); |
57
|
|
|
$database->detectDbSettings($output); |
58
|
|
|
$this->isSocketConnect = $database->getIsSocketConnect(); |
59
|
|
|
$this->dbSettings = $database->getDbSettings(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param $name |
64
|
|
|
* |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
public function __get($name) |
68
|
|
|
{ |
69
|
|
|
if ($name == '_connection') { |
70
|
|
|
return $this->getDatabaseHelper()->getConnection(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Generate help for compression |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
protected function getCompressionHelp() |
80
|
|
|
{ |
81
|
|
|
$messages = array(); |
82
|
|
|
$messages[] = ''; |
83
|
|
|
$messages[] = '<comment>Compression option</comment>'; |
84
|
|
|
$messages[] = ' Supported compression: gzip'; |
85
|
|
|
$messages[] = ' The gzip cli tool has to be installed.'; |
86
|
|
|
$messages[] = ' Additionally, for data-to-csv option tar cli tool has to be installed too.'; |
87
|
|
|
|
88
|
|
|
return implode(PHP_EOL, $messages); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $type |
93
|
|
|
* @return AbstractCompressor |
94
|
|
|
* @deprecated Since 1.1.12; use AbstractCompressor::create() instead |
95
|
|
|
*/ |
96
|
|
|
protected function getCompressor($type) |
97
|
|
|
{ |
98
|
|
|
return AbstractCompressor::create($type); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
* |
104
|
|
|
* @deprecated Please use database helper |
105
|
|
|
*/ |
106
|
|
|
protected function getMysqlClientToolConnectionString() |
107
|
|
|
{ |
108
|
|
|
return $this->getDatabaseHelper()->getMysqlClientToolConnectionString(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Creates a PDO DSN for the adapter from $this->_config settings. |
113
|
|
|
* |
114
|
|
|
* @see Zend_Db_Adapter_Pdo_Abstract |
115
|
|
|
* @return string |
116
|
|
|
* |
117
|
|
|
* @deprecated Please use database helper |
118
|
|
|
*/ |
119
|
|
|
protected function _dsn() |
120
|
|
|
{ |
121
|
|
|
return $this->getDatabaseHelper()->dsn(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return DatabaseHelper |
126
|
|
|
*/ |
127
|
|
|
protected function getDatabaseHelper() |
128
|
|
|
{ |
129
|
|
|
return $this->getHelper('database'); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|