85 lines
2.2 KiB
PHP
85 lines
2.2 KiB
PHP
<?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::OPTIONAL, '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');
|
|
|
|
// if date is specified
|
|
if (!empty($date_string))
|
|
$date = DateTime::createFromFormat('Ymd', $date_string);
|
|
else
|
|
$date = new DateTime();
|
|
|
|
// -1 month
|
|
$date->modify('-1 month');
|
|
|
|
$warrs = $this->em->getRepository(Warranty::class)->findBy(['date_expire' => $date]);
|
|
|
|
foreach ($warrs as $w)
|
|
{
|
|
error_log($w->getID() . ' - ' . $w->getMobileNumber());
|
|
// check valid number
|
|
$num = trim($w->getMobileNumber());
|
|
|
|
// should start with '9'
|
|
if ($num[0] != '9')
|
|
continue;
|
|
|
|
// should be 10 digits
|
|
if (strlen($num) != 10)
|
|
continue;
|
|
|
|
// should be numeric
|
|
if (!is_numeric($num))
|
|
continue;
|
|
|
|
error_log('valid!');
|
|
|
|
// add 63 prefix
|
|
$num = '63' . $num;
|
|
}
|
|
|
|
/*
|
|
error_log('sending sms to ' . $number);
|
|
$msg = 'This is a test.';
|
|
$this->gateway->sendSMS($number, 'MOTOLITE', $msg);
|
|
|
|
return 0;
|
|
*/
|
|
}
|
|
}
|