Bläddra i källkod

[Backend] Correctif newsletter

master
Guillaume 4 år sedan
förälder
incheckning
449db37906
1 ändrade filer med 20 tillägg och 9 borttagningar
  1. +20
    -9
      ShopBundle/Controller/Backend/NewsController.php

+ 20
- 9
ShopBundle/Controller/Backend/NewsController.php Visa fil

@@ -67,7 +67,9 @@ class NewsController extends AdminController
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ;
$countUsers = count($users) ;
$messagesArray = [];

$packageMessagesArray = [];
$packageMessageLimit = 50 ;

$paramsTemplate = [
'news' => $news,
@@ -75,9 +77,14 @@ class NewsController extends AdminController
'user' => $this->security->getUser()
] ;

$i = 0 ;
foreach ($users as $user) {
if(!isset($packageMessagesArray[$i])) {
$packageMessagesArray[$i] = [] ;
}

if($user->getEmail() && strlen($user->getEmail())) {
$messagesArray[] = [
$packageMessagesArray[$i][] = [
'To' => [
[
'Email' => $user->getEmail(),
@@ -94,18 +101,24 @@ class NewsController extends AdminController
'CustomCampaign' => $news->getTitle(),
'DeduplicateCampaign' => true
] ;

if(count($packageMessagesArray[$i]) >= $packageMessageLimit) {
$i ++ ;
}
}
}

if($countUsers > 0) {
$mj = new \Mailjet\Client($this->mailjetTransport->getApiKey(), $this->mailjetTransport->getApiSecret(),true,['version' => 'v3.1']);

$body = [
'Messages' => $messagesArray
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
foreach($packageMessagesArray as $messagesArray) {
$body = [
'Messages' => $messagesArray
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
}

if($response->success()) {
if(isset($response) && $response->success()) {
$this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.');

$news->setIsSent(true) ;
@@ -113,8 +126,6 @@ class NewsController extends AdminController
$this->em->flush() ;
}
else {
print_r($response->getBody()) ;
die() ;
$this->addFlash('error', "Une erreur est survenue lors de l'envoi de l'actualité.");
}
}

Laddar…
Avbryt
Spara