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