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/Traits/CommandOutputFormatterTrait.php b/Command/Traits/CommandOutputFormatterTrait.php
new file mode 100644
index 0000000..689f9e1
--- /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);
+ }
+}
diff --git a/Command/UpdateModuleCommand.php b/Command/UpdateModuleCommand.php
index a5e6632..f2ce0fd 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();
}
@@ -56,44 +65,61 @@ class UpdateModuleCommand extends Command
}
$accountId = $input->getArgument('accountId')
- ? $input->getArgument('accountId')
- : null;
+ ?: null;
+
+ $accountQueryBuilder = $this->accountManager->getActiveQueryBuilder()
+ ->andWhere('account.id > :lastId')
+ ->setMaxResults(static::QUERY_MAX_RESULTS)
+ ;
- $paginator = [];
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/Model/BaseStore.php b/Model/BaseStore.php
new file mode 100644
index 0000000..509a924
--- /dev/null
+++ b/Model/BaseStore.php
@@ -0,0 +1,26 @@
+")
+ */
+ public $shipmentDate;
+
/**
* Дата доставки.
*
@@ -117,4 +129,15 @@ class RequestCalculate
* @Serializer\Type("array")
*/
public $extraData;
+
+ /**
+ * Склад отгрузки.
+ *
+ * @var BaseStore
+ *
+ * @Serializer\Groups({"request", "calculate"})
+ * @Serializer\SerializedName("store")
+ * @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\BaseStore")
+ */
+ public $store;
}
diff --git a/Model/Response/ResponseAutocompleteItem.php b/Model/Response/ResponseAutocompleteItem.php
index 6aac639..8a5186a 100644
--- a/Model/Response/ResponseAutocompleteItem.php
+++ b/Model/Response/ResponseAutocompleteItem.php
@@ -1,6 +1,6 @@
+ *
+ * @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;
+}
diff --git a/Model/StoreWorkTimeItem.php b/Model/StoreWorkTimeItem.php
new file mode 100644
index 0000000..0950266
--- /dev/null
+++ b/Model/StoreWorkTimeItem.php
@@ -0,0 +1,44 @@
+entityManager->getRepository($this->class);
}
+
+ public function getActiveQueryBuilder()
+ {
+ return $this->getRepository()->createQueryBuilder('account')
+ ->where('account.active = true')
+ ->andWhere('account.freeze != 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;
diff --git a/Service/ModuleManager.php b/Service/ModuleManager.php
index d20f512..da488ab 100644
--- a/Service/ModuleManager.php
+++ b/Service/ModuleManager.php
@@ -79,7 +79,7 @@ abstract class ModuleManager implements ModuleManagerInterface
/**
* @var LoggerInterface
*/
- private $logger;
+ protected $logger;
public function __construct(
array $moduleParameters,
@@ -157,8 +157,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;
@@ -238,7 +239,7 @@ abstract class ModuleManager implements ModuleManagerInterface
{
$deliveries = $this->deliveryManager->findBy([
'account' => $this->account,
- 'externalId' => $request->deliveryIds,
+ 'externalId' => $request->deliveryIds[0] ?? null,
]);
if (empty($deliveries)) {
diff --git a/composer.json b/composer.json
index 77b9f3a..766a1ed 100644
--- a/composer.json
+++ b/composer.json
@@ -20,15 +20,21 @@
"jms/serializer-bundle": "^3.5",
"ramsey/uuid": "^3.9",
"ramsey/uuid-doctrine": "^1.5",
- "retailcrm/api-client-php": "^5.0.0",
- "symfony/framework-bundle": "^3.4|^4.0|^5.1",
- "symfony/lock": "^5.1",
- "symfony/routing": "^5.1",
- "symfony/translation": "^5.1",
- "symfony/validator": "^5.1"
+ "retailcrm/api-client-php": "dev-add-logger@dev",
+ "symfony/framework-bundle": "^3.4|^4.0|^5.0",
+ "symfony/lock": "^5.0",
+ "symfony/routing": "^5.0",
+ "symfony/translation": "^5.0",
+ "symfony/validator": "^5.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3",
"friendsofphp/php-cs-fixer": "^2.0"
- }
+ },
+ "repositories": [
+ {
+ "type": "vcs",
+ "url": "https://github.com/raulleo/api-client-php.git"
+ }
+ ]
}