use table helper

This commit is contained in:
Uwe Steinmann 2025-11-13 17:58:48 +01:00
parent 98cb3b042d
commit 799b870f9a

View File

@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Helper\Table;
use Seeddms\Seeddms\Settings;
use Seeddms\Seeddms\Translator;
@ -48,36 +49,39 @@ class ListcacheCommand extends Command
$outformat = '%-20s %-40s %15s %7d';
require_once('inc/inc.DBInit.php');
$cachedir = $settings->_cacheDir;
$totalc = 0;
$totalspace = 0;
// Preview for png, pdf, and txt */
foreach(['png', 'pdf', 'txt'] as $t) {
$path = addDirSep($cachedir).$t;
if(file_exists($path)) {
$space = dskspace($path);
$fi = new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS);
$c = iterator_count($fi);
} else {
$space = $c = 0;
}
$totalc += $c;
$totalspace += $space;
$output->writeln(sprintf($outformat, 'preview'.$t, $translator->translate('preview_'.$t), SeedDMS_Core_File::format_filesize($space), $c));
}
$cachedir = $settings->_cacheDir;
$totalc = 0;
$totalspace = 0;
$tabledata = [];
// Preview for png, pdf, and txt */
foreach(['png', 'pdf', 'txt'] as $t) {
$path = addDirSep($cachedir).$t;
if(file_exists($path)) {
$space = dskspace($path);
$fi = new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS);
$c = iterator_count($fi);
} else {
$space = $c = 0;
}
$totalc += $c;
$totalspace += $space;
// $output->writeln(sprintf($outformat, 'preview'.$t, $translator->translate('preview_'.$t), SeedDMS_Core_File::format_filesize($space), $c));
$tabledata[] = ['preview'.$t, $translator->translate('preview_'.$t), SeedDMS_Core_File::format_filesize($space), $c];
}
/* Javascript */
$path = addDirSep($cachedir).'js';
if(file_exists($path)) {
$space = dskspace($path);
$fi = new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS);
$c = iterator_count($fi);
} else {
$space = $c = 0;
}
$totalc += $c;
$totalspace += $space;
$output->writeln(sprintf($outformat, 'js', $translator->translate('temp_jscode'), SeedDMS_Core_File::format_filesize($space), $c));
/* Javascript */
$path = addDirSep($cachedir).'js';
if(file_exists($path)) {
$space = dskspace($path);
$fi = new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS);
$c = iterator_count($fi);
} else {
$space = $c = 0;
}
$totalc += $c;
$totalspace += $space;
// $output->writeln(sprintf($outformat, 'js', $translator->translate('temp_jscode'), SeedDMS_Core_File::format_filesize($space), $c));
$tabledata[] = ['js', $translator->translate('temp_jscode'), SeedDMS_Core_File::format_filesize($space), $c];
$caches = [];
/* Create a dummy view for passing it to additionalCache() */
@ -90,8 +94,14 @@ class ListcacheCommand extends Command
}
}
foreach($caches as $cache) {
$output->writeln(sprintf($outformat, $cache[0], $cache[1], SeedDMS_Core_File::format_filesize($cache[2]), $cache[3]));
// $output->writeln(sprintf($outformat, $cache[0], $cache[1], SeedDMS_Core_File::format_filesize($cache[2]), $cache[3]));
$tabledata[] = [$cache[0], $cache[1], SeedDMS_Core_File::format_filesize($cache[2]), $cache[3]];
}
$table = new Table($output);
$table
->setHeaders(['Cache', 'Name', 'Size', 'Count'])
->setRows($tabledata);
$table->render();
// print_r($caches);
return Command::SUCCESS;