1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\System; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
8
|
|
|
use N98\Util\Console\Helper\Table\Renderer\RendererFactory; |
9
|
|
|
use N98\Util\Console\Helper\TableHelper; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\Finder\Finder; |
15
|
|
|
|
16
|
|
|
class InfoCommand extends AbstractMagentoCommand |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected $infos; |
22
|
|
|
|
23
|
|
|
protected function configure() |
24
|
|
|
{ |
25
|
|
|
$this |
26
|
|
|
->setName('sys:info') |
27
|
|
|
->addArgument( |
28
|
|
|
'key', |
29
|
|
|
InputArgument::OPTIONAL, |
30
|
|
|
'Only output value of named param like "version". Key is case insensitive.' |
31
|
|
|
)->setDescription('Prints infos about the current magento system.') |
32
|
|
|
->addOption( |
33
|
|
|
'format', |
34
|
|
|
null, |
35
|
|
|
InputOption::VALUE_OPTIONAL, |
36
|
|
|
'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']' |
37
|
|
|
) |
38
|
|
|
; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param InputInterface $input |
43
|
|
|
* @param OutputInterface $output |
44
|
|
|
* |
45
|
|
|
* @return int|void |
46
|
|
|
*/ |
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
48
|
|
|
{ |
49
|
|
|
$this->detectMagento($output); |
50
|
|
|
|
51
|
|
|
$softInitMode = in_array($input->getArgument('key'), array( |
52
|
|
|
'version', |
53
|
|
|
'edition', |
54
|
|
|
)); |
55
|
|
|
|
56
|
|
|
if ($input->getOption('format') == null && $input->getArgument('key') == null) { |
|
|
|
|
57
|
|
|
$this->writeSection($output, 'Magento System Information'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->initMagento($softInitMode); |
61
|
|
|
|
62
|
|
|
$this->infos['Version'] = $this->magentoVersion(); |
63
|
|
|
$this->infos['Edition'] = ($this->_magentoEnterprise ? 'Enterprise' : 'Community'); |
64
|
|
|
$this->infos['Root'] = $this->_magentoRootFolder; |
65
|
|
|
|
66
|
|
|
if ($softInitMode === false) { |
67
|
|
|
$config = \Mage::app()->getConfig(); |
68
|
|
|
$this->addCacheInfos(); |
69
|
|
|
|
70
|
|
|
$this->infos['Session'] = $config->getNode('global/session_save'); |
71
|
|
|
|
72
|
|
|
$this->infos['Crypt Key'] = $config->getNode('global/crypt/key'); |
73
|
|
|
$this->infos['Install Date'] = $config->getNode('global/install/date'); |
74
|
|
|
try { |
75
|
|
|
$this->findCoreOverwrites(); |
76
|
|
|
$this->findVendors(); |
77
|
|
|
$this->attributeCount(); |
78
|
|
|
$this->customerCount(); |
79
|
|
|
$this->categoryCount(); |
80
|
|
|
$this->productCount(); |
81
|
|
|
} catch (Exception $e) { |
82
|
|
|
$output->writeln('<error>' . $e->getMessage() . '</error>'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$table = array(); |
87
|
|
|
foreach ($this->infos as $key => $value) { |
88
|
|
|
$table[] = array($key, $value); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (($settingArgument = $input->getArgument('key')) !== null) { |
92
|
|
|
$settingArgument = strtolower($settingArgument); |
93
|
|
|
$this->infos = array_change_key_case($this->infos, CASE_LOWER); |
94
|
|
|
if (!isset($this->infos[$settingArgument])) { |
95
|
|
|
throw new InvalidArgumentException('Unknown key: ' . $settingArgument); |
96
|
|
|
} |
97
|
|
|
$output->writeln((string) $this->infos[$settingArgument]); |
98
|
|
View Code Duplication |
} else { |
|
|
|
|
99
|
|
|
/* @var $tableHelper TableHelper */ |
100
|
|
|
$tableHelper = $this->getHelper('table'); |
101
|
|
|
$tableHelper |
102
|
|
|
->setHeaders(array('name', 'value')) |
103
|
|
|
->renderByFormat($output, $table, $input->getOption('format')); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
protected function magentoVersion() |
108
|
|
|
{ |
109
|
|
|
if (method_exists('Mage', 'getOpenMageVersion')) { |
110
|
|
|
return 'OpenMage LTS ' . \Mage::getOpenMageVersion(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return \Mage::getVersion(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
protected function addCacheInfos() |
117
|
|
|
{ |
118
|
|
|
$this->infos['Cache Backend'] = get_class(\Mage::app()->getCache()->getBackend()); |
119
|
|
|
|
120
|
|
|
switch (get_class(\Mage::app()->getCache()->getBackend())) { |
121
|
|
|
case 'Zend_Cache_Backend_File': |
122
|
|
|
$cacheDir = \Mage::app()->getConfig()->getOptions()->getCacheDir(); |
123
|
|
|
$this->infos['Cache Directory'] = $cacheDir; |
124
|
|
|
break; |
125
|
|
|
|
126
|
|
|
default: |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return int|void |
132
|
|
|
*/ |
133
|
|
|
protected function findCoreOverwrites() |
134
|
|
|
{ |
135
|
|
|
$folders = array( |
136
|
|
|
$this->_magentoRootFolder . '/app/code/local/Mage', |
137
|
|
|
$this->_magentoRootFolder . '/app/code/local/Enterprise', |
138
|
|
|
$this->_magentoRootFolder . '/app/code/community/Mage', |
139
|
|
|
$this->_magentoRootFolder . '/app/code/community/Enterprise', |
140
|
|
|
); |
141
|
|
|
foreach ($folders as $key => $folder) { |
142
|
|
|
if (!is_dir($folder)) { |
143
|
|
|
unset($folders[$key]); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if (count($folders) > 0) { |
148
|
|
|
$finder = Finder::create(); |
149
|
|
|
$finder |
150
|
|
|
->files() |
151
|
|
|
->ignoreUnreadableDirs(true) |
152
|
|
|
->in($folders); |
153
|
|
|
$this->infos['Core Autoloader Overwrites'] = $finder->count(); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return int|void |
159
|
|
|
*/ |
160
|
|
|
protected function findVendors() |
161
|
|
|
{ |
162
|
|
|
$codePools = array( |
163
|
|
|
'core' => $this->_magentoRootFolder . '/app/code/core/', |
164
|
|
|
'community' => $this->_magentoRootFolder . '/app/code/community/', |
165
|
|
|
); |
166
|
|
|
|
167
|
|
|
if (is_dir($this->_magentoRootFolder . '/app/code/local/')) { |
168
|
|
|
$codePools['local'] = $this->_magentoRootFolder . '/app/code/local/'; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
foreach ($codePools as $codePool => $codePoolDir) { |
172
|
|
|
$finder = Finder::create(); |
173
|
|
|
$finder |
174
|
|
|
->directories() |
175
|
|
|
->ignoreUnreadableDirs(true) |
176
|
|
|
->in($codePoolDir) |
177
|
|
|
->depth(0) |
178
|
|
|
->sortByName(); |
179
|
|
|
|
180
|
|
|
$vendors = iterator_to_array($finder); |
181
|
|
|
$vendors = array_map( |
182
|
|
|
function ($value) use ($codePoolDir) { |
183
|
|
|
return str_replace($codePoolDir, '', $value); |
184
|
|
|
}, |
185
|
|
|
$vendors |
186
|
|
|
); |
187
|
|
|
|
188
|
|
|
$this->infos['Vendors (' . $codePool . ')'] = implode(', ', $vendors); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
protected function categoryCount() |
193
|
|
|
{ |
194
|
|
|
$this->infos['Category Count'] = \Mage::getModel('catalog/category')->getCollection()->getSize(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
protected function productCount() |
198
|
|
|
{ |
199
|
|
|
$this->infos['Product Count'] = \Mage::getModel('catalog/product')->getCollection()->getSize(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
protected function customerCount() |
203
|
|
|
{ |
204
|
|
|
$this->infos['Customer Count'] = \Mage::getModel('customer/customer')->getCollection()->getSize(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
protected function attributeCount() |
208
|
|
|
{ |
209
|
|
|
$this->infos['Attribute Count'] = \Mage::getModel('eav/entity_attribute')->getCollection()->getSize(); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|