From 04e31d273d560aaadd4741f307c1092cd34a2f75 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 30 Jul 2020 22:40:37 +0000 Subject: [PATCH] [MAIL] Make mailserver a required service --- bin/configure | 5 ++++- src/Core/GNUsocial.php | 24 +++++++++++------------- src/Core/Mailer.php | 9 +++------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/bin/configure b/bin/configure index 6d0d6b45f6..26fc96699e 100755 --- a/bin/configure +++ b/bin/configure @@ -50,7 +50,9 @@ EOF fi -echo "${database_url}" > .env.local +echo "${database_url}" >> .env.local + +printf "Mailer dsn: " && read -r mailer_dsn mkdir -p ./docker/social @@ -65,4 +67,5 @@ SOCIAL_ADMIN_NICK="${admin_nick}" SOCIAL_ADMIN_PASSWORD="${admin_password}" SOCIAL_ADMIN_EMAIL="${email}" SOCIAL_SITE_PROFILE="${profile}" +MAILER_DSN="${mailer_dsn}" EOF diff --git a/src/Core/GNUsocial.php b/src/Core/GNUsocial.php index f4ea7a122f..d6b53b351d 100644 --- a/src/Core/GNUsocial.php +++ b/src/Core/GNUsocial.php @@ -47,9 +47,7 @@ use App\Core\DB\DefaultSettings; use App\Core\I18n\I18n; use App\Core\Queue\Queue; use App\Core\Router\Router; -use App\Util\Common; use Doctrine\ORM\EntityManagerInterface; -use Exception; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -58,6 +56,7 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Security as SSecurity; @@ -77,6 +76,8 @@ class GNUsocial implements EventSubscriberInterface protected EventDispatcherInterface $event_dispatcher; protected SessionInterface $session; protected SSecurity $security; + protected MailerInterface $mailer; + protected ModuleManager $module_manager; /** * Symfony dependency injection gives us access to these services @@ -89,7 +90,9 @@ class GNUsocial implements EventSubscriberInterface MessageBusInterface $mb, EventDispatcherInterface $ed, SessionInterface $sess, - SSecurity $sec) + SSecurity $sec, + MailerInterface $mail, + ModuleManager $mod) { $this->logger = $logger; $this->translator = $trans; @@ -100,6 +103,8 @@ class GNUsocial implements EventSubscriberInterface $this->event_dispatcher = $ed; $this->session = $sess; $this->security = $sec; + $this->mailer = $mail; + $this->module_manager = $mod; $this->initialize(); } @@ -119,20 +124,13 @@ class GNUsocial implements EventSubscriberInterface Form::setFactory($this->form_factory); Queue::setMessageBus($this->message_bus); Security::setHelper($this->security); + Mailer::setMailer($this->mailer); DefaultSettings::setDefaults(); - // TODO use configuration properly - try { - if (Common::config('site', 'use_email')) { - Mailer::setMailer($this->containen->get('mailer')); - } - } catch (Exception $e) { - // Table doesn't exist yet - } - Cache::setupCache(); - ModulesManager::loadModules(); + + $this->module_manager->loadModules(); } /** diff --git a/src/Core/Mailer.php b/src/Core/Mailer.php index 79f48c2a88..bc13c8bc24 100644 --- a/src/Core/Mailer.php +++ b/src/Core/Mailer.php @@ -32,21 +32,18 @@ namespace App\Core; -use App\Util\Common; use Symfony\Component\Mailer\MailerInterface; abstract class Mailer { - private MailerInterface $mailer; + private static MailerInterface $mailer; public static function setMailer($m) { - $this->mailer = $m; + self::$mailer = $m; } public static function __callStatic(string $method, array $args) { - if (Common::config('site', 'use_email')) { - return $this->{$method}(...$args); - } + return self::{$method}(...$args); } }