74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use ZipArchive;
|
|
|
|
class Logzip extends Command
|
|
{
|
|
protected static $defaultName = 'logzip';
|
|
protected static $defaultDescription = 'logzip';
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
protected function configure()
|
|
{
|
|
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
|
|
}
|
|
|
|
/**
|
|
* @param InputInterface $input
|
|
* @param OutputInterface $output
|
|
* @return int
|
|
*/
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
// $dir_arr = [
|
|
// 'runtime/logs/',
|
|
// ];
|
|
$dir = 'runtime/logs/';
|
|
// 如果今天是1号
|
|
$yestermonth = date("Y-m-d", strtotime('-1 day'));
|
|
$file_p = 'webman-' . $yestermonth . '.log';
|
|
$dir .= $file_p;
|
|
// foreach ($dir_arr as $dir_a) {
|
|
// $file_arr = getYesterdayFiles($dir_a . $yestermonth . '/');
|
|
// if(!empty($file_arr['files'])) {
|
|
// foreach ($file_arr['files'] as $k => $file_p) {
|
|
// $file = $dir_a . $yestermonth . '/' . $file_p;
|
|
$file = $dir;
|
|
// $zip_filename = str_replace('.log', '.zip', $file);
|
|
$file_zip = str_replace('.log', '.zip', $file);
|
|
// $file_zip = $dir_a . $yestermonth . '/' . $zip_filename;
|
|
$is_close = false;
|
|
if(!file_exists($file_zip)) {
|
|
$zip = new ZipArchive();
|
|
if($zip->open($file_zip, ZipArchive::CREATE) === TRUE) {
|
|
if(file_exists($file)) {
|
|
if($zip->addFile($file, $file_p)) {
|
|
$is_close = true;
|
|
print_r($file . "\r\n");
|
|
}
|
|
}
|
|
if ($is_close) {
|
|
if($zip->close()) {
|
|
unlink($file);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// }
|
|
// }
|
|
// }
|
|
$output->writeln('ok');
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
}
|