33 lines
1.0 KiB
PHP
33 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\command;
|
|
|
|
use app\common\service\mobilerecording\MobileRecordingStorage;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
use think\console\input\Option;
|
|
|
|
final class MobileRecordingCleanup extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('mobile-recording:cleanup')->setDescription('清理无数据库引用且超过一天的私有录音孤儿文件')
|
|
->addOption('dry-run', null, Option::VALUE_NONE, '只统计,不删除');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output): int
|
|
{
|
|
try {
|
|
$result = MobileRecordingStorage::cleanupOrphans((bool) $input->getOption('dry-run'));
|
|
$output->writeln('MOBILE_RECORDING_CLEANUP ' . json_encode($result));
|
|
return $result['errors'] > 0 ? 1 : 0;
|
|
} catch (\Throwable $e) {
|
|
$output->writeln('MOBILE_RECORDING_CLEANUP storage_or_configuration_error');
|
|
return 1;
|
|
}
|
|
}
|
|
}
|