forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSiteStatusCommand.php
More file actions
180 lines (151 loc) · 5.19 KB
/
Copy pathSiteStatusCommand.php
File metadata and controls
180 lines (151 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\SiteStatusCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* This command provides a view of the current drupal installation.
*
* @category site
*/
class SiteStatusCommand extends ContainerAwareCommand
{
/* @var $connectionInfoKeys array */
protected $connectionInfoKeys = [
'driver',
'host',
'database',
'port',
'username',
'password'
];
protected $groups = [
'system',
'database',
'theme',
'directory'
];
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('site:status')
->setDescription($this->trans('commands.site.status.description'))
->addOption(
'format',
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.site.status.options.format'),
'table'
);
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$systemData = $this->getSystemData();
$connectionData = $this->getConnectionData();
$themeInfo = $this->getThemeData();
$directoryData = $this->getDirectoryData();
$siteData = array_merge($systemData, $connectionData, $themeInfo, $directoryData);
$format = $input->getOption('format');
if ('table' === $format) {
$this->showDataAsTable($output, $siteData);
}
if ('json' === $format) {
$output->writeln(json_encode($siteData, JSON_PRETTY_PRINT));
}
}
protected function getSystemData()
{
$systemManager = $this->getSystemManager();
$requirements = $systemManager->listRequirements();
$requirementData = [];
foreach ($requirements as $key => $requirement) {
$requirementData['system'][$requirement['title']] = $requirement['value'];
}
return $requirementData;
}
protected function getConnectionData()
{
$connectionInfo = $this->getConnectionInfo();
$connectionData = [];
foreach ($this->connectionInfoKeys as $connectionInfoKey) {
$connectionKey = $this->trans('commands.site.status.messages.'.$connectionInfoKey);
$connectionData['database'][$connectionKey] = $connectionInfo['default'][$connectionInfoKey];
}
$connectionData['database'][$this->trans('commands.site.status.messages.connection')] = sprintf(
'%s//%s:%s@%s%s/%s',
$connectionInfo['default']['driver'],
$connectionInfo['default']['username'],
$connectionInfo['default']['password'],
$connectionInfo['default']['host'],
$connectionInfo['default']['port'] ? ':'. $connectionInfo['default']['port'] :'',
$connectionInfo['default']['database']
);
return $connectionData;
}
protected function getThemeData()
{
$configFactory = $this->getConfigFactory();
$config = $configFactory->get('system.theme');
return [
'theme' => [
'theme_default' => $config->get('default'),
'theme_admin' => $config->get('admin')
]
];
}
protected function getDirectoryData()
{
$drupalAutoLoad = $this->getHelperSet()->get('drupal-autoload');
$drupal_root = $drupalAutoLoad->getDrupalRoot();
$configFactory = $this->getConfigFactory();
$systemTheme = $configFactory->get('system.theme');
$themeHandler = $this->getThemeHandler();
$themeDefault = $themeHandler->getTheme($systemTheme->get('default'));
$themeAdmin = $themeHandler->getTheme($systemTheme->get('admin'));
$systemFile = $this->getConfigFactory()->get('system.file');
return [
'directory' => [
$this->trans('commands.site.status.messages.directory_root') => $drupal_root,
$this->trans('commands.site.status.messages.directory_temporary') => $systemFile->get('path.temporary'),
$this->trans('commands.site.status.messages.directory_theme_default') => '/'. $themeDefault->getpath(),
$this->trans('commands.site.status.messages.directory_theme_admin') => '/' . $themeAdmin->getpath(),
]
];
}
protected function showDataAsTable($output, $siteData)
{
if (empty($siteData)) {
return [];
}
$table = $this->getHelperSet()->get('table');
$table->setlayout($table::LAYOUT_COMPACT);
foreach ($this->groups as $group) {
$groupData = $siteData[$group];
$table->addRow([
sprintf(
'<comment>%s</comment>',
$this->trans('commands.site.status.messages.'.$group)
),
null
]);
foreach ($groupData as $key => $item) {
$table->addRow([
$key,
$item
]);
}
}
$table->render($output);
}
}