1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file was previously qa_projects.inc. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Drupal\qa\Controller; |
8
|
|
|
|
9
|
|
|
use Drupal\Core\Controller\ControllerBase; |
10
|
|
|
use Drupal\Core\KeyValueStore\KeyValueExpirableFactory; |
11
|
|
|
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; |
12
|
|
|
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; |
13
|
|
|
use Drupal\Core\KeyValueStore\KeyValueStoreInterface; |
14
|
|
|
use Drupal\qa\System\Module; |
15
|
|
|
use Drupal\update\UpdateManagerInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class ProjectsReportController. |
20
|
|
|
* |
21
|
|
|
* @package Drupal\qa\Controller |
22
|
|
|
*/ |
23
|
|
|
class ProjectsReportController extends ControllerBase { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface |
27
|
|
|
*/ |
28
|
|
|
protected $keyValueExpirable; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \Drupal\update\UpdateManagerInterface |
32
|
|
|
*/ |
33
|
|
|
protected $updateManager; |
34
|
|
|
|
35
|
|
|
public function __construct( |
36
|
|
|
UpdateManagerInterface $updateManager, |
37
|
|
|
KeyValueExpirableFactoryInterface $kveFactory |
38
|
|
|
) { |
39
|
|
|
$this->keyValueExpirable = $kveFactory->get('update'); |
40
|
|
|
$this->updateManager = $updateManager; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function create(ContainerInterface $container) { |
44
|
|
|
$updateManager = $container->get('update.manager'); |
45
|
|
|
assert($updateManager instanceof UpdateManagerInterface); |
46
|
|
|
$kve = $container->get('keyvalue.expirable'); |
47
|
|
|
assert($kve instanceof KeyValueExpirableFactoryInterface); |
48
|
|
|
return new static($updateManager, $kve); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Action. |
53
|
|
|
* |
54
|
|
|
* @return array<string,array|string> |
55
|
|
|
* A render array |
56
|
|
|
*/ |
57
|
|
|
public function action() { |
58
|
|
|
$projects = $this->buildProjects(); |
59
|
|
|
return $projects; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Build the list of projects. |
64
|
|
|
* |
65
|
|
|
* On most sites, this will just hold "drupal" and "OSInet QA", since most |
66
|
|
|
* code does not use the undocumented project info file key. |
67
|
|
|
* |
68
|
|
|
* @return array |
69
|
|
|
* A render array. |
70
|
|
|
*/ |
71
|
|
|
protected function buildProjects() { |
72
|
|
|
$this->keyValueExpirable->delete('update_project_projects'); |
73
|
|
|
$projects = $this->updateManager->getProjects(); |
74
|
|
|
$build = [ |
75
|
|
|
'#type' => 'table', |
76
|
|
|
'#header' => [ |
77
|
|
|
$this->t('Name'), |
78
|
|
|
$this->t('Type'), |
79
|
|
|
$this->t('Status'), |
80
|
|
|
], |
81
|
|
|
'#rows' => [], |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
foreach ($projects as $projectName => $project) { |
85
|
|
|
$row = [ |
86
|
|
|
$projectName, |
87
|
|
|
$project['project_type'], |
88
|
|
|
$project['project_status'], |
89
|
|
|
]; |
90
|
|
|
$build['#rows'][] = $row; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $build; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param \Drupal\qa\Controller\Variable|NULL $variable |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
* |
101
|
|
|
* FIXME this is is legacy D7 one-off code. |
102
|
|
|
* |
103
|
|
|
* @deprecated |
104
|
|
|
*/ |
105
|
|
|
private function qa_report_project(Variable $variable = NULL) { |
|
|
|
|
106
|
|
|
$c = cache_get('views_data:fr', 'cache_views'); |
|
|
|
|
107
|
|
|
$ret = '<pre>' . json_encode($c, JSON_PRETTY_PRINT) . '</pre>'; |
108
|
|
|
return $ret; |
109
|
|
|
$bc = drupal_get_breadcrumb(); |
|
|
|
|
110
|
|
|
$bc[] = l($this->t('Administration'), 'admin'); |
|
|
|
|
111
|
|
|
$bc[] = l($this->t('Reports'), 'admin/reports'); |
112
|
|
|
$bc[] = l($this->t('Quality Assurance'), 'admin/reports/qa'); |
113
|
|
|
$bc[] = l($this->t('Variables'), 'admin/reports/qa/variable'); |
114
|
|
|
drupal_set_breadcrumb($bc); |
|
|
|
|
115
|
|
|
|
116
|
|
|
drupal_set_title($this->t('Variable: %name', ['%name' => $variable->name]), ['passthrough' => TRUE]); |
|
|
|
|
117
|
|
|
return $variable->dump(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Page callback for projects list. |
122
|
|
|
* |
123
|
|
|
* @return array |
124
|
|
|
* A render array. |
125
|
|
|
* |
126
|
|
|
* @FIXME This still uses the D7 info structure. |
127
|
|
|
* |
128
|
|
|
* @deprecated |
129
|
|
|
*/ |
130
|
|
|
private function qa_report_projects() { |
|
|
|
|
131
|
|
|
$ret = '<h3>Projects</h3>'; |
132
|
|
|
drupal_static_reset('update_get_projects'); |
133
|
|
|
$GLOBALS['conf']['update_check_disabled'] = TRUE; |
134
|
|
|
$projects = update_get_projects(); |
|
|
|
|
135
|
|
|
ksort($projects); |
136
|
|
|
$ret .= kprint_r($projects, TRUE); |
|
|
|
|
137
|
|
|
|
138
|
|
|
$ret .= '<h3>Modules info</h3>'; |
139
|
|
|
[$modules, $projects] = Module::getInfo(); |
140
|
|
|
|
141
|
|
|
$header = [ |
142
|
|
|
$this->t('Project'), |
143
|
|
|
$this->t('Module'), |
144
|
|
|
$this->t('Module status'), |
145
|
|
|
$this->t('Project status'), |
146
|
|
|
]; |
147
|
|
|
|
148
|
|
|
$rows = []; |
149
|
|
|
$previous_project = ''; |
150
|
|
|
/** @var \Drupal\qa\System\Project $project */ |
151
|
|
|
foreach ($projects as $name => $project) { |
152
|
|
|
$row = []; |
153
|
|
|
$project_cell = ['data' => $name,]; |
154
|
|
|
$count = $project->useCount(); |
155
|
|
|
if ($count > 1) { |
156
|
|
|
//$project_cell['rowspan'] = $count; |
157
|
|
|
} |
158
|
|
|
if ($name != $previous_project) { |
159
|
|
|
$previous_project = $name; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$enabled = $this->t('Enabled'); |
163
|
|
|
$disabled = $this->t('Disabled'); |
164
|
|
|
|
165
|
|
|
/** @var \Drupal\qa\System\Module $module */ |
166
|
|
|
foreach (array_values($project->modules) as $index => $module) { |
167
|
|
|
$row = []; |
168
|
|
|
$row[] = ($index === 0) ? $project_cell : ''; |
169
|
|
|
|
170
|
|
|
$row[] = $module->name; |
171
|
|
|
$row[] = $module->isEnabled() ? $enabled : $disabled; |
172
|
|
|
|
173
|
|
|
if ($index === 0) { |
174
|
|
|
if ($count === 0) { |
175
|
|
|
$last_cell = [ |
176
|
|
|
'style' => 'background-color: #ff8080', |
177
|
|
|
'data' => $count, |
178
|
|
|
]; |
179
|
|
|
} |
180
|
|
|
else { |
181
|
|
|
$last_cell = $count; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
else { |
185
|
|
|
$last_cell = ''; |
186
|
|
|
} |
187
|
|
|
$row[] = $last_cell; |
188
|
|
|
|
189
|
|
|
$rows[] = $row; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
return [ |
193
|
|
|
'#theme' => 'table', |
194
|
|
|
'#header' => $header, |
195
|
|
|
'#rows' => $rows, |
196
|
|
|
]; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
} |
200
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.