1
0
mirror of synced 2025-01-26 10:11:41 +03:00

Merge branch 'master' into add_command_output_formatting

This commit is contained in:
Alex Gridnev 2020-12-17 14:30:21 +03:00 committed by GitHub
commit 7a91ca3fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 293 additions and 94 deletions

View File

@ -2,8 +2,7 @@
namespace RetailCrm\DeliveryModuleBundle\Command; namespace RetailCrm\DeliveryModuleBundle\Command;
use Doctrine\ORM\Tools\Pagination\Paginator; use Doctrine\Persistence\ObjectManager;
use RetailCrm\DeliveryModuleBundle\Exception\AbstractModuleException;
use RetailCrm\DeliveryModuleBundle\Service\AccountManager; use RetailCrm\DeliveryModuleBundle\Service\AccountManager;
use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface; use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
@ -16,6 +15,8 @@ class StatusesCommand extends Command
{ {
use LockableTrait; use LockableTrait;
const QUERY_MAX_RESULTS = 100;
/** /**
* @var ModuleManagerInterface * @var ModuleManagerInterface
*/ */
@ -26,6 +27,11 @@ class StatusesCommand extends Command
*/ */
private $accountManager; private $accountManager;
/**
* @var ObjectManager
*/
private $entityManager;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -34,13 +40,15 @@ class StatusesCommand extends Command
$this $this
->setName('statuses:update') ->setName('statuses:update')
->setDescription('Update statuses') ->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->moduleManager = $moduleManager;
$this->accountManager = $accountManager; $this->accountManager = $accountManager;
$this->entityManager = $entityManager;
parent::__construct(); parent::__construct();
} }
@ -60,40 +68,57 @@ class StatusesCommand extends Command
? (int) $input->getArgument('accountId') ? (int) $input->getArgument('accountId')
: null; : null;
$paginator = []; $accountQueryBuilder = $this->accountManager->getActiveQueryBuilder()
->andWhere('account.id > :lastId')
->setMaxResults(static::QUERY_MAX_RESULTS)
;
if (null !== $accountId) { if (null !== $accountId) {
$paginator = [$this->accountManager - find($accountId)]; $accountQueryBuilder
} else { ->andWhere('account.id = :accountId')
$accountQuery = $this->accountManager->getRepository() ->setParameter('accountId', $accountId)
->createQueryBuilder('account') ;
->where('account.active = true')
->andWhere('account.freeze != true')
->addOrderBy('account.id')
->getQuery()
->setFirstResult(0)
->setMaxResults(100);
$paginator = new Paginator($accountQuery);
} }
$accountQuery = $accountQueryBuilder->getQuery();
$commandResult = 0;
$count = 0; $count = 0;
foreach ($paginator as $account) { $lastId = 0;
try { while (true) {
$count += $this->moduleManager $accountQuery->setParameter('lastId', $lastId);
->setAccount($account)
->updateStatuses() $result = $accountQuery->getResult();
; if (empty($result)) {
} catch (AbstractModuleException $e) { break;
$output->writeln(
"<error>Failed to update statuses for account {$account->getCrmUrl()}[{$account->getId()}]</error>"
);
$output->writeln("<error>Error: {$e->getMessage()}</error>");
} }
foreach ($result as $account) {
$lastId = $account->getId();
try {
$count += $this->moduleManager
->setAccount($account)
->updateStatuses()
;
} catch (\Exception $e) {
$output->writeln(
"<error>Failed to update statuses for account {$account->getCrmUrl()}[{$account->getId()}]</error>"
);
$output->writeln("<error>Error: {$e->getMessage()}</error>");
$commandResult = 1;
}
}
$this->entityManager->clear();
gc_collect_cycles();
} }
$output->writeln("<info>{$count} statuses updated.</info>"); $output->writeln("<info>{$count} statuses updated.</info>");
$this->release(); $this->release();
return 0; return $commandResult;
} }
} }

View File

@ -2,7 +2,7 @@
namespace RetailCrm\DeliveryModuleBundle\Command; namespace RetailCrm\DeliveryModuleBundle\Command;
use Doctrine\ORM\Tools\Pagination\Paginator; use Doctrine\Persistence\ObjectManager;
use RetailCrm\DeliveryModuleBundle\Service\AccountManager; use RetailCrm\DeliveryModuleBundle\Service\AccountManager;
use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface; use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
@ -15,6 +15,8 @@ class UpdateModuleCommand extends Command
{ {
use LockableTrait; use LockableTrait;
const QUERY_MAX_RESULTS = 100;
/** /**
* @var ModuleManagerInterface * @var ModuleManagerInterface
*/ */
@ -25,6 +27,11 @@ class UpdateModuleCommand extends Command
*/ */
private $accountManager; private $accountManager;
/**
* @var ObjectManager
*/
private $entityManager;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -33,13 +40,15 @@ class UpdateModuleCommand extends Command
$this $this
->setName('module:update') ->setName('module:update')
->setDescription('Update module') ->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->moduleManager = $moduleManager;
$this->accountManager = $accountManager; $this->accountManager = $accountManager;
$this->entityManager = $entityManager;
parent::__construct(); parent::__construct();
} }
@ -59,41 +68,59 @@ class UpdateModuleCommand extends Command
? $input->getArgument('accountId') ? $input->getArgument('accountId')
: null; : null;
$paginator = []; $accountQueryBuilder = $this->accountManager->getActiveQueryBuilder()
->andWhere('account.id > :lastId')
->setMaxResults(static::QUERY_MAX_RESULTS)
;
if (null !== $accountId) { if (null !== $accountId) {
$paginator = [$this->accountManager->find($accountId)]; $accountQueryBuilder
} else { ->andWhere('account.id = :accountId')
$accountQuery = $this->accountManager->getRepository() ->setParameter('accountId', $accountId)
->createQueryBuilder('account') ;
->where('account.active = true')
->andWhere('account.freeze != true')
->addOrderBy('account.id')
->getQuery()
->setFirstResult(0)
->setMaxResults(100);
$paginator = new Paginator($accountQuery);
} }
$accountQuery = $accountQueryBuilder->getQuery();
$commandResult = 0;
$count = 0; $count = 0;
foreach ($paginator as $account) {
try { $lastId = 0;
$this->moduleManager while (true) {
->setAccount($account) $accountQuery->setParameter('lastId', $lastId);
->updateModuleConfiguration()
; $result = $accountQuery->getResult();
++$count; if (empty($result)) {
} catch (\Exception $e) { break;
$output->writeln(
"<error>Failed to update configuration for account {$account->getCrmUrl()}[{$account->getId()}]</error>"
);
$output->writeln("<error>Error: {$e->getMessage()}</error>");
} }
foreach ($result as $account) {
$lastId = $account->getId();
try {
$this->moduleManager
->setAccount($account)
->updateModuleConfiguration()
;
++$count;
} catch (\Exception $e) {
$output->writeln(
"<error>Failed to update configuration for account {$account->getCrmUrl()}[{$account->getId()}]</error>"
);
$output->writeln("<error>Error: {$e->getMessage()}</error>");
$commandResult = 1;
}
}
$this->entityManager->clear();
gc_collect_cycles();
} }
$output->writeln("<info>{$count} modules updated.</info>"); $output->writeln("<info>{$count} modules updated.</info>");
$this->release(); $this->release();
return 0; return $commandResult;
} }
} }

View File

@ -66,12 +66,6 @@ class ClientIdSubscriber implements EventSubscriberInterface
if (null === $account) { if (null === $account) {
throw new AccessDeniedHttpException('ClientId not found'); 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); $this->moduleManager->setAccount($account);
} }

View File

@ -106,6 +106,17 @@ class Configuration
*/ */
public $selfShipmentAvailable = false; public $selfShipmentAvailable = false;
/**
* Возможность работы с заказом, содержащим несколько позиций с одинаковым торговым предложением
*
* @var bool
*
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("duplicateOrderProductSupported")
* @Serializer\Type("boolean")
*/
public $duplicateOrderProductSupported = true;
/** /**
* Разрешить отдельно передавать трек номер * Разрешить отдельно передавать трек номер
* *

View File

@ -79,7 +79,7 @@ class Customer
* *
* @Serializer\Groups({"get"}) * @Serializer\Groups({"get"})
* @Serializer\SerializedName("contragent") * @Serializer\SerializedName("contragent")
* @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\Model\Contragent") * @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\Contragent")
*/ */
public $contragent; public $contragent;

View File

@ -1,13 +1,14 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Request;
use Intaro\CRMBundle\Entity\Model\DeliveryTime; use RetailCrm\DeliveryModuleBundle\Model\DeliveryTime;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
use RetailCrm\DeliveryModuleBundle\Model\Traits\ExtraDataTrait;
class RequestCalculate class RequestCalculate
{ {
use Traits\ExtraDataTrait; use ExtraDataTrait;
/** /**
* Адрес отгрузки. * Адрес отгрузки.
@ -34,7 +35,7 @@ class RequestCalculate
/** /**
* Набор упаковок. * Набор упаковок.
* *
* @var Intaro\CRMDeliveryBundle\Form\Model\Package[] * @var RetailCrm\DeliveryModuleBundle\Model\Package[]
* *
* @Serializer\Groups({"request", "calculate"}) * @Serializer\Groups({"request", "calculate"})
* @Serializer\SerializedName("packages") * @Serializer\SerializedName("packages")

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Request;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Request;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -1,10 +1,10 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Request;
use Symfony\Component\Validator\Mapping\ClassMetadata; use RetailCrm\DeliveryModuleBundle\Model\Customer;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
use RetailCrm\DeliveryModuleBundle\Model\Manager;
class RequestSave class RequestSave
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Request;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -1,12 +1,13 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Request;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
use RetailCrm\DeliveryModuleBundle\Model\Traits\ExtraDataTrait;
class RequestShipmentSave class RequestShipmentSave
{ {
use Traits\ExtraDataTrait; use ExtraDataTrait;
/** /**
* Идентификатор отгрузки в службе доставки. Передается если требуется отредактировать уже оформленную отгрузку * Идентификатор отгрузки в службе доставки. Передается если требуется отредактировать уже оформленную отгрузку

View File

@ -1,8 +1,9 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Request;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
use RetailCrm\DeliveryModuleBundle\Model\StatusInfo;
class RequestStatusUpdateItem class RequestStatusUpdateItem
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -1,8 +1,9 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
use RetailCrm\DeliveryModuleBundle\Model\Terminal;
class ResponseCalculate class ResponseCalculate
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -1,9 +1,9 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use Symfony\Component\Validator\Mapping\ClassMetadata; use RetailCrm\DeliveryModuleBundle\Model\DeliveryAddress;
use Symfony\Component\Validator\Constraints as Assert; use RetailCrm\DeliveryModuleBundle\Model\StatusInfo;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
class ResponseLoadDeliveryData class ResponseLoadDeliveryData

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
class ResponseResult class ResponseResult
{ {

View File

@ -1,13 +1,9 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
use Intaro\CRMDeliveryBundle\Delivery\Generic\Generic;
class ResponseSave class ResponseSave
{ {
/** /**

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace RetailCrm\DeliveryModuleBundle\Model; namespace RetailCrm\DeliveryModuleBundle\Model\Response;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -23,4 +23,13 @@ class Store
* @Serializer\Type("string") * @Serializer\Type("string")
*/ */
public $name; public $name;
/**
* @var StoreWorkTime
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("workTime")
* @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\StoreWorkTime")
*/
public $workTime;
} }

71
Model/StoreWorkTime.php Normal file
View File

@ -0,0 +1,71 @@
<?php
namespace RetailCrm\DeliveryModuleBundle\Model;
use JMS\Serializer\Annotation as Serializer;
class StoreWorkTime
{
/**
* @var array<StoreWorkTimeItem>
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("mo")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\StoreWorkTimeItem>")
*/
public $monday;
/**
* @var array<StoreWorkTimeItem>
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("tu")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\StoreWorkTimeItem>")
*/
public $tuesday;
/**
* @var array<StoreWorkTimeItem>
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("we")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\StoreWorkTimeItem>")
*/
public $wednesday;
/**
* @var array<StoreWorkTimeItem>
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("th")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\StoreWorkTimeItem>")
*/
public $thursday;
/**
* @var array<StoreWorkTimeItem>
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("fr")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\StoreWorkTimeItem>")
*/
public $friday;
/**
* @var array<StoreWorkTimeItem>
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("sa")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\StoreWorkTimeItem>")
*/
public $saturday;
/**
* @var array<StoreWorkTimeItem>
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("su")
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\StoreWorkTimeItem>")
*/
public $sunday;
}

View File

@ -0,0 +1,44 @@
<?php
namespace RetailCrm\DeliveryModuleBundle\Model;
use JMS\Serializer\Annotation as Serializer;
class StoreWorkTimeItem
{
/**
* @var string
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("startTime")
* @Serializer\Type("string")
*/
public $startTime;
/**
* @var string
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("endTime")
* @Serializer\Type("string")
*/
public $endTime;
/**
* @var string
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("lunchStartTime")
* @Serializer\Type("string")
*/
public $lunchStartTime;
/**
* @var string
*
* @Serializer\Groups({"request"})
* @Serializer\SerializedName("lunchEndTime")
* @Serializer\Type("string")
*/
public $lunchEndTime;
}

View File

@ -52,4 +52,13 @@ class AccountManager
{ {
return $this->entityManager->getRepository($this->class); return $this->entityManager->getRepository($this->class);
} }
public function getActiveQueryBuilder()
{
return $this->getRepository()->createQueryBuilder('account')
->where('account.active = true')
->andWhere('account.freeze != true')
->orderBy('account.id')
;
}
} }

View File

@ -8,8 +8,16 @@ use RetailCrm\DeliveryModuleBundle\Model\Entity\DeliveryOrder;
class DeliveryOrderManager class DeliveryOrderManager
{ {
/**
* @var string
*/
protected $class; protected $class;
/**
* @var ObjectManager
*/
protected $entityManager;
public function __construct(string $deliveryOrderClass, ObjectManager $entityManager) public function __construct(string $deliveryOrderClass, ObjectManager $entityManager)
{ {
$this->class = $deliveryOrderClass; $this->class = $deliveryOrderClass;

View File

@ -85,7 +85,7 @@ abstract class ModuleManager implements ModuleManagerInterface
/** /**
* @var LoggerInterface * @var LoggerInterface
*/ */
private $logger; protected $logger;
public function __construct( public function __construct(
array $moduleParameters, array $moduleParameters,
@ -163,8 +163,9 @@ abstract class ModuleManager implements ModuleManagerInterface
return true; return true;
} else { } else {
if ($this->logger) { if ($this->logger) {
$errorMsg = $response['error_msg'] ?? ''; $errorMsg = $response['errorMsg'] ?? '';
$this->logger->warning("Failed to update module configuration[account={$this->getAccount()->getCrmUrl()}]:{$errorMsg}"); $errors = json_encode($response['errors'] ?? '');
$this->logger->warning("Failed to update module configuration[account={$this->getAccount()->getCrmUrl()}]: {$errorMsg}. Detailed errors: {$errors}");
} }
return false; return false;