Skip to content

Commit

Permalink
Exception for one customer does not sto the export
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Nov 16, 2023
1 parent 4c37ff7 commit 275b971
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
43 changes: 24 additions & 19 deletions Command/BrevoExportCustomerCommand.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <[email protected]>
*
* 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;
Expand All @@ -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
Expand All @@ -37,29 +42,29 @@ 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;
}

$customers = CustomerQuery::create()->find();

$progressBar = ProgressBarHelper::createProgressBar($output, $customers->count());

try {
foreach ($customers as $customer) {
$progressBar->setMessage("<info>".$customer->getEmail()."</info>");
foreach ($customers as $customer) {
$progressBar->setMessage('<info>'.$customer->getEmail().'</info>');

try {
$this->brevoCustomerService->createUpdateContact($customer->getId());

$progressBar->advance();
} catch (\Exception $exception) {
$progressBar->setMessage('<error>'.$exception->getMessage().'</error>');
}

$progressBar->finish();
} catch (\Exception $exception) {
$output->writeln('error during import : '.$exception->getMessage());
$progressBar->setMessage("<error>".$exception->getMessage()."</error>");
$progressBar->advance();
}

$output->writeln(" customer export done.");
$progressBar->finish();

$output->writeln(' customer export done.');

return Command::SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.1.9</version>
<version>1.1.10</version>
<authors>
<author>
<name>Chabreuil Antoine</name>
Expand Down

0 comments on commit 275b971

Please sign in to comment.