Skip to content

Commit

Permalink
SendMail: Send PDFs asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab authored and sukhwinder33445 committed May 7, 2024
1 parent 6fb47e3 commit 9cebc42
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions library/Reporting/Actions/SendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Module\Reporting\Actions;

use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport;
use Icinga\Module\Reporting\Hook\ActionHook;
use Icinga\Module\Reporting\Mail;
Expand All @@ -13,6 +14,7 @@
use ipl\Stdlib\Str;
use ipl\Validator\CallbackValidator;
use ipl\Validator\EmailAddressValidator;
use Throwable;

class SendMail extends ActionHook
{
Expand Down Expand Up @@ -40,11 +42,25 @@ public function execute(Report $report, array $config)
$mail->setSubject($config['subject']);
}

/** @var array<int, string> $recipients */
$recipients = preg_split('/[\s,]+/', $config['recipients']);
$recipients = array_filter($recipients);

switch ($config['type']) {
case 'pdf':
$mail->attachPdf(Pdfexport::first()->htmlToPdf($report->toPdf()), $name);
/** @var Pdfexport $exporter */
$exporter = Pdfexport::first();
$exporter->asyncHtmlToPdf($report->toPdf())->then(

Check failure on line 53 in library/Reporting/Actions/SendMail.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Call to an undefined method Icinga\Module\Pdfexport\ProvidedHook\Pdfexport::asyncHtmlToPdf().

Check failure on line 53 in library/Reporting/Actions/SendMail.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Call to an undefined method Icinga\Module\Pdfexport\ProvidedHook\Pdfexport::asyncHtmlToPdf().

Check failure on line 53 in library/Reporting/Actions/SendMail.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Call to an undefined method Icinga\Module\Pdfexport\ProvidedHook\Pdfexport::asyncHtmlToPdf().

Check failure on line 53 in library/Reporting/Actions/SendMail.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.0 on ubuntu-latest

Call to an undefined method Icinga\Module\Pdfexport\ProvidedHook\Pdfexport::asyncHtmlToPdf().

Check failure on line 53 in library/Reporting/Actions/SendMail.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.1 on ubuntu-latest

Call to an undefined method Icinga\Module\Pdfexport\ProvidedHook\Pdfexport::asyncHtmlToPdf().

Check failure on line 53 in library/Reporting/Actions/SendMail.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

Call to an undefined method Icinga\Module\Pdfexport\ProvidedHook\Pdfexport::asyncHtmlToPdf().

Check failure on line 53 in library/Reporting/Actions/SendMail.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

Call to an undefined method Icinga\Module\Pdfexport\ProvidedHook\Pdfexport::asyncHtmlToPdf().
function ($pdf) use ($mail, $name, $recipients) {
$mail->attachPdf($pdf, $name);
$mail->send(null, $recipients);
}
)->otherwise(function (Throwable $e) {
Logger::error($e);
Logger::debug($e->getTraceAsString());
});

break;
return;
case 'csv':
$mail->attachCsv($report->toCsv(), $name);

Expand All @@ -57,10 +73,7 @@ public function execute(Report $report, array $config)
throw new \InvalidArgumentException();
}

/** @var array<int, string> $recipients */
$recipients = preg_split('/[\s,]+/', $config['recipients']);

$mail->send(null, array_filter($recipients));
$mail->send(null, $recipients);
}

public function initConfigForm(Form $form, Report $report)
Expand Down

0 comments on commit 9cebc42

Please sign in to comment.