From bd84effedcb8edbc078b6504e387f712c0b32c2d Mon Sep 17 00:00:00 2001 From: shibafu Date: Sat, 23 May 2020 15:35:17 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=88?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E3=81=AA=E4=BB=B6=E6=95=B0=E3=81=AB=E4=B8=8A?= =?UTF-8?q?=E9=99=90=E3=82=92=E8=A8=AD=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/CheckinCsvImporter.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Services/CheckinCsvImporter.php b/app/Services/CheckinCsvImporter.php index f33785c..31ad354 100644 --- a/app/Services/CheckinCsvImporter.php +++ b/app/Services/CheckinCsvImporter.php @@ -17,6 +17,9 @@ use Throwable; class CheckinCsvImporter { + /** @var int 取り込み件数の上限 */ + private const IMPORT_LIMIT = 5000; + /** @var User Target user */ private $user; /** @var string CSV filename */ @@ -42,6 +45,7 @@ class CheckinCsvImporter // Import return DB::transaction(function () use ($csv) { + $alreadyImportedCount = $this->user->ejaculations()->where('ejaculation.source', Ejaculation::SOURCE_CSV)->count(); $errors = []; if (!in_array('日時', $csv->getHeader(), true)) { @@ -55,6 +59,12 @@ class CheckinCsvImporter $imported = 0; foreach ($csv->getRecords() as $offset => $record) { $line = $offset + 1; + if (self::IMPORT_LIMIT < $alreadyImportedCount + $imported) { + $limit = self::IMPORT_LIMIT; + $errors[] = "{$line} 行 : インポート機能で取り込めるデータは{$limit}件までに制限されています。これ以上取り込みできません。"; + throw new CsvImportException(...$errors); + } + $ejaculation = new Ejaculation(['user_id' => $this->user->id]); $validator = Validator::make($record, [