diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index 6a975fd..f888b6a 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -96,9 +96,9 @@ class SettingController extends Controller set_time_limit(0); $importer = new CheckinCsvImporter(Auth::user(), $file->path()); - $importer->execute(); + $imported = $importer->execute(); - return redirect()->route('setting.import')->with('status', 'インポートに性交しました。'); + return redirect()->route('setting.import')->with('status', "{$imported}件のインポートに性交しました。"); } catch (CsvImportException $e) { return redirect()->route('setting.import')->with('import_errors', $e->getErrors()); } diff --git a/app/Services/CheckinCsvImporter.php b/app/Services/CheckinCsvImporter.php index 834ca5f..e03ae4d 100644 --- a/app/Services/CheckinCsvImporter.php +++ b/app/Services/CheckinCsvImporter.php @@ -27,7 +27,7 @@ class CheckinCsvImporter $this->filename = $filename; } - public function execute() + public function execute(): int { // Guess charset $charset = $this->guessCharset($this->filename); @@ -40,7 +40,7 @@ class CheckinCsvImporter } // Import - DB::transaction(function () use ($csv) { + return DB::transaction(function () use ($csv) { $errors = []; if (!in_array('日時', $csv->getHeader(), true)) { @@ -51,6 +51,7 @@ class CheckinCsvImporter throw new CsvImportException(...$errors); } + $imported = 0; foreach ($csv->getRecords() as $offset => $record) { $line = $offset + 1; $ejaculation = new Ejaculation(['user_id' => $this->user->id]); @@ -87,6 +88,7 @@ class CheckinCsvImporter $ejaculation->tags()->sync(collect($tags)->pluck('id')); } DB::commit(); + $imported++; } catch (QueryException $e) { DB::rollBack(); if ($e->errorInfo[0] === '23505') { @@ -103,6 +105,8 @@ class CheckinCsvImporter if (!empty($errors)) { throw new CsvImportException(...$errors); } + + return $imported; }); }