From ab67b455fb393f4a948b10d441edea0285b139ad Mon Sep 17 00:00:00 2001 From: gridnev Date: Thu, 3 Sep 2020 15:15:43 +0300 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 From 5b860d78b83c87dcdbb0de539665834b42ff46ef Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 16 Dec 2020 11:39:46 +0300 Subject: [PATCH 09/12] Add CommandOutputFormatterTrait --- .../Traits/CommandOutputFormatterTrait.php | 21 +++++++++++++++++++ 1 file changed, 21 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..9db1b4b --- /dev/null +++ b/Command/Traits/CommandOutputFormatterTrait.php @@ -0,0 +1,21 @@ +getMessage('INFO', $message); + } + + public function getErrorMessage(string $message): string + { + return $this->getMessage('ERROR', $message); + } +} \ No newline at end of file From 0760b28b2c471a1d989fb1c81cc09c22d6c91313 Mon Sep 17 00:00:00 2001 From: gridnev Date: Tue, 2 Mar 2021 13:30:17 +0300 Subject: [PATCH 10/12] fix printDocument method --- Service/ModuleManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/ModuleManager.php b/Service/ModuleManager.php index 67e301c..56430b2 100644 --- a/Service/ModuleManager.php +++ b/Service/ModuleManager.php @@ -244,7 +244,7 @@ abstract class ModuleManager implements ModuleManagerInterface { $deliveries = $this->deliveryManager->findBy([ 'account' => $this->account, - 'externalId' => $request->deliveryIds, + 'externalId' => $request->deliveryIds[0], ]); if (empty($deliveries)) { From 89e90a8555baef7162ea6f0171fe59a1924eade9 Mon Sep 17 00:00:00 2001 From: gridnev Date: Tue, 2 Mar 2021 15:11:01 +0300 Subject: [PATCH 11/12] fix printDocument method v2 --- Service/ModuleManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/ModuleManager.php b/Service/ModuleManager.php index 67e301c..bfdb670 100644 --- a/Service/ModuleManager.php +++ b/Service/ModuleManager.php @@ -244,7 +244,7 @@ abstract class ModuleManager implements ModuleManagerInterface { $deliveries = $this->deliveryManager->findBy([ 'account' => $this->account, - 'externalId' => $request->deliveryIds, + 'externalId' => $request->deliveryIds[0] ?? null, ]); if (empty($deliveries)) { From 5eb8487019e840761af96aa87f12358f3237b99b Mon Sep 17 00:00:00 2001 From: Ivan Lutokhin Date: Tue, 18 May 2021 09:23:45 +0300 Subject: [PATCH 12/12] Fix model namespaces --- Model/RequestCalculate.php | 4 ++-- Model/ResponseLoadDeliveryData.php | 2 +- Model/Settings.php | 5 ++--- Model/Unit.php | 2 ++ 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Model/RequestCalculate.php b/Model/RequestCalculate.php index 63acab0..7f9c94b 100644 --- a/Model/RequestCalculate.php +++ b/Model/RequestCalculate.php @@ -11,7 +11,7 @@ class RequestCalculate /** * Адрес отгрузки. * - * @var RetailCrm\DeliveryModuleBundle\Model\DeliveryAddress + * @var DeliveryAddress * * @Serializer\Groups({"request", "calculate"}) * @Serializer\SerializedName("shipmentAddress") @@ -33,7 +33,7 @@ class RequestCalculate /** * Набор упаковок. * - * @var RetailCrm\DeliveryModuleBundle\Model\Package[] + * @var Package[] * * @Serializer\Groups({"request", "calculate"}) * @Serializer\SerializedName("packages") diff --git a/Model/ResponseLoadDeliveryData.php b/Model/ResponseLoadDeliveryData.php index ccca5f1..7a6491d 100644 --- a/Model/ResponseLoadDeliveryData.php +++ b/Model/ResponseLoadDeliveryData.php @@ -50,7 +50,7 @@ class ResponseLoadDeliveryData /** * Время доставки - * @var RetailCrm\DeliveryModuleBundle\Model\DeliveryTime + * @var DeliveryTime * * @Serializer\Groups({"response"}) * @Serializer\SerializedName("deliveryTime") diff --git a/Model/Settings.php b/Model/Settings.php index b97c484..4464a85 100644 --- a/Model/Settings.php +++ b/Model/Settings.php @@ -3,7 +3,6 @@ namespace RetailCrm\DeliveryModuleBundle\Model; use JMS\Serializer\Annotation as Serializer; -use RetailCrm\DeliveryModuleBundle\Model\Settings\ExtraData; use RetailCrm\DeliveryModuleBundle\Model\Settings\PaymentType; use RetailCrm\DeliveryModuleBundle\Model\Settings\ShipmentPoint; use RetailCrm\DeliveryModuleBundle\Model\Settings\Status; @@ -77,7 +76,7 @@ class Settings public $statuses; /** - * @var array|ExtraData[] + * @var array * * @Serializer\Groups({"set", "get"}) * @Serializer\SerializedName("deliveryExtraData") @@ -86,7 +85,7 @@ class Settings public $deliveryExtraData; /** - * @var array|ExtraData[] + * @var array * * @Serializer\Groups({"set", "get"}) * @Serializer\SerializedName("shipmentExtraData") diff --git a/Model/Unit.php b/Model/Unit.php index 4f45d32..c46abe8 100644 --- a/Model/Unit.php +++ b/Model/Unit.php @@ -2,6 +2,8 @@ namespace RetailCrm\DeliveryModuleBundle\Model; +use JMS\Serializer\Annotation as Serializer; + class Unit { /**