Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendMail: Send PDFs asynchronously #231

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
$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 @@
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
Loading