-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exception for one customer does not sto the export
- Loading branch information
Franck Allimant
committed
Nov 16, 2023
1 parent
4c37ff7
commit 275b971
Showing
2 changed files
with
25 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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,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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters