DBUpdateController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Services\CallApiService;
  4. use Illuminate\Http\Request;
  5. class DBUpdateController extends Controller
  6. {
  7. private $callApiService;
  8. public function __construct(CallApiService $callApiService)
  9. {
  10. $this->callApiService = $callApiService;
  11. }
  12. public function index()
  13. {
  14. $dbupdateProc = $this->callApiService->callApi([
  15. 'url' => 'dbupdate-proc',
  16. 'data' => [
  17. 'IsRun' => request('is_run', '0'),
  18. 'IsSkipUpdate' => env('IS_SKIP_DBUPDATE')
  19. ],
  20. ]);
  21. if (empty($dbupdateProc['Page'])) {
  22. return $this->redirectDashboard();
  23. }
  24. return view('pages.dbupdate-dashboard', ['dbupdateProc' => $dbupdateProc])
  25. ->with('codeTitle', [ "sort('dbupdate')" ]);
  26. }
  27. public function store()
  28. {
  29. $dbupdateProc = $this->callApiService->callApi([
  30. 'url' => 'dbupdate-proc',
  31. 'data' => [
  32. 'IsRun' => request('is_run', '0'),
  33. 'IsSkipUpdate' => env('IS_SKIP_DBUPDATE')
  34. ],
  35. ]);
  36. if (empty(request('is_run'))) {
  37. return redirect()->route('db-update.index');
  38. }
  39. if ($this->callApiService->verifyApiError($dbupdateProc)) {
  40. notify()->error(_e('Action failed'), 'Error', 'bottomRight');
  41. return redirect()->route('db-update.index');
  42. }
  43. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  44. return $this->redirectDashboard();
  45. }
  46. public function redirectDashboard()
  47. {
  48. session()->put('user.is_member', true);
  49. return redirect()->route('dashboard');
  50. }
  51. }