From 275b971eb628edbb7c618823e6cefebb2854e64a Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 16 Nov 2023 19:14:17 +0100 Subject: [PATCH] Exception for one customer does not sto the export --- Command/BrevoExportCustomerCommand.php | 43 ++++++++++++++------------ Config/module.xml | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Command/BrevoExportCustomerCommand.php b/Command/BrevoExportCustomerCommand.php index 8a7eb8c..0a755f8 100644 --- a/Command/BrevoExportCustomerCommand.php +++ b/Command/BrevoExportCustomerCommand.php @@ -1,12 +1,20 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Brevo\Command; -use Brevo\Api\BrevoClient; use Brevo\Brevo; use Brevo\Services\BrevoCustomerService; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Thelia\Command\ContainerAwareCommand; @@ -15,20 +23,17 @@ class BrevoExportCustomerCommand extends ContainerAwareCommand { - public function __construct( private BrevoCustomerService $brevoCustomerService - ) - { + ) { parent::__construct(); } - protected function configure() + protected function configure(): void { $this - ->setName("brevo:export:customers") - ->setDescription("Export customers to brevo"); - + ->setName('brevo:export:customers') + ->setDescription('Export customers to brevo'); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -37,6 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (null === ConfigQuery::read(Brevo::CONFIG_API_SECRET)) { $output->writeln('Please configure this module in the back office'); + return Command::FAILURE; } @@ -44,22 +50,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progressBar = ProgressBarHelper::createProgressBar($output, $customers->count()); - try { - foreach ($customers as $customer) { - $progressBar->setMessage("".$customer->getEmail().""); + foreach ($customers as $customer) { + $progressBar->setMessage(''.$customer->getEmail().''); + try { $this->brevoCustomerService->createUpdateContact($customer->getId()); - - $progressBar->advance(); + } catch (\Exception $exception) { + $progressBar->setMessage(''.$exception->getMessage().''); } - $progressBar->finish(); - } catch (\Exception $exception) { - $output->writeln('error during import : '.$exception->getMessage()); - $progressBar->setMessage("".$exception->getMessage().""); + $progressBar->advance(); } - $output->writeln(" customer export done."); + $progressBar->finish(); + + $output->writeln(' customer export done.'); return Command::SUCCESS; } diff --git a/Config/module.xml b/Config/module.xml index cc093ed..f807240 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -13,7 +13,7 @@ en_US fr_FR - 1.1.9 + 1.1.10 Chabreuil Antoine