Merge branch '394-warranty-expiration-sms-reminder' of gitlab.com:jankstudio/resq into 394-warranty-expiration-sms-reminder
This commit is contained in:
commit
416441c572
1 changed files with 59 additions and 0 deletions
59
src/Command/WarrantySMSCommand.php
Normal file
59
src/Command/WarrantySMSCommand.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Service\RisingTideGateway;
|
||||
use App\Entity\Warranty;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class WarrantySMSCommand extends Command
|
||||
{
|
||||
protected $gateway;
|
||||
protected $em;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$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.');
|
||||
}
|
||||
|
||||
public function __construct(EntityManagerInterface $em, RisingTideGateway $gateway)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->gateway = $gateway;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$date_string = $input->getArgument('date');
|
||||
$date = DateTime::createFromFormat('Ymd', $date_string);
|
||||
$date->modify('-1 month');
|
||||
|
||||
$warrs = $this->em->getRepository(Warranty::class)->findBy(['date_expire' => $date]);
|
||||
|
||||
foreach ($warrs as $w)
|
||||
{
|
||||
error_log($w->getID());
|
||||
}
|
||||
|
||||
/*
|
||||
error_log('sending sms to ' . $number);
|
||||
$msg = 'This is a test.';
|
||||
$this->gateway->sendSMS($number, 'MOTOLITE', $msg);
|
||||
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue