From 1225f8f391c0dda9e6ce5cefc854b6aca9ca3231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danyi=20D=C3=A1vid?= Date: Tue, 21 May 2019 20:48:18 +0200 Subject: [PATCH] * pending sms display --- config/autoload/cli.global.php | 2 + src/App/Command/PendingCommand.php | 60 +++++++++++++++++++++++ src/App/Command/PendingCommandFactory.php | 18 +++++++ src/App/Service/SmsStoreService.php | 25 ++++++++-- 4 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 src/App/Command/PendingCommand.php create mode 100644 src/App/Command/PendingCommandFactory.php diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php index 511d388..a01aed0 100644 --- a/config/autoload/cli.global.php +++ b/config/autoload/cli.global.php @@ -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, ], ], ]; diff --git a/src/App/Command/PendingCommand.php b/src/App/Command/PendingCommand.php new file mode 100644 index 0000000..d487e93 --- /dev/null +++ b/src/App/Command/PendingCommand.php @@ -0,0 +1,60 @@ +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("Pengind SMS:"); + $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(); + } +} diff --git a/src/App/Command/PendingCommandFactory.php b/src/App/Command/PendingCommandFactory.php new file mode 100644 index 0000000..488661d --- /dev/null +++ b/src/App/Command/PendingCommandFactory.php @@ -0,0 +1,18 @@ +get(SmsStoreService::class); + return new PendingCommand($smsStoreService); + } +} diff --git a/src/App/Service/SmsStoreService.php b/src/App/Service/SmsStoreService.php index 754cb7a..615c8ad 100644 --- a/src/App/Service/SmsStoreService.php +++ b/src/App/Service/SmsStoreService.php @@ -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' + ]); + } }