31 lines
1.1 KiB
PHP
31 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Box\Mod\Mailgateway;
|
|
|
|
use Pimple\Container;
|
|
|
|
class TemplateInstaller
|
|
{
|
|
public function __construct(private Container $di) {}
|
|
|
|
public function install(): void
|
|
{
|
|
$code = 'mailgateway_sender_mismatch';
|
|
$email = $this->di['mod_service']('email');
|
|
// Preserve existing custom content and enabled/disabled preference.
|
|
if ($email->getTemplateRepository()->findOneByActionCode($code) !== null) {
|
|
return;
|
|
}
|
|
$source = file_get_contents(__DIR__ . '/templates/email/' . $code . '.html.twig');
|
|
if (!is_string($source)
|
|
|| !preg_match('/{%\s*block subject\s*%}(.*?){%\s*endblock\s*%}/s', $source, $subject)
|
|
|| !preg_match('/{%\s*block content\s*%}(.*?){%\s*endblock\s*%}/s', $source, $content)) {
|
|
throw new \RuntimeException('Mail Gateway sender-mismatch template is missing or invalid');
|
|
}
|
|
// This existing custom action code does not use the mod_* discovery convention.
|
|
$email->templateCreate($code, trim($subject[1]), trim($content[1]), 1, 'mailgateway');
|
|
}
|
|
}
|