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\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
abstract class AbstractDatabaseCommand extends AbstractMagentoCommand |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
protected $dbSettings; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var bool |
19
|
|
|
*/ |
20
|
|
|
protected $isSocketConnect = false; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
24
|
|
|
*/ |
25
|
|
|
protected function detectDbSettings(OutputInterface $output) |
26
|
|
|
{ |
27
|
|
|
$database = $this->getDatabaseHelper(); |
28
|
|
|
$database->detectDbSettings($output); |
29
|
|
|
$this->isSocketConnect = $database->getIsSocketConnect(); |
30
|
|
|
$this->dbSettings = $database->getDbSettings(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param $name |
35
|
|
|
* |
36
|
|
|
* @return mixed |
37
|
|
|
*/ |
38
|
|
|
public function __get($name) |
39
|
|
|
{ |
40
|
|
|
if ($name == '_connection') { |
41
|
|
|
return $this->getDatabaseHelper()->getConnection(); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Generate help for compression |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
protected function getCompressionHelp() |
51
|
|
|
{ |
52
|
|
|
$messages = array(); |
53
|
|
|
$messages[] = ''; |
54
|
|
|
$messages[] = '<comment>Compression option</comment>'; |
55
|
|
|
$messages[] = ' Supported compression: gzip'; |
56
|
|
|
$messages[] = ' The gzip cli tool has to be installed.'; |
57
|
|
|
$messages[] = ' Additionally, for data-to-csv option tar cli tool has to be installed too.'; |
58
|
|
|
|
59
|
|
|
return implode(PHP_EOL, $messages); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $type |
64
|
|
|
* @return AbstractCompressor |
65
|
|
|
* @deprecated Since 1.1.12; use AbstractCompressor::create() instead |
66
|
|
|
*/ |
67
|
|
|
protected function getCompressor($type) |
68
|
|
|
{ |
69
|
|
|
return AbstractCompressor::create($type); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
* |
75
|
|
|
* @deprecated Please use database helper |
76
|
|
|
*/ |
77
|
|
|
protected function getMysqlClientToolConnectionString() |
78
|
|
|
{ |
79
|
|
|
return $this->getDatabaseHelper()->getMysqlClientToolConnectionString(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Creates a PDO DSN for the adapter from $this->_config settings. |
84
|
|
|
* |
85
|
|
|
* @see Zend_Db_Adapter_Pdo_Abstract |
86
|
|
|
* @return string |
87
|
|
|
* |
88
|
|
|
* @deprecated Please use database helper |
89
|
|
|
*/ |
90
|
|
|
protected function _dsn() |
91
|
|
|
{ |
92
|
|
|
return $this->getDatabaseHelper()->dsn(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return DatabaseHelper |
97
|
|
|
*/ |
98
|
|
|
protected function getDatabaseHelper() |
99
|
|
|
{ |
100
|
|
|
return $this->getHelper('database'); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|