From 81f8bf84d3a83a4a9462ef63e444aaf60662ef38 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 4 May 2020 03:23:04 +0000 Subject: [PATCH] Made date an optional argument to command. #394 --- src/Command/WarrantySMSCommand.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Command/WarrantySMSCommand.php b/src/Command/WarrantySMSCommand.php index 3e8591aa..0b6f9d39 100644 --- a/src/Command/WarrantySMSCommand.php +++ b/src/Command/WarrantySMSCommand.php @@ -24,7 +24,7 @@ class WarrantySMSCommand extends Command $this->setName('warranty:sms') ->setDescription('Sends an SMS message to users whose warranty expired one month ago.') ->setHelp('Sends warranty SMS.') - ->addArgument('date', InputArgument::REQUIRED, 'Date to use as basis of expiration. Defaults to current date.'); + ->addArgument('date', InputArgument::OPTIONAL, 'Date to use as basis of expiration. Defaults to current date.'); } public function __construct(EntityManagerInterface $em, RisingTideGateway $gateway) @@ -37,9 +37,14 @@ class WarrantySMSCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { + $date = new DateTime(); $date_string = $input->getArgument('date'); - $date = DateTime::createFromFormat('Ymd', $date_string); - $date->modify('-1 month'); + + if (!empty($date_string)) + { + $date = DateTime::createFromFormat('Ymd', $date_string); + $date->modify('-1 month'); + } $warrs = $this->em->getRepository(Warranty::class)->findBy(['date_expire' => $date]);