diff --git a/app/Http/Controllers/Web/Auth/LoginController.php b/app/Http/Controllers/Web/Auth/LoginController.php index d007fa1..2381c5e 100644 --- a/app/Http/Controllers/Web/Auth/LoginController.php +++ b/app/Http/Controllers/Web/Auth/LoginController.php @@ -25,6 +25,7 @@ class LoginController extends WebController public function __construct(protected LoginParam $param) { + parent::__construct(); } protected function run(Request $request): JsonResponse diff --git a/app/Http/Controllers/Web/Auth/LogoutController.php b/app/Http/Controllers/Web/Auth/LogoutController.php index daf7bc4..17642aa 100644 --- a/app/Http/Controllers/Web/Auth/LogoutController.php +++ b/app/Http/Controllers/Web/Auth/LogoutController.php @@ -25,6 +25,7 @@ class LogoutController extends WebController public function __construct(protected LogoutParam $param) { + parent::__construct(); } protected function run(Request $request): JsonResponse diff --git a/app/Http/Controllers/Web/Auth/MeController.php b/app/Http/Controllers/Web/Auth/MeController.php index a2c6aa2..17d7b78 100644 --- a/app/Http/Controllers/Web/Auth/MeController.php +++ b/app/Http/Controllers/Web/Auth/MeController.php @@ -2,12 +2,9 @@ namespace App\Http\Controllers\Web\Auth; -use App\Http\Controllers\Web\IParam; use App\Http\Controllers\Web\WebController; -use App\Models\User; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; class MeController extends WebController { @@ -26,6 +23,7 @@ class MeController extends WebController public function __construct(protected MeParam $param) { + parent::__construct(); } diff --git a/app/Http/Controllers/Web/WebController.php b/app/Http/Controllers/Web/WebController.php index eb46b7b..1071dc5 100644 --- a/app/Http/Controllers/Web/WebController.php +++ b/app/Http/Controllers/Web/WebController.php @@ -167,16 +167,23 @@ abstract class WebController extends BaseController $this->authorize(); - return $this->run($request); + $this->transaction->beginTransaction(); + $ret = $this->run($request); + $this->transaction->commit(); + return $ret; } catch (GeneralErrorMessageException $e) { + $this->transaction->rollBack(); return $this->failedResponse([], $e->getMessage()); } catch (AppCommonException $e) { + $this->transaction->rollBack(); logs()->error(sprintf("Appエラー:%s", $e->getMessage())); return $this->failedResponse(); } catch (ExclusiveException $e) { + $this->transaction->rollBack(); logs()->error(sprintf("排他エラー:%s", $e->getMessage())); return $this->exclusiveErrorResponse(); } catch (LogicException $e) { + $this->transaction->rollBack(); logs()->error([ sprintf("実装エラー:%s", $e->getMessage()), get_class($e), @@ -189,13 +196,16 @@ abstract class WebController extends BaseController }, ARRAY_FILTER_USE_BOTH)); return $this->failedResponse(); } catch (ValidationException $e) { + $this->transaction->rollBack(); return $this->validateErrorResponse($e); } catch (HttpException $e) { + $this->transaction->rollBack(); if ($e->getStatusCode() === 401) { return $this->unAuthorizedResponse(); } throw e; } catch (Exception $e) { + $this->transaction->rollBack(); logs()->error([ sprintf("例外エラー:%s", $e->getMessage()), get_class($e), diff --git a/app/Util/DBUtil.php b/app/Util/DBUtil.php index 22f676e..47a5fb4 100644 --- a/app/Util/DBUtil.php +++ b/app/Util/DBUtil.php @@ -22,7 +22,8 @@ class DBUtil public function beginTransaction(): void { if ($this->isBeginning) { - throw new LogicException("2重トランザクション開始検知"); + // throw new LogicException("2重トランザクション開始検知"); + return; } DB::beginTransaction(); @@ -32,7 +33,8 @@ class DBUtil public function commit(): void { if (!$this->isBeginning) { - throw new LogicException("無効なコミット検知"); + // throw new LogicException("無効なコミット検知"); + return; } DB::commit(); $this->isBeginning = false; @@ -41,7 +43,8 @@ class DBUtil public function rollBack(): void { if (!$this->isBeginning) { - throw new LogicException("無効なロールバック検知"); + // throw new LogicException("無効なロールバック検知"); + return; } DB::rollBack();