| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use App\Module\Cleanup\Services\CleanupService;
- use Dcat\Admin\Grid\Tools\AbstractTool;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- /**
- * 清理过期备份Action
- *
- * 用于清理过期的备份文件
- */
- class CleanExpiredBackupsAction extends AbstractTool
- {
- /**
- * 按钮标题
- */
- protected $title = '清理过期备份';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- $dryRun = $request->input('dry_run', false);
-
- // 调用服务清理过期备份
- $result = CleanupService::cleanExpiredBackups($dryRun);
-
- if (!$result['success']) {
- return $this->response()
- ->error('清理失败:' . $result['message']);
- }
-
- $data = $result['data'];
-
- if ($dryRun) {
- return $this->response()
- ->success('预览完成')
- ->detail("
- 发现过期备份:{$data['expired_count']} 个<br>
- 预计释放空间:{$data['estimated_freed_space']}<br>
- <br>
- <small>这是预览模式,没有实际删除任何文件。</small>
- ");
- } else {
- return $this->response()
- ->success('清理完成!')
- ->detail("
- 删除过期备份:{$data['deleted_count']} 个<br>
- 释放空间:{$data['freed_space']}<br>
- 清理时间:{$data['execution_time']}秒
- ")
- ->refresh();
- }
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('清理失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- */
- public function confirm()
- {
- return [
- '清理过期备份',
- '将删除所有已过期的备份文件,释放存储空间。',
- [
- 'dry_run' => [
- 'type' => 'checkbox',
- 'label' => '预览模式',
- 'checked' => true,
- 'help' => '勾选则只预览,不实际删除文件',
- ]
- ]
- ];
- }
- }
|