Skip to content

Commit

Permalink
licenses added to console package:list (#6052)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Blum <thomas@redaxo.de>
Co-authored-by: Gregor Harlan <mail@gh01.de>
  • Loading branch information
3 people committed Apr 7, 2024
1 parent d7390a9 commit c855369
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion redaxo/src/core/lib/console/package/list.php
Expand Up @@ -50,6 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'version' => $package->getVersion(),
'installed' => $package->isInstalled(),
'activated' => $package->isAvailable(),
'license' => $package->getLicense(),
];

if (!$jsonOutput) {
Expand Down Expand Up @@ -81,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return $usingExitCode ? (int) (0 === count($rows)) : 0;
}

$io->table(['package-id', 'author', 'version', 'installed', 'activated'], $rows);
$io->table(['package-id', 'author', 'version', 'installed', 'activated', 'license'], $rows);
return $usingExitCode ? (int) (0 === count($rows)) : 0;
}
}
21 changes: 21 additions & 0 deletions redaxo/src/core/lib/packages/package.php
Expand Up @@ -314,6 +314,27 @@ public function loadProperties(bool $force = false)
$this->propertiesLoaded = true;
}

public function getLicense(): ?string
{
$license = trim((string) $this->getProperty('license', ''));

if ('' !== $license) {
return $license;
}

if (is_readable($licenseFile = $this->getPath('LICENSE')) || is_readable($licenseFile = $this->getPath('LICENSE.md'))) {
$f = fopen($licenseFile, 'r');
$license = trim(fgets($f) ?: '');
fclose($f);

if (preg_match('/^The MIT License(?: \(MIT\))$/i', $license)) {
return 'MIT License';
}
}

return $license ?: null;
}

/**
* Clears the cache of the package.
*
Expand Down
16 changes: 4 additions & 12 deletions redaxo/src/core/pages/packages.list.php
Expand Up @@ -85,17 +85,9 @@
}
}

$license = '';
if (is_readable($licenseFile = $package->getPath('LICENSE.md')) || is_readable($licenseFile = $package->getPath('LICENSE'))) {
$f = fopen($licenseFile, 'r');
$firstLine = fgets($f) ?: '';
fclose($f);

if (preg_match('/^The MIT License(?: \(MIT\))$/i', $firstLine)) {
$firstLine = 'MIT License';
}

$license = '<a class="rex-link-expanded" href="' . rex_url::currentBackendPage(['subpage' => 'license', 'package' => $packageId]) . '" data-pjax-scroll-to="0"><i class="rex-icon rex-icon-license"></i> ' . rex_escape($firstLine) . '</a>';
$license = $package->getLicense();
if ($license) {
$license = '<a class="rex-link-expanded" href="' . rex_url::currentBackendPage(['subpage' => 'license', 'package' => $packageId]) . '" data-pjax-scroll-to="0"><i class="rex-icon rex-icon-license"></i> ' . rex_escape($license) . '</a>';
}

return '
Expand All @@ -106,7 +98,7 @@
<td class="rex-table-slim" data-title="' . rex_i18n::msg('package_hhelp') . '">
<a class="rex-link-expanded" href="' . rex_url::currentBackendPage(['subpage' => 'help', 'package' => $packageId]) . '" data-pjax-scroll-to="0" title="' . rex_i18n::msg('package_help') . ' ' . rex_escape($package->getName()) . '"><i class="rex-icon rex-icon-help"></i> ' . rex_i18n::msg('package_hhelp') . ' <span class="sr-only">' . rex_escape($package->getName()) . '</span></a>
</td>
<td class="rex-table-width-6" data-title="' . rex_i18n::msg('package_hlicense') . '">' . $license . '</td>
<td class="rex-table-width-6" data-title="' . rex_i18n::msg('package_hlicense') . '">' . ($license ?? '') . '</td>
<td class="rex-table-action">' . $install . '</td>
<td class="rex-table-action">' . $status . '</td>
<td class="rex-table-action">' . $uninstall . '</td>
Expand Down

0 comments on commit c855369

Please sign in to comment.