function drush_site_audit_audit_all in Site Audit 7
Same name and namespace in other branches
- 8.2 site_audit.drush.inc \drush_site_audit_audit_all()
Execute every single report.
File
- ./
site_audit.drush.inc, line 369 - Drupal site auditing commands.
Code
function drush_site_audit_audit_all($url = '', $key = '') {
$reports_to_skip = array();
if (drush_get_option('skip')) {
$reports_to_skip = explode(',', drush_get_option('skip'));
}
$command = drush_get_command();
drush_command_invoke_all_ref('drush_command_alter', $command);
$report_names = $command['reports'];
if (!empty($report_names)) {
$reports_to_render = array();
foreach ($report_names as $report_name) {
if (is_array($report_name)) {
require_once $report_name['location'];
$report_name = $report_name['name'];
}
$report_class = 'SiteAuditReport' . $report_name;
// Allow a specific report to be skipped.
if (!in_array(strtolower($report_name), $reports_to_skip)) {
// Special case for arguments.
if ($report_name == 'Insights') {
$report = new $report_class($url, $key);
}
else {
$report = new $report_class();
}
$reports_to_render[get_class($report)] = $report;
}
}
if (empty($reports_to_render)) {
return drush_set_error('SITE_AUDIT_NO_REPORTS', dt('No reports are available!'));
}
if (drush_get_option('bootstrap')) {
echo file_get_contents(SITE_AUDIT_BASE_PATH . '/html/header.html');
}
// Header.
$report_time = dt('Generated on @time', array(
'@time' => date('r'),
));
// Prepare JSON format.
if (drush_get_option('json')) {
$report_all = array(
'time' => time(),
'reports' => array(),
);
}
elseif (drush_get_option('html')) {
$report_title = l(dt('Site Audit'), 'https://drupal.org/project/site_audit');
if ($url) {
$report_title .= ' ' . dt('report for !url', array(
'!url' => l($url, $url),
));
}
echo '<div class="page-header">';
echo '<h1>' . $report_title . '<br/><small>' . $report_time . '</small></h1>';
echo '</div>';
}
else {
if ($url) {
drush_print(dt('https://drupal.org/project/site_audit report for @url', array(
'@url' => $url,
)));
}
else {
drush_print(dt('https://drupal.org/project/site_audit report'));
}
drush_print($report_time);
drush_print();
}
// Table of Contents; HTML only.
if (drush_get_option('html') && !drush_get_option('json')) {
echo '<h2 id="top">' . dt('Summary') . '</h2>';
$buttons = array();
foreach ($reports_to_render as $report) {
$button_text = $report
->getLabel();
if ($report
->getPercent() != SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO) {
$button_text .= ' (' . $report
->getPercent() . '%)';
}
else {
$button_text .= ' (' . dt('Info') . ')';
}
$buttons[] = l($button_text, '', array(
'fragment' => get_class($report),
'external' => TRUE,
'attributes' => array(
'class' => array(
'btn',
'btn-' . $report
->getPercentCssClass(),
'btn-mini',
),
'style' => 'margin-bottom: 5px;',
),
));
}
echo '<p>' . implode(' ', $buttons) . '</p>';
}
// Render reports.
foreach ($reports_to_render as $report) {
if (drush_get_option('json')) {
$report_all['reports'][get_class($report)] = json_decode($report
->toJson());
}
else {
$report
->render();
}
if (drush_get_option('html') && !drush_get_option('json')) {
echo '<div>' . l(dt('Back to top'), '', array(
'fragment' => 'top',
'external' => TRUE,
'attributes' => array(
'class' => array(
'btn',
'btn-default',
'btn-mini',
),
),
)) . '</div>';
}
}
if (drush_get_option('bootstrap')) {
echo file_get_contents(SITE_AUDIT_BASE_PATH . '/html/footer.html');
}
}
if (drush_get_option('json')) {
echo json_encode($report_all);
return;
}
}