Skip to content

Commit

Permalink
Merge branch 'feature/multipleSenders' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Jun 5, 2021
2 parents b4e1a77 + ef0ce5d commit f20bdbe
Show file tree
Hide file tree
Showing 68 changed files with 1,277 additions and 612 deletions.
5 changes: 3 additions & 2 deletions Classes/Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
/**
* Class ClearCommand
*/
class ClearCommand extends Command {

class ClearCommand extends Command
{
/**
* Configure the command by defining the name, options and arguments
*/
Expand All @@ -32,6 +32,7 @@ public function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var NewsletterRepository $newsletterRepository */
$newsletterRepository = ObjectUtility::getObjectManager()->get(NewsletterRepository::class);
$newsletterRepository->truncateAll();
$output->writeln('Truncated all luxletter tables!');
Expand Down
41 changes: 41 additions & 0 deletions Classes/Command/ClearQueueCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace In2code\Luxletter\Command;

use In2code\Luxletter\Domain\Repository\QueueRepository;
use In2code\Luxletter\Utility\ObjectUtility;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Extbase\Object\Exception;

/**
* Class ClearQueueCommand
*/
class ClearQueueCommand extends Command
{
/**
* Configure the command by defining the name, options and arguments
*/
public function configure()
{
$this->setDescription('Remove all queued newsletters');
}

/**
* Sends a bunch of emails from the queue
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var QueueRepository $queueRepository */
$queueRepository = ObjectUtility::getObjectManager()->get(QueueRepository::class);
$queueRepository->truncate();
$output->writeln('Truncated queue table!');
return 0;
}
}
18 changes: 13 additions & 5 deletions Classes/Command/QueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
use In2code\Luxletter\Exception\ArgumentMissingException;
use In2code\Luxletter\Exception\MisconfigurationException;
use In2code\Luxletter\Mail\ProgressQueue;
use In2code\Luxletter\Utility\ObjectUtility;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
Expand All @@ -27,14 +26,19 @@
*/
class QueueCommand extends Command
{

/**
* Configure the command by defining the name, options and arguments
*/
public function configure()
{
$this->setDescription('Send a bunch of emails from the queue.');
$this->addArgument('amount', InputArgument::OPTIONAL, 'How many mails should be send per wave?', 50);
$this->addArgument(
'newsletter',
InputArgument::OPTIONAL,
'Newsletter uid if only queued mails from a specific NL should be send',
0
);
}

/**
Expand All @@ -58,8 +62,12 @@ public function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$progressQueue = ObjectUtility::getObjectManager()->get(ProgressQueue::class, $output);
$progressed = $progressQueue->progress((int)$input->getArgument('amount'));
/** @var ProgressQueue $progressQueue */
$progressQueue = GeneralUtility::makeInstance(ProgressQueue::class, $output);
$progressed = $progressQueue->progress(
(int)$input->getArgument('amount'),
(int)$input->getArgument('newsletter')
);
if ($progressed > 0) {
$output->writeln('Successfully sent ' . $progressed . ' email(s) from the queue...');
} else {
Expand Down
14 changes: 9 additions & 5 deletions Classes/Controller/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
use In2code\Luxletter\Domain\Repository\UserRepository;
use In2code\Luxletter\Domain\Service\LogService;
use In2code\Luxletter\Domain\Service\ParseNewsletterUrlService;
use In2code\Luxletter\Domain\Service\SiteService;
use In2code\Luxletter\Exception\ArgumentMissingException;
use In2code\Luxletter\Exception\AuthenticationFailedException;
use In2code\Luxletter\Exception\MissingRelationException;
use In2code\Luxletter\Exception\UserValuesAreMissingException;
use In2code\Luxletter\Utility\BackendUserUtility;
use In2code\Luxletter\Utility\LocalizationUtility;
use In2code\Luxletter\Utility\ObjectUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
Expand Down Expand Up @@ -58,11 +59,14 @@ public function initializePreviewAction(): void
public function previewAction(string $origin): string
{
try {
$urlService = ObjectUtility::getObjectManager()->get(ParseNewsletterUrlService::class, $origin);
return $urlService->getParsedContent();
/** @var SiteService $siteService */
$siteService = GeneralUtility::makeInstance(SiteService::class);
/** @var ParseNewsletterUrlService $urlService */
$urlService = GeneralUtility::makeInstance(ParseNewsletterUrlService::class, $origin);
return $urlService->getParsedContent($siteService->getSite());
} catch (\Exception $exception) {
return 'Origin ' . htmlspecialchars($origin) . ' could not be converted into a valid url!<br>'
. 'Message: ' . $exception->getMessage();
return 'Error: Origin ' . htmlspecialchars($origin) . ' could not be converted into a valid url!<br>'
. 'Reason: ' . $exception->getMessage() . ' (' . $exception->getCode() . ')';
}
}

Expand Down
117 changes: 62 additions & 55 deletions Classes/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
use In2code\Luxletter\Domain\Factory\UserFactory;
use In2code\Luxletter\Domain\Model\Dto\Filter;
use In2code\Luxletter\Domain\Model\Newsletter;
use In2code\Luxletter\Domain\Model\Configuration;
use In2code\Luxletter\Domain\Model\User;
use In2code\Luxletter\Domain\Repository\LogRepository;
use In2code\Luxletter\Domain\Repository\NewsletterRepository;
use In2code\Luxletter\Domain\Repository\ConfigurationRepository;
use In2code\Luxletter\Domain\Repository\UserRepository;
use In2code\Luxletter\Domain\Service\ParseNewsletterService;
use In2code\Luxletter\Domain\Service\ParseNewsletterUrlService;
use In2code\Luxletter\Domain\Service\QueueService;
use In2code\Luxletter\Domain\Service\ReceiverAnalysisService;
use In2code\Luxletter\Domain\Service\SiteService;
use In2code\Luxletter\Exception\AuthenticationFailedException;
use In2code\Luxletter\Exception\InvalidUrlException;
use In2code\Luxletter\Exception\MisconfigurationException;
Expand Down Expand Up @@ -75,6 +78,37 @@ class NewsletterController extends ActionController
*/
protected $logRepository = null;

/**
* @var ConfigurationRepository
*/
protected $configurationRepository = null;

/**
* NewsletterController constructor.
* @param NewsletterRepository|null $newsletterRepository
* @param UserRepository|null $userRepository
* @param LogRepository|null $logRepository
* @param ConfigurationRepository|null $configurationRepository
* @throws Exception
*/
public function __construct(
NewsletterRepository $newsletterRepository = null,
UserRepository $userRepository = null,
LogRepository $logRepository = null,
ConfigurationRepository $configurationRepository = null
) {
$this->newsletterRepository = $newsletterRepository ?: ObjectUtility::getObjectManager()->get(
NewsletterRepository::class
);
$this->userRepository = $userRepository ?: ObjectUtility::getObjectManager()->get(
UserRepository::class
);
$this->logRepository = $logRepository ?: ObjectUtility::getObjectManager()->get(LogRepository::class);
$this->configurationRepository = $configurationRepository ?: ObjectUtility::getObjectManager()->get(
ConfigurationRepository::class
);
}

/**
* @return void
* @throws DBALException
Expand Down Expand Up @@ -104,15 +138,20 @@ public function dashboardAction(): void
*/
public function listAction(): void
{
$newsletters = $this->newsletterRepository->findAll();
$this->view->assign('newsletters', $newsletters);
$this->view->assignMultiple([
'newsletters' => $this->newsletterRepository->findAll(),
'configurations' => $this->configurationRepository->findAll()
]);
}

/**
* @return void
*/
public function newAction(): void
{
$this->view->assignMultiple([
'configurations' => $this->configurationRepository->findAll()
]);
}

/**
Expand Down Expand Up @@ -236,26 +275,20 @@ public function receiverAction(Filter $filter): void

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response Todo: Second parameter is removed in TYPO3 10
* @return ResponseInterface
* @throws DBALException
* @throws Exception
*/
public function wizardUserPreviewAjax(
ServerRequestInterface $request,
ResponseInterface $response = null
): ResponseInterface
public function wizardUserPreviewAjax(ServerRequestInterface $request): ResponseInterface
{
if ($response === null) {
$response = ObjectUtility::getObjectManager()->get(JsonResponse::class);
}
$userRepository = ObjectUtility::getObjectManager()->get(UserRepository::class);
$standaloneView = ObjectUtility::getObjectManager()->get(StandaloneView::class);
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($this->wizardUserPreviewFile));
$standaloneView->assignMultiple([
'userPreview' => $userRepository->getUsersFromGroup((int)$request->getQueryParams()['usergroup'], 3),
'userAmount' => $userRepository->getUserAmountFromGroup((int)$request->getQueryParams()['usergroup'])
]);
$response = ObjectUtility::getJsonResponse();
$response->getBody()->write(json_encode(
['html' => $standaloneView->render()]
));
Expand All @@ -264,7 +297,6 @@ public function wizardUserPreviewAjax(

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response Todo: Second parameter is removed in TYPO3 10
* @return ResponseInterface
* @throws AuthenticationFailedException
* @throws Exception
Expand All @@ -277,21 +309,23 @@ public function wizardUserPreviewAjax(
* @throws MisconfigurationException
* @throws TransportExceptionInterface
*/
public function testMailAjax(
ServerRequestInterface $request,
ResponseInterface $response = null
): ResponseInterface {
public function testMailAjax(ServerRequestInterface $request): ResponseInterface
{
if (BackendUserUtility::isBackendUserAuthenticated() === false) {
throw new AuthenticationFailedException('You are not authenticated to send mails', 1560872725);
}
if ($response === null) {
$response = ObjectUtility::getObjectManager()->get(JsonResponse::class);
}
/** @var ParseNewsletterUrlService $parseUrlService */
$parseUrlService = ObjectUtility::getObjectManager()->get(
ParseNewsletterUrlService::class,
$request->getQueryParams()['origin']
);
/** @var ParseNewsletterService $parseService */
$parseService = ObjectUtility::getObjectManager()->get(ParseNewsletterService::class);
/** @var ConfigurationRepository $configurationRepository */
$configurationRepository = ObjectUtility::getObjectManager()->get(ConfigurationRepository::class);
/** @var Configuration $configuration */
$configuration = $configurationRepository->findByUid($request->getQueryParams()['configuration']);
/** @var UserFactory $userFactory */
$userFactory = ObjectUtility::getObjectManager()->get(UserFactory::class);
$user = $userFactory->getDummyUser();
$mailService = ObjectUtility::getObjectManager()->get(
Expand All @@ -300,26 +334,22 @@ public function testMailAjax(
$request->getQueryParams()['subject'],
['user' => $user]
),
$parseUrlService->getParsedContent()
$parseUrlService->getParsedContent($configuration->getSiteConfiguration()),
$configuration
);
$status = $mailService->sendNewsletter([$request->getQueryParams()['email'] => $user->getReadableName()]);
$response = ObjectUtility::getJsonResponse();
$response->getBody()->write(json_encode(['status' => $status]));
return $response;
}

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response Todo: Second parameter is removed in TYPO3 10
* @return ResponseInterface
* @throws Exception
*/
public function receiverDetailAjax(
ServerRequestInterface $request,
ResponseInterface $response = null
): ResponseInterface {
if ($response === null) {
$response = ObjectUtility::getObjectManager()->get(JsonResponse::class);
}
public function receiverDetailAjax(ServerRequestInterface $request): ResponseInterface
{
$userRepository = ObjectUtility::getObjectManager()->get(UserRepository::class);
$visitorRepository = ObjectUtility::getObjectManager()->get(VisitorRepository::class);
$logRepository = ObjectUtility::getObjectManager()->get(LogRepository::class);
Expand All @@ -332,6 +362,7 @@ public function receiverDetailAjax(
'visitor' => $visitorRepository->findOneByFrontenduser($user),
'logs' => $logRepository->findByUser($user)
]);
$response = ObjectUtility::getJsonResponse();
$response->getBody()->write(json_encode(
['html' => $standaloneView->render()]
));
Expand Down Expand Up @@ -370,36 +401,12 @@ protected function setDatetimeObjectInNewsletterRequest(): void
protected function parseNewsletterToBodytext(): void
{
$newsletter = (array)$this->request->getArgument('newsletter');
/** @var ParseNewsletterUrlService $parseService */
$parseService = ObjectUtility::getObjectManager()->get(ParseNewsletterUrlService::class, $newsletter['origin']);
$parseService->setParseVariables(false);
$newsletter['bodytext'] = $parseService->getParsedContent();
/** @var Configuration $configuration */
$configuration = $this->configurationRepository->findByUid((int)$newsletter['configuration']);
$newsletter['bodytext'] = $parseService->getParsedContent($configuration->getSiteConfiguration());
$this->request->setArgument('newsletter', $newsletter);
}

/**
* @param NewsletterRepository $newsletterRepository
* @return void
*/
public function injectNewsletterRepository(NewsletterRepository $newsletterRepository): void
{
$this->newsletterRepository = $newsletterRepository;
}

/**
* @param UserRepository $userRepository
* @return void
*/
public function injectUserRepository(UserRepository $userRepository): void
{
$this->userRepository = $userRepository;
}

/**
* @param LogRepository $logRepository
* @return void
*/
public function injectLogRepository(LogRepository $logRepository): void
{
$this->logRepository = $logRepository;
}
}
Loading

0 comments on commit f20bdbe

Please sign in to comment.