ResumeTaskAction.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Module\Cleanup\AdminControllers\Actions;
  3. use App\Module\Cleanup\Services\CleanupService;
  4. use Dcat\Admin\Grid\RowAction;
  5. use Dcat\Admin\Actions\Response;
  6. use Illuminate\Http\Request;
  7. /**
  8. * 恢复任务Action
  9. *
  10. * 用于恢复已暂停的清理任务
  11. */
  12. class ResumeTaskAction extends RowAction
  13. {
  14. /**
  15. * 按钮标题
  16. */
  17. protected $title = '恢复任务';
  18. /**
  19. * 处理请求
  20. */
  21. public function handle(Request $request)
  22. {
  23. try {
  24. $taskId = $this->getKey();
  25. // 调用服务恢复任务
  26. $result = CleanupService::resumeTask($taskId);
  27. if (!$result['success']) {
  28. return $this->response()
  29. ->error('恢复失败:' . $result['message']);
  30. }
  31. return $this->response()
  32. ->success('任务恢复成功!')
  33. ->detail('任务已恢复执行,将从暂停点继续。')
  34. ->refresh();
  35. } catch (\Exception $e) {
  36. return $this->response()
  37. ->error('恢复失败:' . $e->getMessage());
  38. }
  39. }
  40. /**
  41. * 确认对话框
  42. */
  43. public function confirm()
  44. {
  45. return [
  46. '确认恢复任务?',
  47. '任务将从暂停点继续执行。'
  48. ];
  49. }
  50. /**
  51. * 权限检查
  52. */
  53. public function allowed()
  54. {
  55. $row = $this->row;
  56. return $row->status == 7; // 只有已暂停的任务可以恢复
  57. }">
  58. <i class="fa fa-play"></i> {$this->title}
  59. </a>
  60. HTML;
  61. }
  62. }