settings = $settings; $this->logger = $logger; $this->translator = $translator; parent::__construct(); } protected function configure() { $this->setName('cache:list') ->setDescription('List caches') ->setHelp('Lists all caches including size.') ; } protected function execute(InputInterface $input, OutputInterface $output) : int { $app = $this->getApplication(); $settings = $this->settings; $logger = $this->logger; $translator = $this->translator; $outformat = '%-20s %-40s %15s %7d'; require_once('inc/inc.DBInit.php'); $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)); $tabledata[] = ['js', $translator->translate('temp_jscode'), SeedDMS_Core_File::format_filesize($space), $c]; $caches = []; /* Create a dummy view for passing it to additionalCache() */ $view = new SeedDMS_View_Common(['settings'=>$settings]); if (isset($GLOBALS['SEEDDMS_HOOKS']['view']['clearCache'])) { foreach ($GLOBALS['SEEDDMS_HOOKS']['view']['clearCache'] as $hookObj) { if (method_exists($hookObj, 'additionalCache')) { $caches += $hookObj->additionalCache($view); } } } foreach($caches as $cache) { // $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; } } // vim: ts=4 sw=4 expandtab