Skip to content

Commit

Permalink
Fix calendar seeder if it's already prepopulated
Browse files Browse the repository at this point in the history
remp/crm#3337

(cherry picked from commit 47b7cf92000a0b05f53c4759643936c5bb3cbe66)
  • Loading branch information
rootpd committed Nov 26, 2024
1 parent dabd8e2 commit b4bf521
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Seeders/CalendarSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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(' <comment>* calendar seeded with dates until ' . $thresholdDate->format('Y-m-d') . '</comment>');
}
Expand Down

0 comments on commit b4bf521

Please sign in to comment.