From b4bf5212e968fbd25c3dc4627aa7b61eb21ecd39 Mon Sep 17 00:00:00 2001 From: Peter Dulacka Date: Tue, 26 Nov 2024 10:31:54 +0100 Subject: [PATCH] Fix calendar seeder if it's already prepopulated remp/crm#3337 (cherry picked from commit 47b7cf92000a0b05f53c4759643936c5bb3cbe66) --- src/Seeders/CalendarSeeder.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Seeders/CalendarSeeder.php b/src/Seeders/CalendarSeeder.php index b7217fd..0ebedd3 100644 --- a/src/Seeders/CalendarSeeder.php +++ b/src/Seeders/CalendarSeeder.php @@ -19,7 +19,9 @@ public function seed(OutputInterface $output) $lastRecord = $this->database->query('SELECT * FROM `calendar` ORDER BY `id` DESC LIMIT 1;')->fetch(); if ($lastRecord) { - $nextDate = (new \DateTime($lastRecord['date']))->modify('+1 day'); + /** @var \DateTime $lastDate */ + $lastDate = $lastRecord['date']; + $nextDate = $lastDate->modify('+1 day'); } else { $nextDate = new \DateTime('2014-01-01 00:00:00'); } @@ -45,7 +47,9 @@ public function seed(OutputInterface $output) $nextDate->modify('+1 day'); } - $this->database->query('INSERT INTO calendar ', $dates); + if (count($dates)) { + $this->database->query('INSERT INTO calendar ', $dates); + } $output->writeln(' * calendar seeded with dates until ' . $thresholdDate->format('Y-m-d') . ''); }