From 1daab343e00dffdcdbc3530440a10e020063860b Mon Sep 17 00:00:00 2001 From: gridnev Date: Thu, 9 Jul 2020 17:20:59 +0300 Subject: [PATCH 01/10] Remove account isActive and isFreeze checks from ClientIdSubscriber --- EventSubscriber/ClientIdSubscriber.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/EventSubscriber/ClientIdSubscriber.php b/EventSubscriber/ClientIdSubscriber.php index f6e6439..47193e7 100644 --- a/EventSubscriber/ClientIdSubscriber.php +++ b/EventSubscriber/ClientIdSubscriber.php @@ -66,12 +66,6 @@ class ClientIdSubscriber implements EventSubscriberInterface if (null === $account) { throw new AccessDeniedHttpException('ClientId not found'); } - if (!$account->isActive()) { - throw new AccessDeniedHttpException('Account is not active'); - } - if ($account->isFreeze()) { - throw new AccessDeniedHttpException('Account is freezed'); - } $this->moduleManager->setAccount($account); } From 8a49cdd1d3433b79eda08919d52161b1daa39982 Mon Sep 17 00:00:00 2001 From: gridnev Date: Thu, 9 Jul 2020 17:26:08 +0300 Subject: [PATCH 02/10] Add duplicateOrderProductSupported field in Configuration model --- Model/Configuration.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Model/Configuration.php b/Model/Configuration.php index 98ccaff..4cb6c6c 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -106,6 +106,17 @@ class Configuration */ public $selfShipmentAvailable = false; + /** + * Возможность работы с заказом, содержащим несколько позиций с одинаковым торговым предложением + * + * @var bool + * + * @Serializer\Groups({"set", "get"}) + * @Serializer\SerializedName("duplicateOrderProductSupported") + * @Serializer\Type("boolean") + */ + public $duplicateOrderProductSupported = true; + /** * Разрешить отдельно передавать трек номер * From ab67b455fb393f4a948b10d441edea0285b139ad Mon Sep 17 00:00:00 2001 From: gridnev Date: Thu, 3 Sep 2020 15:15:43 +0300 Subject: [PATCH 03/10] Fix logging in updateModuleConfiguration method --- Service/ModuleManager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Service/ModuleManager.php b/Service/ModuleManager.php index 67e301c..a0ec619 100644 --- a/Service/ModuleManager.php +++ b/Service/ModuleManager.php @@ -163,8 +163,9 @@ abstract class ModuleManager implements ModuleManagerInterface return true; } else { if ($this->logger) { - $errorMsg = $response['error_msg'] ?? ''; - $this->logger->warning("Failed to update module configuration[account={$this->getAccount()->getCrmUrl()}]:{$errorMsg}"); + $errorMsg = $response['errorMsg'] ?? ''; + $errors = json_encode($response['errors'] ?? ''); + $this->logger->warning("Failed to update module configuration[account={$this->getAccount()->getCrmUrl()}]: {$errorMsg}. Detailed errors: {$errors}"); } return false; From 1583739691ac6b94cc1302ae9965cb12dabe8d57 Mon Sep 17 00:00:00 2001 From: gridnev Date: Thu, 3 Sep 2020 16:01:07 +0300 Subject: [PATCH 04/10] Make logger protected in ModuleManager --- Service/ModuleManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/ModuleManager.php b/Service/ModuleManager.php index 67e301c..f121b17 100644 --- a/Service/ModuleManager.php +++ b/Service/ModuleManager.php @@ -85,7 +85,7 @@ abstract class ModuleManager implements ModuleManagerInterface /** * @var LoggerInterface */ - private $logger; + protected $logger; public function __construct( array $moduleParameters, From a58480c77ada16623e2cffc09ebc607ff24197b8 Mon Sep 17 00:00:00 2001 From: gridnev Date: Tue, 8 Sep 2020 16:27:37 +0300 Subject: [PATCH 05/10] Fix Request/Response namespaces --- Model/Request/RequestCalculate.php | 9 +++++---- Model/Request/RequestDelete.php | 2 +- Model/Request/RequestPrint.php | 2 +- Model/Request/RequestSave.php | 6 +++--- Model/Request/RequestShipmentDelete.php | 2 +- Model/Request/RequestShipmentSave.php | 5 +++-- Model/Request/RequestStatusUpdateItem.php | 3 ++- Model/Response/ResponseAutocompleteItem.php | 2 +- Model/Response/ResponseAutocompleteSuccessful.php | 2 +- Model/Response/ResponseCalculate.php | 3 ++- Model/Response/ResponseCalculateSuccessful.php | 2 +- Model/Response/ResponseLoadDeliveryData.php | 6 +++--- Model/Response/ResponseResult.php | 2 +- Model/Response/ResponseSave.php | 6 +----- Model/Response/ResponseShipmentSave.php | 2 +- Model/Response/ResponseSuccessful.php | 2 +- 16 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Model/Request/RequestCalculate.php b/Model/Request/RequestCalculate.php index f0eb59e..a5dad7b 100644 --- a/Model/Request/RequestCalculate.php +++ b/Model/Request/RequestCalculate.php @@ -1,13 +1,14 @@ Date: Wed, 9 Sep 2020 09:47:49 +0300 Subject: [PATCH 06/10] Fix Contragent serializer type in Customer --- Model/Customer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Customer.php b/Model/Customer.php index 83b18ec..30b250d 100644 --- a/Model/Customer.php +++ b/Model/Customer.php @@ -79,7 +79,7 @@ class Customer * * @Serializer\Groups({"get"}) * @Serializer\SerializedName("contragent") - * @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\Model\Contragent") + * @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\Contragent") */ public $contragent; From fb844786f126afce6f3fb68a9f97ae6efc2e66dd Mon Sep 17 00:00:00 2001 From: gridnev Date: Fri, 6 Nov 2020 11:35:47 +0300 Subject: [PATCH 07/10] add workTime to Store model --- Model/Store.php | 9 +++++ Model/StoreWorkTime.php | 71 +++++++++++++++++++++++++++++++++++++ Model/StoreWorkTimeItem.php | 44 +++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 Model/StoreWorkTime.php create mode 100644 Model/StoreWorkTimeItem.php diff --git a/Model/Store.php b/Model/Store.php index 87c2e96..62441db 100644 --- a/Model/Store.php +++ b/Model/Store.php @@ -23,4 +23,13 @@ class Store * @Serializer\Type("string") */ public $name; + + /** + * @var StoreWorkTime + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("workTime") + * @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\StoreWorkTime") + */ + public $workTime; } diff --git a/Model/StoreWorkTime.php b/Model/StoreWorkTime.php new file mode 100644 index 0000000..b262967 --- /dev/null +++ b/Model/StoreWorkTime.php @@ -0,0 +1,71 @@ + + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("mo") + * @Serializer\Type("array") + */ + public $monday; + + /** + * @var array + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("tu") + * @Serializer\Type("array") + */ + public $tuesday; + + /** + * @var array + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("we") + * @Serializer\Type("array") + */ + public $wednesday; + + /** + * @var array + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("th") + * @Serializer\Type("array") + */ + public $thursday; + + /** + * @var array + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("fr") + * @Serializer\Type("array") + */ + public $friday; + + /** + * @var array + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("sa") + * @Serializer\Type("array") + */ + public $saturday; + + /** + * @var array + * + * @Serializer\Groups({"request"}) + * @Serializer\SerializedName("su") + * @Serializer\Type("array") + */ + public $sunday; +} \ No newline at end of file diff --git a/Model/StoreWorkTimeItem.php b/Model/StoreWorkTimeItem.php new file mode 100644 index 0000000..80ebac8 --- /dev/null +++ b/Model/StoreWorkTimeItem.php @@ -0,0 +1,44 @@ + Date: Mon, 16 Nov 2020 13:54:23 +0300 Subject: [PATCH 08/10] Fixed account selection in StatusesCommand and UpdateModuleConfigurationCommand --- Command/StatusesCommand.php | 81 ++++++++++++++++++++----------- Command/UpdateModuleCommand.php | 83 +++++++++++++++++++++----------- Service/AccountManager.php | 9 ++++ Service/DeliveryOrderManager.php | 8 +++ 4 files changed, 125 insertions(+), 56 deletions(-) diff --git a/Command/StatusesCommand.php b/Command/StatusesCommand.php index 3168b18..1a92722 100644 --- a/Command/StatusesCommand.php +++ b/Command/StatusesCommand.php @@ -2,8 +2,7 @@ namespace RetailCrm\DeliveryModuleBundle\Command; -use Doctrine\ORM\Tools\Pagination\Paginator; -use RetailCrm\DeliveryModuleBundle\Exception\AbstractModuleException; +use Doctrine\Persistence\ObjectManager; use RetailCrm\DeliveryModuleBundle\Service\AccountManager; use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface; use Symfony\Component\Console\Command\Command; @@ -16,6 +15,8 @@ class StatusesCommand extends Command { use LockableTrait; + const QUERY_MAX_RESULTS = 100; + /** * @var ModuleManagerInterface */ @@ -26,6 +27,11 @@ class StatusesCommand extends Command */ private $accountManager; + /** + * @var ObjectManager + */ + private $entityManager; + /** * {@inheritdoc} */ @@ -34,13 +40,15 @@ class StatusesCommand extends Command $this ->setName('statuses:update') ->setDescription('Update statuses') - ->addArgument('accountId', InputArgument::OPTIONAL, 'Choose account, or make it for all'); + ->addArgument('accountId', InputArgument::OPTIONAL, 'Choose account, or make it for all') + ; } - public function __construct(ModuleManagerInterface $moduleManager, AccountManager $accountManager) + public function __construct(ModuleManagerInterface $moduleManager, AccountManager $accountManager, ObjectManager $entityManager) { $this->moduleManager = $moduleManager; $this->accountManager = $accountManager; + $this->entityManager = $entityManager; parent::__construct(); } @@ -60,40 +68,57 @@ class StatusesCommand extends Command ? (int) $input->getArgument('accountId') : null; - $paginator = []; + $accountQueryBuilder = $this->accountManager->getActiveQueryBuilder() + ->andWhere('account.id > :lastId') + ->setMaxResults(static::QUERY_MAX_RESULTS) + ; + if (null !== $accountId) { - $paginator = [$this->accountManager - find($accountId)]; - } else { - $accountQuery = $this->accountManager->getRepository() - ->createQueryBuilder('account') - ->where('account.active = true') - ->andWhere('account.freeze != true') - ->addOrderBy('account.id') - ->getQuery() - ->setFirstResult(0) - ->setMaxResults(100); - $paginator = new Paginator($accountQuery); + $accountQueryBuilder + ->andWhere('account.id = :accountId') + ->setParameter('accountId', $accountId) + ; } + $accountQuery = $accountQueryBuilder->getQuery(); + + $commandResult = 0; $count = 0; - foreach ($paginator as $account) { - try { - $count += $this->moduleManager - ->setAccount($account) - ->updateStatuses() - ; - } catch (AbstractModuleException $e) { - $output->writeln( - "Failed to update statuses for account {$account->getCrmUrl()}[{$account->getId()}]" - ); - $output->writeln("Error: {$e->getMessage()}"); + $lastId = 0; + while (true) { + $accountQuery->setParameter('lastId', $lastId); + + $result = $accountQuery->getResult(); + if (empty($result)) { + break; } + + foreach ($result as $account) { + $lastId = $account->getId(); + + try { + $count += $this->moduleManager + ->setAccount($account) + ->updateStatuses() + ; + } catch (\Exception $e) { + $output->writeln( + "Failed to update statuses for account {$account->getCrmUrl()}[{$account->getId()}]" + ); + $output->writeln("Error: {$e->getMessage()}"); + + $commandResult = 1; + } + } + + $this->entityManager->clear(); + gc_collect_cycles(); } $output->writeln("{$count} statuses updated."); $this->release(); - return 0; + return $commandResult; } } diff --git a/Command/UpdateModuleCommand.php b/Command/UpdateModuleCommand.php index a5e6632..e36be72 100644 --- a/Command/UpdateModuleCommand.php +++ b/Command/UpdateModuleCommand.php @@ -2,7 +2,7 @@ namespace RetailCrm\DeliveryModuleBundle\Command; -use Doctrine\ORM\Tools\Pagination\Paginator; +use Doctrine\Persistence\ObjectManager; use RetailCrm\DeliveryModuleBundle\Service\AccountManager; use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface; use Symfony\Component\Console\Command\Command; @@ -15,6 +15,8 @@ class UpdateModuleCommand extends Command { use LockableTrait; + const QUERY_MAX_RESULTS = 100; + /** * @var ModuleManagerInterface */ @@ -25,6 +27,11 @@ class UpdateModuleCommand extends Command */ private $accountManager; + /** + * @var ObjectManager + */ + private $entityManager; + /** * {@inheritdoc} */ @@ -33,13 +40,15 @@ class UpdateModuleCommand extends Command $this ->setName('module:update') ->setDescription('Update module') - ->addArgument('accountId', InputArgument::OPTIONAL, 'Choose account, or make it for all'); + ->addArgument('accountId', InputArgument::OPTIONAL, 'Choose account, or make it for all') + ; } - public function __construct(ModuleManagerInterface $moduleManager, AccountManager $accountManager) + public function __construct(ModuleManagerInterface $moduleManager, AccountManager $accountManager, ObjectManager $entityManager) { $this->moduleManager = $moduleManager; $this->accountManager = $accountManager; + $this->entityManager = $entityManager; parent::__construct(); } @@ -59,41 +68,59 @@ class UpdateModuleCommand extends Command ? $input->getArgument('accountId') : null; - $paginator = []; + $accountQueryBuilder = $this->accountManager->getActiveQueryBuilder() + ->andWhere('account.id > :lastId') + ->setMaxResults(static::QUERY_MAX_RESULTS) + ; + if (null !== $accountId) { - $paginator = [$this->accountManager->find($accountId)]; - } else { - $accountQuery = $this->accountManager->getRepository() - ->createQueryBuilder('account') - ->where('account.active = true') - ->andWhere('account.freeze != true') - ->addOrderBy('account.id') - ->getQuery() - ->setFirstResult(0) - ->setMaxResults(100); - $paginator = new Paginator($accountQuery); + $accountQueryBuilder + ->andWhere('account.id = :accountId') + ->setParameter('accountId', $accountId) + ; } + $accountQuery = $accountQueryBuilder->getQuery(); + + $commandResult = 0; $count = 0; - foreach ($paginator as $account) { - try { - $this->moduleManager - ->setAccount($account) - ->updateModuleConfiguration() - ; - ++$count; - } catch (\Exception $e) { - $output->writeln( - "Failed to update configuration for account {$account->getCrmUrl()}[{$account->getId()}]" - ); - $output->writeln("Error: {$e->getMessage()}"); + + $lastId = 0; + while (true) { + $accountQuery->setParameter('lastId', $lastId); + + $result = $accountQuery->getResult(); + if (empty($result)) { + break; } + + foreach ($result as $account) { + $lastId = $account->getId(); + + try { + $this->moduleManager + ->setAccount($account) + ->updateModuleConfiguration() + ; + ++$count; + } catch (\Exception $e) { + $output->writeln( + "Failed to update configuration for account {$account->getCrmUrl()}[{$account->getId()}]" + ); + $output->writeln("Error: {$e->getMessage()}"); + + $commandResult = 1; + } + } + + $this->entityManager->clear(); + gc_collect_cycles(); } $output->writeln("{$count} modules updated."); $this->release(); - return 0; + return $commandResult; } } diff --git a/Service/AccountManager.php b/Service/AccountManager.php index d9da37c..97d7f44 100644 --- a/Service/AccountManager.php +++ b/Service/AccountManager.php @@ -52,4 +52,13 @@ class AccountManager { return $this->entityManager->getRepository($this->class); } + + public function getActiveQueryBuilder() + { + return $this->getRepository()->createQueryBuilder('account') + ->where('account.isActive IS TRUE') + ->andWhere('account.isFreeze IS NOT TRUE') + ->orderBy('account.id') + ; + } } diff --git a/Service/DeliveryOrderManager.php b/Service/DeliveryOrderManager.php index e68390f..4f8161c 100644 --- a/Service/DeliveryOrderManager.php +++ b/Service/DeliveryOrderManager.php @@ -8,8 +8,16 @@ use RetailCrm\DeliveryModuleBundle\Model\Entity\DeliveryOrder; class DeliveryOrderManager { + /** + * @var string + */ protected $class; + /** + * @var ObjectManager + */ + protected $entityManager; + public function __construct(string $deliveryOrderClass, ObjectManager $entityManager) { $this->class = $deliveryOrderClass; From 55cb647511c9b7d2b57d851d9fc7d3d1cda20027 Mon Sep 17 00:00:00 2001 From: Alexander Kozlov Date: Tue, 17 Nov 2020 15:04:27 +0300 Subject: [PATCH 09/10] Fixed typo in AccountManager --- Service/AccountManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Service/AccountManager.php b/Service/AccountManager.php index 97d7f44..99f7441 100644 --- a/Service/AccountManager.php +++ b/Service/AccountManager.php @@ -56,8 +56,8 @@ class AccountManager public function getActiveQueryBuilder() { return $this->getRepository()->createQueryBuilder('account') - ->where('account.isActive IS TRUE') - ->andWhere('account.isFreeze IS NOT TRUE') + ->where('account.active = true') + ->andWhere('account.freeze != true') ->orderBy('account.id') ; } From a6ac3c1f587bbd4ea0c5bde869180880bf9b95d3 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 16 Dec 2020 11:39:46 +0300 Subject: [PATCH 10/10] Add CommandOutputFormatterTrait --- Command/Traits/CommandOutputFormatterTrait.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Command/Traits/CommandOutputFormatterTrait.php diff --git a/Command/Traits/CommandOutputFormatterTrait.php b/Command/Traits/CommandOutputFormatterTrait.php new file mode 100644 index 0000000..f2a27ca --- /dev/null +++ b/Command/Traits/CommandOutputFormatterTrait.php @@ -0,0 +1,16 @@ +output('INFO', $message); + } +} \ No newline at end of file