-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[5.7] Fix an issue when using Mail::queue to queue Mailables #27618
[5.7] Fix an issue when using Mail::queue to queue Mailables #27618
Conversation
A queue name and the queue manager where being used indistinctly so the call errored as it expected an \Illuminate\Contracts\Queue\Factory and not a string.
I was against renaming the |
Is it possible to come up with a test for these two cases? |
There's indeed a bug but I'm unsure this implementation is twtg. Can you at least provide a test like @mfn suggested which proves that the behavior was fixed? |
Sure, I'll look into it. I wasn't sure about it either, but since the view object is the one responsible to hand out on which queue it is supposed to be queued, this was the best way to do it that didn't involved major refactors. As far as I can tell this is equivalent to how I was used to queue mailables on specific queues:
And it shouldn't have affected the other way of setting the queue name directly in the mailable and having it implement the The thing I'm not happy about is that having the statement:
I wouldn't expect any side effects on the mailable (setting the queue name) and instead having the mailer do all the nuances, but I don't think is possible without changing the underlying code relating to queues or duplicating chunks of it on the mailer. |
On the way to the office I was thinking about this an wondered what if we match the This way we have consistency across the mail classes that handle queueing. So we would end with this: /**
* Queue a new e-mail message for sending.
*
* @param \Illuminate\Contracts\Mail\Mailable $view
* @param \Illuminate\Contracts\Queue\Factory|null $queue
* @return mixed
*
* @throws \InvalidArgumentException
*/
public function queue($view, Queue $queue = null)
{
if (! $view instanceof MailableContract) {
throw new InvalidArgumentException('Only mailables may be queued.');
}
return $view->queue(is_null($queue) ? $this->queue : $queue);
}
/**
* Queue a new e-mail message for sending on the given queue.
*
* @param string $queue
* @param \Illuminate\Contracts\Mail\Mailable $view
* @return mixed
*/
public function onQueue($queue, $view)
{
return $this->queue($view->onQueue($queue));
} And instead of calling I think this would be better and more consistent. What do you think? |
I think the solution you have here is fine. People really shouldn't even be calling Mail::later directly. Should be using |
I agree that using |
The issue was found on the
Illuminate\Mail\Mailer::queue
method. The given queue name and the queue manager where used indistinctly which caused the error when calling theIlluminate\Mail\Mailable::queue
method as it expected anIlluminate\Contracts\Queue\Factory
object.Fixes #27612