Skip to content

Commit

Permalink
chore: re-use the existing information email job
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Sep 29, 2023
1 parent 412a207 commit c4901f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
32 changes: 13 additions & 19 deletions framework/core/src/Api/Controller/SendTestMailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

use Flarum\Http\RequestUtil;
use Flarum\Locale\TranslatorInterface;
use Flarum\Mail\Job\SendInformationalEmailJob;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message;
use Illuminate\Contracts\Queue\Factory;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -24,7 +25,8 @@ class SendTestMailController implements RequestHandlerInterface
public function __construct(
protected Mailer $mailer,
protected TranslatorInterface $translator,
protected SettingsRepositoryInterface $settings
protected SettingsRepositoryInterface $settings,
protected Factory $queue
) {
}

Expand All @@ -33,23 +35,15 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$actor = RequestUtil::getActor($request);
$actor->assertAdmin();

$infoContent = $this->translator->trans('core.email.send_test.body');

$title = $this->translator->trans('core.email.send_test.subject');
$forumTitle = $this->settings->get('forum_title');
$userEmail = $actor->email;
$username = $actor->display_name;

$this->mailer->send(
[
'text' => 'flarum.forum::email.plain.information.base',
'html' => 'flarum.forum::email.html.information.base'
],
compact('infoContent', 'userEmail', 'forumTitle', 'title', 'username'),
function (Message $message) use ($actor) {
$message->to($actor->email);
$message->subject($this->translator->trans('core.email.send_test.subject'));
}
$this->queue->connection('sync')->push(
new SendInformationalEmailJob(
email: $actor->email,
displayName: $actor->display_name,
subject: $this->translator->trans('core.email.send_test.subject'),
body: $this->translator->trans('core.email.send_test.body'),
forumTitle: $this->settings->get('forum_title'),
bodyTitle: $this->translator->trans('core.email.send_test.subject')
)
);

return new EmptyResponse();
Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Queue/QueueFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class QueueFactory implements Factory
/**
* The cached queue instance.
*/
private ?Queue $queue;
private ?Queue $queue = null;

/**
* Expects a callback that will be called to instantiate the queue adapter,
Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/User/Job/RequestPasswordResetJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function handle(

$queue->push(new SendInformationalEmailJob(
email: $user->email,
displayName: Arr::get($data, 'username'),
subject: $subject,
body: $body,
forumTitle: Arr::get($data, 'forum'),
displayName: Arr::get($data, 'username'),
bodyTitle: $subject
));
}
Expand Down

0 comments on commit c4901f7

Please sign in to comment.