Completed
Push — develop ( f63da3...8c2b94 )
by Tom
04:32
created

AbstractDatabaseCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 110
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCompressionHelp() 0 11 1
A detectDbSettings() 0 7 1
A __get() 0 6 2
A getCompressor() 0 4 1
A getMysqlClientToolConnectionString() 0 4 1
A _dsn() 0 4 1
A resolveTables() 0 4 1
A getDatabaseHelper() 0 4 1
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