From bbf43d3ed8609b9cd27dcb1e6dfcb30d70a88b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Wed, 1 Dec 2021 13:16:29 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A6=AA=E3=82=92=E5=89=8A=E9=99=A4=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=82=89=E3=80=81=E5=AD=90=E3=83=AA=E3=83=AC=E3=83=BC?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=80=81=E4=BC=9A=E8=AD=B0=E3=80=81?= =?UTF-8?q?=E4=BC=9A=E8=AD=B0=E3=81=AEPDF=E3=80=81=E4=BC=9A=E8=AD=B0?= =?UTF-8?q?=E3=81=AE=E7=94=BB=E5=83=8F=E3=83=87=E3=83=BC=E3=82=BF=E5=8F=8A?= =?UTF-8?q?=E3=81=B3=E3=80=81=E4=BC=9A=E8=AD=B0=E3=81=AE=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=82=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/FathersController.php | 77 +++++++++++-------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/backend/app/Http/Controllers/Api/FathersController.php b/backend/app/Http/Controllers/Api/FathersController.php index 41f5a464..afb3fdd1 100644 --- a/backend/app/Http/Controllers/Api/FathersController.php +++ b/backend/app/Http/Controllers/Api/FathersController.php @@ -16,6 +16,8 @@ use Image; use App\Models\Father; use App\Models\FatherRelation; use App\Models\EmailActivation; +use App\Models\Meeting; +use App\Models\MeetingImage; use App\Models\MeetingApprovals; use App\Mail\FathersForgetPasswordMail; @@ -517,13 +519,38 @@ class FathersController extends Controller { } public function withdrawal (Request $r) { + $images = []; + $pdfs = []; + try { // DBに入ります。 DB::beginTransaction(); $father = Father::find((int)$r->father_id); + $rel = FatherRelation::where('father_id', (int)$r->father_id); + $meet = Meeting::where('father_id', (int)$r->father_id); + + if ($meet->count() > 0) { + foreach ($meet->get() as $n) { + $meim = MeetingImage::where('meeting_id', (int)$n->id); + $oldpdf = str_replace('/files/', '', $n->pdf); + $pdfs[] = $oldpdf; + + if ($meim->count() > 0) { + foreach ($meim->get() as $m) { + $oldimg = str_replace('/files/', '', $m->image); + $images[] = $oldimg; + } + } + } + } + $img = $father->image; + $father->delete(); + $rel->delete(); + $meet->delete(); + $meim->delete(); if (!is_null($img)) { $img = str_replace('/files/', '', $father->image); @@ -535,39 +562,29 @@ class FathersController extends Controller { } } - Session::forget($this->getGuard()); - DB::commit(); - } catch (\Throwable $e) { - // 失敗 - Log::critical($e->getMessage()); - DB::rollback(); - return ['status_code' => 400, 'error_messages' => ['親の削除に失敗しました。']]; - } - - // 成功 - return ['status_code' => 200, 'success_messages' => ['親の削除に成功しました。']]; - } - - public function delete ($father_id) { - try { - // DBに入ります。 - DB::beginTransaction(); - - $father = Father::find((int)$father_id); - $img = $father->image; - $father->delete(); - - if (!is_null($img)) { - $img = str_replace('/files/', '', $father->image); - if (!Storage::disk('private')->exists($img)) { - Log::warning($img.'というパスは不正です。'); - } - else { - Storage::disk('private')->delete($img); + if (!empty($pdfs)) { + foreach ($pdfs as $p) { + if (!Storage::disk('private')->exists($p)) { + Log::warning($p.'というパスは不正です。'); + } + else { + Storage::disk('private')->delete($p); + } } } - Session::forget($this->getGuard()); + if (!empty($images)) { + foreach ($images as $g) { + if (!Storage::disk('private')->exists($g)) { + Log::warning($g.'というパスは不正です。'); + } + else { + Storage::disk('private')->delete($g); + } + } + } + + Session::forget('fathers'); DB::commit(); } catch (\Throwable $e) { // 失敗