3 use Drupal\Component\Utility\Unicode;
6 use Drupal\hacked\hackedProject;
9 * Batch callback to build the hacked report.
11 function hacked_build_report_batch($project_name, &$context) {
12 if (!isset($context['results']['report'])) {
13 $context['results']['report'] = array();
15 \Drupal::moduleHandler()
16 ->loadInclude('hacked', 'inc', 'includes/hacked_project');
17 $project = new hackedProject($project_name);
18 $context['results']['report'][$project_name] = $project->compute_report();
19 $context['message'] = t('Finished processing: @name', array('@name' => $project->title()));
23 * Completion callback for the report batch.
28 function hacked_build_report_batch_finished($success, $results) {
31 usort($results['report'], '_hacked_project_report_sort_by_status');
33 \Drupal::cache(HACKED_CACHE_TABLE)
34 ->set('hacked:full-report', $results['report'], strtotime('+1 day'));
35 \Drupal::state()->set('hacked.last_check', time());
40 * Implements hook_preprocess_update_last_check().
42 function hacked_preprocess_update_last_check(&$variables) {
43 $route = \Drupal::routeMatch()->getRouteName();
44 if ($route == 'hacked.report') {
45 $variables['link'] = $variables['link'] = Link::fromTextAndUrl(t('Check manually'), new Url('hacked.manual_status', array(), array(
46 'query' => \Drupal::destination()
53 * Prepares variables for hacked project status templates.
55 * Default template: hacked-project-status.html.twig.
57 * @param array $variables
58 * An associative array containing:
59 * - project: An array of information about the project.
61 function hacked_preprocess_update_project_status(&$variables) {
62 $route = \Drupal::routeMatch()->getRouteName();
63 if ($route == 'hacked.report') {
65 // Storing by reference because we are sorting the project values.
66 $project = &$variables['project'];
68 $variables['install_type'] = $project['install_type'];
69 if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) {
70 $variables['datestamp'] = Drupal::service('date.formatter')
71 ->format($project['datestamp'], 'custom', 'Y-M-d');
74 $variables['existing_version'] = $project['existing_version'];
76 $variables['versions'] = [
78 '#theme' => 'hacked_project_summary',
79 '#project' => $project,
83 switch ($project['status']) {
84 case HACKED_STATUS_UNHACKED:
85 $uri = 'core/misc/icons/73b355/check.svg';
86 $text = t('Unchanged');
87 $project['status'] = UPDATE_CURRENT;
89 case HACKED_STATUS_HACKED:
90 $uri = 'core/misc/icons/e32700/error.svg';
91 $text = t('Changed!');
92 $project['status'] = UPDATE_NOT_CHECKED;
94 case HACKED_STATUS_UNCHECKED:
96 $uri = 'core/misc/icons/e29700/warning.svg';
97 $text = t('Unchecked');
98 $project['status'] = UPDATE_NOT_CHECKED;
102 $variables['status']['label'] = $text;
103 $variables['status']['icon'] = [
115 * Prepares variables for hacked status report templates.
117 * Default template: hacked-report.html.twig.
119 * @param array $variables
120 * An associative array containing:
121 * - data: An array of data about each project's status.
123 function template_preprocess_hacked_report(&$variables) {
124 $data = $variables['data'];
126 $last = \Drupal::state()->get('hacked.last_check') ?: 0;
128 $variables['last_checked'] = [
129 '#theme' => 'update_last_check',
131 // Attach the library to a variable that gets printed always.
134 'update/drupal.update.admin',
139 // For no project update data, populate no data message.
141 $destination = \Drupal::destination()->getAsArray();
142 $variables['no_updates_message'] = t('No hacked information available. <a href=":check_manually">check manually</a>.', array(
143 ':run_cron' => Url::fromRoute('system.run_cron', [], ['query' => $destination]),
144 ':check_manually' => Url::fromRoute('hacked.manual_status', [], ['query' => $destination]),
150 foreach ($data as $project) {
151 if (!isset($project['status'])) {
156 '#theme' => 'update_project_status',
157 '#project' => $project,
160 // Build project rows.
161 if (!isset($rows[$project['project_type']])) {
162 $rows[$project['project_type']] = [
164 '#attributes' => ['class' => ['update']],
167 $row_key = !empty($project['title']) ? Unicode::strtolower($project['title']) : Unicode::strtolower($project['name']);
169 // Add the project status row and details.
170 $rows[$project['project_type']][$row_key]['status'] = $project_status;
172 // Add project status class attribute to the table row.
173 switch ($project['status']) {
174 case HACKED_STATUS_UNHACKED:
175 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-success']];
177 case HACKED_STATUS_HACKED:
178 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-error']];
180 case HACKED_STATUS_UNCHECKED:
182 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-warning']];
188 'core' => t('Drupal core'),
189 'module' => t('Modules'),
190 'theme' => t('Themes'),
191 'module-disabled' => t('Uninstalled modules'),
192 'theme-disabled' => t('Uninstalled themes'),
195 $variables['project_types'] = [];
196 foreach ($project_types as $type_name => $type_label) {
197 if (!empty($rows[$type_name])) {
198 ksort($rows[$type_name]);
199 $variables['project_types'][] = [
200 'label' => $type_label,
201 'table' => $rows[$type_name],
210 function template_preprocess_hacked_project_summary(&$variables) {
211 $project = $variables['project'];
213 $changes[] = \Drupal::translation()
214 ->formatPlural($project['counts']['different'], '1 file changed', '@count files changed');
215 $changes[] = \Drupal::translation()
216 ->formatPlural($project['counts']['missing'], '1 file deleted', '@count files deleted');
217 if ($project['counts']['access_denied'] > 0) {
218 $changes[] = \Drupal::translation()
219 ->formatPlural($project['counts']['access_denied'], '1 unreadable file', '@count unreadable files');
221 $variables['changes'] = implode(', ', $changes);
223 $variables['link'] = Url::fromRoute('hacked.project', ['project' => $project['project_name']]);