Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AUDUL committed Nov 23, 2023
1 parent a727810 commit 021b8b9
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 34 deletions.
2 changes: 2 additions & 0 deletions bundle/Command/SendMailingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

use Carbon\Carbon;
use CodeRhapsodie\IbexaMailingBundle\Core\Processor\SendMailingProcessorInterface as SendMailing;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand('ibexamailing:send:mailing')]
class SendMailingCommand extends Command
{
/**
Expand Down
15 changes: 7 additions & 8 deletions bundle/Command/SendMailingSubProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
use CodeRhapsodie\IbexaMailingBundle\Core\Mailer\Mailing;
use CodeRhapsodie\IbexaMailingBundle\Core\Provider\Broadcast;
use CodeRhapsodie\IbexaMailingBundle\Core\Provider\MailingContent;
use CodeRhapsodie\IbexaMailingBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use CodeRhapsodie\IbexaMailingBundle\Repository\BroadcastRepository;
use CodeRhapsodie\IbexaMailingBundle\Repository\UserRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'novaezmailing:send:mailing-subprocess', hidden: true)]
#[AsCommand(name: 'ibexamailing:send:mailing-subprocess', hidden: true)]
class SendMailingSubProcessCommand extends Command
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly BroadcastRepository $broadcastRepository,
private readonly UserRepository $userRepository,
private readonly MailingContent $mailingContent,
private readonly Broadcast $broadcastProvider,
private readonly Mailing $mailing
Expand All @@ -39,15 +40,13 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$userRepository = $this->entityManager->getRepository(User::class);
$broadcastRepository = $this->entityManager->getRepository(Broadcast::class);
$usersId = explode(',', $input->getOption('users-id'));
/** @var \CodeRhapsodie\IbexaMailingBundle\Entity\Broadcast $broadcast */
$broadcast = $broadcastRepository->find($input->getOption('broadcast-id'));
$broadcast = $this->broadcastRepository->find($input->getOption('broadcast-id'));
$mailing = $broadcast->getMailing();

foreach ($usersId as $userId) {
$user = $userRepository->find($userId);
$user = $this->userRepository->find($userId);
$contentMessage = $this->mailingContent->getContentMailing($mailing, $user, $broadcast);
$this->mailing->sendMessage($contentMessage);

Expand Down
8 changes: 6 additions & 2 deletions bundle/Controller/Admin/MailingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Ibexa\AdminUi\UI\Module\Subitems\ContentViewParameterSupplier;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Core\Helper\TranslationHelper;
use Ibexa\Core\MVC\Symfony\SiteAccess\Router;
use Ibexa\Core\MVC\Symfony\View\ContentView;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
Expand Down Expand Up @@ -180,9 +181,12 @@ public function testAction(
Mailing $mailing,
TestMailing $processor,
EntityManagerInterface $entityManager,
Registry $workflows
Registry $workflows,
Router $ibexaRouter
): RedirectResponse {
$machine = $workflows->get($mailing);
$siteaccess = $ibexaRouter->getSiteAccess()->name;

if ($machine->can($mailing, 'test')) {
$ccEmail = $request->request->get('cc');
if ($ccEmail !== '') {
Expand All @@ -192,6 +196,6 @@ public function testAction(
}
}

return $this->redirectToRoute('ibexamailing_mailing_show', ['mailing' => $mailing->getId()]);
return $this->redirectToRoute('ibexamailing_mailing_show', ['mailing' => $mailing->getId(), 'siteaccess' => $siteaccess]);
}
}
4 changes: 2 additions & 2 deletions bundle/Controller/TrackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function continueAction(
Request $request
): RedirectResponse {
$broadcast = $broadcastRepository->find($broadcastId);
$browser = new Browser($request->headers->get('UserRepository-Agent'));
$browser = new Browser($request->headers->get('user-agent', 'Unknown'));
$stat = new StatHit();
$decodedUrl = base64_decode(str_replace(['-', '_'], ['+', '/'], $url));
$stat
Expand All @@ -60,7 +60,7 @@ public function readAction(
BroadcastRepository $broadcastRepository
): Response {
$broadcast = $broadcastRepository->find($broadcastId);
$browser = new Browser($request->headers->get('UserRepository-Agent'));
$browser = new Browser($request->headers->get('user-agent', 'Unknown'));
$stat = new StatHit();
$stat
->setOsName($browser->getPlatform())
Expand Down
4 changes: 3 additions & 1 deletion bundle/Core/Mailer/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ private function fetchIterationFromUserList(array $users, int $iterationCount):
do {
$usersId = [];

foreach ($users as $user) {
foreach ($users as $key => $user) {
$usersId[] = $user->getId();
unset($users[$key]);

if (\count($usersId) === $iterationCount) {
$data = $usersId;
$usersId = [];
Expand Down
2 changes: 1 addition & 1 deletion bundle/Core/Mailer/MailingProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function getPhpProcess(int $broadcastId, array $usersId): Process
$subProcessArgs = [
$this->getPhpPath(),
$consolePath,
'novaezmailing:send:mailing-subprocess',
'ibexamailing:send:mailing-subprocess',
'--broadcast-id='.$broadcastId,
'--users-id='.implode(',', $usersId),
'--env='.$this->kernelEnv,
Expand Down
8 changes: 1 addition & 7 deletions bundle/Core/Provider/Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@

class Broadcast
{
/**
* @var EntityManagerInterface
*/
private $entityManager;

public function __construct(EntityManagerInterface $entityManager)
public function __construct(private readonly EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

public function start(Mailing $mailing, string $html): BroadcastEntity
Expand Down
15 changes: 8 additions & 7 deletions bundle/Core/Provider/MailingContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
use CodeRhapsodie\IbexaMailingBundle\Entity\Broadcast as BroadcastEntity;
use CodeRhapsodie\IbexaMailingBundle\Entity\Mailing;
use CodeRhapsodie\IbexaMailingBundle\Entity\User as UserEntity;
use Ibexa\Core\MVC\Symfony\SiteAccess\Router;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Expand All @@ -28,13 +29,12 @@ class MailingContent
*
* @param ModifierInterface[] $modifiers
*/
public function __construct(protected readonly iterable $modifiers, protected readonly RouterInterface $router, private readonly KernelInterface $kernel)
public function __construct(protected readonly iterable $modifiers, protected readonly RouterInterface $router, private readonly HttpKernelInterface $httpKernel, private readonly Router $ibexaRouter)
{
}

public function preFetchContent(Mailing $mailing): string
{
$client = new HttpKernelBrowser($this->kernel);
$url = $this->router->generate(
'_ibexamailing_ez_content_view',
[
Expand All @@ -45,9 +45,10 @@ public function preFetchContent(Mailing $mailing): string
],
UrlGeneratorInterface::ABSOLUTE_URL
);

$crawler = $client->request('/GET', $url);
$this->nativeContent[$mailing->getLocationId()] = "<!DOCTYPE html><html>{$crawler->html()}</html>";
$request = Request::create($url);
$request->attributes->set('siteaccess', $this->ibexaRouter->matchByName($mailing->getSiteAccess()));
$response = $this->httpKernel->handle($request);
$this->nativeContent[$mailing->getLocationId()] = $response->getContent();

return $this->nativeContent[$mailing->getLocationId()];
}
Expand Down
5 changes: 3 additions & 2 deletions bundle/Core/Utils/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,20 @@ private function setVersion(string $userAgentBrand, string $userAgent): string
'other',
];
$matches = null;
$version = null;
$pattern = '#(?<browser>'.implode('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
preg_match_all($pattern, $userAgent, $matches);

// see how many we have
if (\count($matches['browser']) !== 1) {
if (\count($matches['browser']) > 1) {
// we will have two since we are not using 'other' argument yet
// see if version is before or after the name
if (strripos($userAgent, 'Version') < strripos($userAgent, $userAgentBrand)) {
$version = $matches['version'][0];
} else {
$version = $matches['version'][1];
}
} else {
} elseif (!empty($matches['version'])) {
$version = $matches['version'][0];
}

Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/translations/ibexamailing+intl-icu.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mailing.mailing_tabs.confirm: Confirm
mailing.mailing_tabs.test_mailing: Test the Mailing
mailing.mailing_tabs.report_mail1: CampaignRepository defines
mailing.mailing_tabs.report_mail2: as report email
mailing.mailing_tabs.add_cc: 'Would you like to <strong>cc</strong> someone?'
mailing.mailing_tabs.add_cc: '<strong>cc</strong> someone'
mailing.mailing_tabs.email: email
mailing.mailing_tabs.send_test: Send a test
mailing.mailing_tabs.cancel: Cancel
Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/translations/ibexamailing+intl-icu.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mailing.mailing_tabs.confirm: Confirmer
mailing.mailing_tabs.test_mailing: Tester l'envoi
mailing.mailing_tabs.report_mail1: La campagne définit
mailing.mailing_tabs.report_mail2: comme courriel de signalement
mailing.mailing_tabs.add_cc: 'Désirez-vous ajouter une personne en <strong>cc</strong>?'
mailing.mailing_tabs.add_cc: 'Ajouter une personne en <strong>cc</strong>'
mailing.mailing_tabs.email: courriel
mailing.mailing_tabs.send_test: Envoyer un test
mailing.mailing_tabs.cancel: Annuler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% for broadcast in items %}
{% if broadcast.emailSentCount > 0 %}
<div class="ibexamailing-broadcast-charts-group p-2">
<div class="ibexamailing-broadcast-charts-group row p-2">
<h3>{{ "common.list.broadcast_graph.broadcasted_on"|trans }} {{ broadcast.started|format_datetime(ibexamailing.dateformat.date, ibexamailing.dateformat.date) }}</h3>
<hr/>
<div class="graph-broadcast full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<div class="input-group-text">@</div>
</div>
<input type="email" name="cc" class="form-control" id="ccEmailTest"
placeholder={{ "mailing.mailing_tabs.email"|trans }}/>
placeholder="{{ "mailing.mailing_tabs.email"|trans }}" required/>
</div>
</div>
<div class="modal-footer">
Expand Down

0 comments on commit 021b8b9

Please sign in to comment.