public function HackedCommands::calculateProjectData in Hacked! 8.2
Compute the report data for hacked.
WARNING: This function can invoke a batch process and end your current page. So you'll want to be very careful if you call this!
Parameters
array $projects: An array of Drupal projects.
bool|false $force: If TRUE, force rebuild of project data.
Return value
array The report data.
1 call to HackedCommands::calculateProjectData()
- HackedCommands::listProjects in src/
Commands/ HackedCommands.php - List all projects that can be analysed by Hacked!
File
- src/
Commands/ HackedCommands.php, line 333
Class
- HackedCommands
- A Drush commandfile for Hacked! module.
Namespace
Drupal\hacked\CommandsCode
public function calculateProjectData(array $projects, $force = FALSE) {
// Try to get the report form cache if we can.
$cache = $this->cacheBackend
->get('hacked:drush:full-report');
if (!empty($cache->data) && !$force) {
return $cache->data;
}
$op_callback = [
$this,
'buildReportBatch',
];
$finished_callback = [
$this,
'buildReportBatchFinished',
];
$title = $this
->t('Building report');
// If Drupal 8.6+, use BatchBuilder class.
if (class_exists('\\Drupal\\Core\\Batch\\BatchBuilder')) {
$batch_builder = (new BatchBuilder())
->setTitle($title)
->setFinishCallback($finished_callback);
foreach ($projects as $project) {
$batch_builder
->addOperation($op_callback, [
$project['name'],
]);
}
$batch = $batch_builder
->toArray();
}
else {
// Enter a batch to build the report.
$operations = [];
foreach ($projects as $project) {
$operations[] = [
$op_callback,
[
$project['name'],
],
];
}
$batch = [
'operations' => $operations,
'finished' => $finished_callback,
'title' => $title,
];
}
$this
->output()
->writeln((string) $this
->t('Rebuilding Hacked! report'));
batch_set($batch);
$batch =& batch_get();
$batch['progressive'] = FALSE;
drush_backend_batch_process();
$this
->output()
->writeln((string) $this
->t('Done.'));
// Now we can get the data from the cache.
$cache = $this->cacheBackend
->get('hacked:drush:full-report');
if (!empty($cache->data)) {
return $cache->data;
}
return [];
}