Pull merge.
[yaffs-website] / web / modules / contrib / hacked / src / Controller / HackedController.php
1 <?php
2
3 namespace Drupal\hacked\Controller;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\hacked\hackedProject;
7
8 /**
9  * Controller routines for hacked routes.
10  */
11 class HackedController extends ControllerBase {
12
13   /**
14    * @param \Drupal\hacked\hackedProject $project
15    * @return array
16    */
17   public function hackedProject(hackedProject $project) {
18     return [
19       '#theme' => 'hacked_detailed_report',
20       '#project' => $project->compute_details()
21     ];
22   }
23
24   /**
25    * Menu title callback for the hacked details page.
26    */
27   public function hackedProjectTitle(hackedProject $project) {
28     return $this->t('Hacked status for @project', ['@project' => $project->title()]);
29   }
30
31   /**
32    * Page callback to build up a full report.
33    */
34   public function hackedStatus() {
35     // We're going to be borrowing heavily from the update module
36     $build = ['#theme' => 'update_report'];
37     if ($available = update_get_available(TRUE)) {
38       $build = ['#theme' => 'hacked_report'];
39       $this->moduleHandler()->loadInclude('update', 'compare.inc');
40       $data = update_calculate_project_data($available);
41       $build['#data'] = $this->getProjectData($data);
42       if (!is_array($build['#data'])) {
43         return $build['#data'];
44       }
45     }
46     return $build;
47   }
48
49   /**
50    * Page callback to rebuild the hacked report.
51    */
52   public function hackedStatusManually() {
53     // We're going to be borrowing heavily from the update module
54     if ($available = update_get_available(TRUE)) {
55       $this->moduleHandler()->loadInclude('update', 'compare.inc');
56       $data = update_calculate_project_data($available);
57       return $this->getProjectData($data, TRUE, 'admin/reports/hacked');
58     }
59     return $this->redirect('hacked.report');
60   }
61
62   /**
63    * Compute the report data for hacked.
64    *
65    * @param            $projects
66    * @param bool|FALSE $force
67    * @param null       $redirect
68    * @return mixed
69    */
70   protected function getProjectData($projects, $force = FALSE, $redirect = NULL) {
71     // Try to get the report form cache if we can.
72     $cache = \Drupal::cache(HACKED_CACHE_TABLE)->get('hacked:full-report');
73     if (!empty($cache->data) && !$force) {
74       return $cache->data;
75     }
76
77     // Enter a batch to build the report.
78     $operations = [];
79     foreach ($projects as $project) {
80       $operations[] = [
81         'hacked_build_report_batch',
82         [$project['name']],
83       ];
84     }
85
86     $batch = array(
87       'operations' => $operations,
88       'finished' => 'hacked_build_report_batch_finished',
89       'file' => drupal_get_path('module', 'hacked') . '/hacked.report.inc',
90       'title' => t('Building report'),
91     );
92
93     batch_set($batch);
94     // End page execution and run the batch.
95     return batch_process($redirect);
96   }
97
98 }