* pending sms display
This commit is contained in:
parent
a40ac5fb70
commit
1225f8f391
@ -7,6 +7,7 @@ return [
|
||||
App\Command\KoinImportCommand::class => App\Command\KoinImportCommandFactory::class,
|
||||
App\Command\PeriodicSZEPCommand::class => App\Command\PeriodicSZEPCommandFactory::class,
|
||||
App\Command\DebugCommand::class => App\Command\DebugCommandFactory::class,
|
||||
App\Command\PendingCommand::class => App\Command\PendingCommandFactory::class,
|
||||
],
|
||||
],
|
||||
'console' => [
|
||||
@ -14,6 +15,7 @@ return [
|
||||
App\Command\KoinImportCommand::class,
|
||||
App\Command\PeriodicSZEPCommand::class,
|
||||
App\Command\DebugCommand::class,
|
||||
App\Command\PendingCommand::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
60
src/App/Command/PendingCommand.php
Normal file
60
src/App/Command/PendingCommand.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Sms;
|
||||
use App\Service\SmsStoreService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class PendingCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var SmsStoreService
|
||||
*/
|
||||
private $smsStoreService;
|
||||
|
||||
public function __construct(SmsStoreService $smsStoreService)
|
||||
{
|
||||
$this->smsStoreService = $smsStoreService;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('pending:show')
|
||||
->setDescription('Show failed koin import SMS entries');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$pendingImports = $this->smsStoreService->getFailedImports();
|
||||
$output->writeln("<info>Pengind SMS:</info>");
|
||||
$section = $output->section();
|
||||
$table = new Table($section);
|
||||
$table->setHeaders([
|
||||
'Id',
|
||||
'Text',
|
||||
'Date',
|
||||
]);
|
||||
/** @var Sms $sms */
|
||||
foreach ($pendingImports as $sms) {
|
||||
$table->addRow([
|
||||
$sms->getId(),
|
||||
$sms->getText(),
|
||||
$sms->getOccuredAt()->format("Y-m-d H:i"),
|
||||
]);
|
||||
}
|
||||
$table->render();
|
||||
}
|
||||
}
|
||||
18
src/App/Command/PendingCommandFactory.php
Normal file
18
src/App/Command/PendingCommandFactory.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\SmsStoreService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PendingCommandFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var SmsStoreService $smsStoreService */
|
||||
$smsStoreService = $container->get(SmsStoreService::class);
|
||||
return new PendingCommand($smsStoreService);
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,12 @@ namespace App\Service;
|
||||
|
||||
use App\Entity\Sms;
|
||||
use App\Entity\User;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\OptimisticLockException;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Exception;
|
||||
use Zend\EventManager\EventManager;
|
||||
|
||||
class SmsStoreService
|
||||
@ -28,8 +33,9 @@ class SmsStoreService
|
||||
* @param int $direction
|
||||
* @param array $requestData
|
||||
* @return bool
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws ORMException
|
||||
* @throws OptimisticLockException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function storeSms(string $hashKey, int $direction, array $requestData): bool
|
||||
{
|
||||
@ -39,7 +45,7 @@ class SmsStoreService
|
||||
$sms->setDirection($direction)
|
||||
->setContactName($requestData['contactName'])
|
||||
->setContactNumber($requestData['contactNumber'])
|
||||
->setOccuredAt(new \DateTime($normalizedDate))
|
||||
->setOccuredAt(new DateTime($normalizedDate))
|
||||
->setOwner($user)
|
||||
->setText($requestData['text']);
|
||||
$this->em->persist($sms);
|
||||
@ -55,8 +61,8 @@ class SmsStoreService
|
||||
/**
|
||||
* @param string $hashKey
|
||||
* @return User
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws ORMException
|
||||
* @throws OptimisticLockException
|
||||
*/
|
||||
private function ensureUserExists(string $hashKey): User
|
||||
{
|
||||
@ -74,4 +80,13 @@ class SmsStoreService
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function getFailedImports(): array
|
||||
{
|
||||
return $this->em->getRepository(Sms::class)->findBy([
|
||||
'parsedAndHandled' => false,
|
||||
], [
|
||||
'occuredAt' => 'ASC'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user