public function UpgradeStatusCommands::formatDrushStdoutResult in Upgrade Status 8.2
Same name and namespace in other branches
- 8.3 src/Commands/UpgradeStatusCommands.php \Drupal\upgrade_status\Commands\UpgradeStatusCommands::formatDrushStdoutResult()
Format results output for an extension for Drush STDOUT usage.
Parameters
\Drupal\Core\Extension\Extension $extension: Drupal extension objet.
Return value
array Scan results formatted for output, per line.
1 call to UpgradeStatusCommands::formatDrushStdoutResult()
- UpgradeStatusCommands::analyze in src/
Commands/ UpgradeStatusCommands.php - Analyze projects output as ASCII.
File
- src/
Commands/ UpgradeStatusCommands.php, line 265
Class
- UpgradeStatusCommands
- Upgrade Status Drush command
Namespace
Drupal\upgrade_status\CommandsCode
public function formatDrushStdoutResult(Extension $extension) {
$table = [];
$result = $this->resultFormatter
->getRawResult($extension);
$info = $extension->info;
$table[] = $info['name'] . ', ' . (!empty($info['version']) ? ' ' . $info['version'] : '--');
$table[] = dt('Scanned on @date', [
'@date' => $this->dateFormatter
->format($result['date']),
]);
if (isset($result['data']['totals'])) {
$project_error_count = $result['data']['totals']['file_errors'];
}
else {
$project_error_count = 0;
}
if (!$project_error_count || !is_array($result['data']['files'])) {
$table[] = '';
$table[] = dt('No known issues found.');
$table[] = '';
return $table;
}
foreach ($result['data']['files'] as $filepath => $errors) {
// Remove the Drupal root directory name. If this is a composer setup,
// then the webroot is in a web/ directory, add that back in for easy
// path copy-pasting.
$short_path = str_replace(DRUPAL_ROOT . '/', '', $filepath);
if (preg_match('!/web$!', DRUPAL_ROOT)) {
$short_path = 'web/' . $short_path;
}
$short_path = wordwrap(dt('FILE: ') . $short_path, 80, "\n", TRUE);
$table[] = '';
$table[] = $short_path;
$table[] = '';
$title_level = str_pad(dt('STATUS'), 15, ' ');
$title_line = str_pad(dt('LINE'), 5, ' ');
$title_msg = str_pad(dt('MESSAGE'), 60, ' ', STR_PAD_BOTH);
$table[] = $title_level . $title_line . $title_msg;
foreach ($errors['messages'] as $error) {
$table[] = str_pad('', 80, '-');
$error['message'] = str_replace("\n", ' ', $error['message']);
$error['message'] = str_replace(' ', ' ', $error['message']);
$error['message'] = trim($error['message']);
$level_label = dt('Check manually');
if ($error['upgrade_status_category'] == 'ignore') {
$level_label = dt('Ignore');
}
elseif ($error['upgrade_status_category'] == 'later') {
$level_label = dt('Fix later');
}
elseif (in_array($error['upgrade_status_category'], [
'safe',
'old',
])) {
$level_label = dt('Fix now');
}
$linecount = 0;
$msg_parts = explode("\n", wordwrap($error['message'], 60, "\n", TRUE));
foreach ($msg_parts as $msg_part) {
$msg_part = str_pad($msg_part, 60, ' ');
if (!$linecount++) {
$level_label = str_pad(substr($level_label, 0, 15), '15', ' ');
$line = str_pad($error['line'], 5, ' ');
}
else {
$level_label = str_pad(substr('', 0, 15), '15', ' ');
$line = str_pad('', 5, ' ');
}
$table[] = $level_label . $line . $msg_part;
}
}
$table[] = str_pad('', 80, '-');
}
if (!empty($result['plans'])) {
$table[] = '';
$table[] = DrupalUtil::drushRender($result['plans']);
}
$table[] = '';
return $table;
}