画像を削除するようにしておかないと、トランザクションに失敗した時に「不要な画像が溜まる」
このコミットが含まれているのは:
コミット
26047a6125
|
@ -126,8 +126,6 @@ KIKI承知システムを使って「聞いてない!」「言ってない!
|
|||
|
||||
$ext = explode('/', mime_content_type($r->image))[1];
|
||||
$filename = $this->uuidv4() . '.'.$ext;
|
||||
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
||||
Storage::disk('public')->put($filename, $image);
|
||||
|
||||
$insert = [
|
||||
'identity' => $r->identity,
|
||||
|
@ -136,7 +134,6 @@ KIKI承知システムを使って「聞いてない!」「言ってない!
|
|||
'password' => $password,
|
||||
'last_name' => $r->last_name,
|
||||
'first_name' => $r->first_name,
|
||||
'image' => '/storage/'.$filename,
|
||||
'company' => $r->company,
|
||||
];
|
||||
|
||||
|
@ -145,6 +142,10 @@ KIKI承知システムを使って「聞いてない!」「言ってない!
|
|||
$child = new Child;
|
||||
$telact = TelActivation::where('token', $r->token)->first();
|
||||
|
||||
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
||||
Storage::disk('public')->put($filename, $image);
|
||||
$insert['image'] = '/storage/'.$filename;
|
||||
|
||||
$child->fill($insert);
|
||||
$child->push();
|
||||
|
||||
|
@ -156,6 +157,7 @@ KIKI承知システムを使って「聞いてない!」「言ってない!
|
|||
// 失敗
|
||||
Log::critical($e->getMessage());
|
||||
DB::rollback();
|
||||
Storage::disk('public')->delete($filename);
|
||||
return ['status_code' => 400, 'error_messages' => ['登録に失敗しました。']];
|
||||
}
|
||||
|
||||
|
@ -375,9 +377,10 @@ KIKI承知システムを使って「聞いてない!」「言ってない!
|
|||
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
||||
}
|
||||
|
||||
$ext = explode('/', mime_content_type($r->image))[1];
|
||||
$filename = $this->uuidv4() . '.'.$ext;
|
||||
|
||||
try {
|
||||
$ext = explode('/', mime_content_type($r->image))[1];
|
||||
$filename = $this->uuidv4() . '.'.$ext;
|
||||
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
||||
Storage::disk('public')->put($filename, $image);
|
||||
|
||||
|
@ -395,6 +398,7 @@ KIKI承知システムを使って「聞いてない!」「言ってない!
|
|||
} catch (\Throwable $e) {
|
||||
// 失敗
|
||||
Log::critical($e->getMessage());
|
||||
Storage::disk('public')->delete($filename);
|
||||
return ['status_code' => 400, 'error_messages' => ['画像の更新に失敗しました。']];
|
||||
}
|
||||
|
||||
|
|
|
@ -193,6 +193,7 @@ class FathersController extends Controller {
|
|||
// 本登録に失敗
|
||||
Log::critical($e->getMessage());
|
||||
DB::rollback();
|
||||
Storage::disk('public')->delete($filename);
|
||||
return ['status_code' => 400, 'error_messages' => ['本登録に失敗しました。']];
|
||||
}
|
||||
|
||||
|
|
|
@ -37,9 +37,10 @@ class MeetingImagesController extends Controller {
|
|||
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
||||
}
|
||||
|
||||
$ext = explode('/', mime_content_type($r->image))[1];
|
||||
$filename = $this->uuidv4() . '.'.$ext;
|
||||
|
||||
try {
|
||||
$ext = explode('/', mime_content_type($r->image))[1];
|
||||
$filename = $this->uuidv4() . '.'.$ext;
|
||||
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
||||
Storage::disk('public')->put($filename, $image);
|
||||
|
||||
|
@ -52,6 +53,7 @@ class MeetingImagesController extends Controller {
|
|||
} catch (\Throwable $e) {
|
||||
// 失敗
|
||||
Log::critical($e->getMessage());
|
||||
Storage::disk('public')->delete($filename);
|
||||
return ['status_code' => 400];
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,9 @@ class MeetingsController extends Controller {
|
|||
'memo' => $r->memo
|
||||
];
|
||||
|
||||
$filename = '';
|
||||
$fnames = [];
|
||||
|
||||
try {
|
||||
if (isset($r->pdf)) {
|
||||
$filename = $this->uuidv4() . '.pdf';
|
||||
|
@ -82,6 +85,7 @@ class MeetingsController extends Controller {
|
|||
if (substr($img, -5) != '.jpeg' && substr($img, -4) != '.jpg' && substr($img, -4) != '.png' && substr($img, -4) != '.gif') {
|
||||
$ext = explode('/', mime_content_type($img))[1];
|
||||
$fname = $this->uuidv4() . '.'.$ext;
|
||||
$fnames[] = $fname;
|
||||
$image = base64_decode(substr($img, strpos($img, ',') + 1));
|
||||
Storage::disk('public')->put($fname, $image);
|
||||
|
||||
|
@ -115,6 +119,14 @@ class MeetingsController extends Controller {
|
|||
} catch (\Throwable $e) {
|
||||
// 失敗
|
||||
Log::critical($e->getMessage());
|
||||
if (isset($r->pdf)) {
|
||||
Storage::disk('public')->delete($filename);
|
||||
}
|
||||
if (isset($r->image)) {
|
||||
foreach ($fnames as $f) {
|
||||
Storage::disk('public')->delete($f);
|
||||
}
|
||||
}
|
||||
return ['status_code' => 400, 'error_messages' => ['ミーティングの登録に失敗しました。']];
|
||||
}
|
||||
|
||||
|
@ -678,6 +690,8 @@ class MeetingsController extends Controller {
|
|||
if (isset($r->memo)) $update['memo'] = $r->memo;
|
||||
else if (is_null($r->memo)) $update['memo'] = '';
|
||||
|
||||
$filename = '';
|
||||
|
||||
try {
|
||||
// リクエストでPDFがある場合
|
||||
if (isset($r->pdf) && !is_null($r->pdf)) {
|
||||
|
@ -716,6 +730,9 @@ class MeetingsController extends Controller {
|
|||
Meeting::where('id', (int)$meeting_id)->update($update);
|
||||
} catch (\Throwable $e) {
|
||||
Log::critical($e->getMessage());
|
||||
if (isset($r->pdf) && !is_null($r->pdf)) {
|
||||
Storage::disk('public')->delete($filename);
|
||||
}
|
||||
return ['status_code' => 400];
|
||||
}
|
||||
|
||||
|
|
新しいイシューから参照