HackedController.php in Hacked! 8.2
File
src/Controller/HackedController.php
View source
<?php
namespace Drupal\hacked\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\hacked\hackedProject;
class HackedController extends ControllerBase {
public function hackedProject(hackedProject $project) {
return [
'#theme' => 'hacked_detailed_report',
'#project' => $project
->compute_details(),
];
}
public function hackedProjectTitle(hackedProject $project) {
return $this
->t('Hacked status for @project', [
'@project' => $project
->title(),
]);
}
public function hackedStatus() {
$build = [
'#theme' => 'update_report',
];
if ($available = update_get_available(TRUE)) {
$build = [
'#theme' => 'hacked_report',
];
$this
->moduleHandler()
->loadInclude('update', 'compare.inc');
$data = update_calculate_project_data($available);
$build['#data'] = $this
->getProjectData($data);
if (!is_array($build['#data'])) {
return $build['#data'];
}
}
return $build;
}
public function hackedStatusManually() {
if ($available = update_get_available(TRUE)) {
$this
->moduleHandler()
->loadInclude('update', 'compare.inc');
$data = update_calculate_project_data($available);
return $this
->getProjectData($data, TRUE, 'admin/reports/hacked');
}
return $this
->redirect('hacked.report');
}
protected function getProjectData($projects, $force = FALSE, $redirect = NULL) {
$cache = \Drupal::cache(HACKED_CACHE_TABLE)
->get('hacked:full-report');
if (!empty($cache->data) && !$force) {
return $cache->data;
}
$operations = [];
foreach ($projects as $project) {
$operations[] = [
'hacked_build_report_batch',
[
$project['name'],
],
];
}
$batch = array(
'operations' => $operations,
'finished' => 'hacked_build_report_batch_finished',
'file' => drupal_get_path('module', 'hacked') . '/hacked.report.inc',
'title' => t('Building report'),
);
batch_set($batch);
return batch_process($redirect);
}
}