This commit is contained in:
2025-08-15 14:34:48 +08:00
parent d8ef43508f
commit f57512a312

View File

@@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use ZipArchive;
class Logzip extends Command class Logzip extends Command
{ {
@@ -29,24 +29,23 @@ class Logzip extends Command
*/ */
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$dir_arr = [ // $dir_arr = [
'runtime/admin/log/', // 'runtime/logs/',
'runtime/api/log/', // ];
'runtime/czg/log/', $dir = 'runtime/logs/';
'runtime/log/',
];
$yestermonth = date("Ym");
// 如果今天是1号 // 如果今天是1号
if(date('d') == 01 || date('d') == 1) { $yestermonth = date("Y-m-d", strtotime('-1 day'));
$yestermonth = date("Ym", strtotime('-1 month')); $file_p = 'webman-' . $yestermonth . '.log';
} $dir .= $file_p;
foreach ($dir_arr as $dir_a) { // foreach ($dir_arr as $dir_a) {
$file_arr = getYesterdayFiles($dir_a . $yestermonth . '/'); // $file_arr = getYesterdayFiles($dir_a . $yestermonth . '/');
if(!empty($file_arr['files'])) { // if(!empty($file_arr['files'])) {
foreach ($file_arr['files'] as $k => $file_p) { // foreach ($file_arr['files'] as $k => $file_p) {
$file = $dir_a . $yestermonth . '/' . $file_p; // $file = $dir_a . $yestermonth . '/' . $file_p;
$zip_filename = str_replace('.log', '.zip', $file_p); $file = $dir;
$file_zip = $dir_a . $yestermonth . '/' . $zip_filename; // $zip_filename = str_replace('.log', '.zip', $file);
$file_zip = str_replace('.log', '.zip', $file);
// $file_zip = $dir_a . $yestermonth . '/' . $zip_filename;
$is_close = false; $is_close = false;
if(!file_exists($file_zip)) { if(!file_exists($file_zip)) {
$zip = new ZipArchive(); $zip = new ZipArchive();
@@ -59,16 +58,14 @@ class Logzip extends Command
} }
if ($is_close) { if ($is_close) {
if($zip->close()) { if($zip->close()) {
if($is_close) { unlink($file);
unlink($file);
}
} }
} }
} }
} }
} // }
} // }
} // }
$output->writeln('ok'); $output->writeln('ok');
return self::SUCCESS; return self::SUCCESS;
} }