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

[5.3] Mailable queue class not found #15065

Closed
JValck opened this issue Aug 26, 2016 · 15 comments
Closed

[5.3] Mailable queue class not found #15065

JValck opened this issue Aug 26, 2016 · 15 comments

Comments

@JValck
Copy link

JValck commented Aug 26, 2016

I just upgraded from laravel 5.2 to laravel 5.3
Currently I have troubles with the Mailables.

I always receive the ReflectionException Class not found. The strange thing is that, when I try sending the mail directly (without queuing), no problems occur.

I reviewed the jobs table in my database, as I am using the database queuing driver. But that doesn't seems to be the issue.

Here is the full stacktrace:

in Container.php line 734
at ReflectionClass->__construct('') in Container.php line 734
at Container->build('', array()) in Container.php line 629
at Container->make('', array()) in Application.php line 699
at Application->make('') in Job.php line 83
at Job->resolve('') in Job.php line 149
at Job->failed(object(ReflectionException)) in SyncQueue.php line 168
at SyncQueue->handleFailedJob(object(SyncJob), object(ReflectionException)) in SyncQueue.php line 65
at SyncQueue->handleSyncException(object(SyncJob), object(ReflectionException)) in SyncQueue.php line 46
at SyncQueue->push(object(SendQueuedMailable)) in Mailable.php line 138
at Mailable->queue(object(QueueManager)) in Mailer.php line 211
at Mailer->queue(object(OrderReceived)) in MailableMailer.php line 127
at MailableMailer->queue(object(OrderReceived)) in VisitorController.php line 302
at VisitorController->_flushToDatabase(array('firstName' => 'Jules', 'lastName' => 'test', 'email' => 'demo@gmail.com', 'subscribe' => 'true', 'printTicketsByOrganisation' => 'true', 'tickets' => array(array('priceId' => '5947ed599e6a4e19bba0d9b54cb8a471', 'price' => '15.00', 'category' => 'Standaardprijs', 'seat' => '267', 'amount' => '1'), array('priceId' => '49f91249bff343f09cf1a90b9dd5cc1d', 'price' => '5-5.00', 'category' => 'Kinderen (GRATIS)', 'seat' => '266', 'amount' => '1'))), object(Request)) in VisitorController.php line 261
at VisitorController->ajaxPersist(object(Request))
at call_user_func_array(array(object(VisitorController), 'ajaxPersist'), array(object(Request))) in Controller.php line 52
at Controller->callAction('ajaxPersist', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(VisitorController), 'ajaxPersist') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TicketsAvailable.php line 25
at TicketsAvailable->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TicketsOpen.php line 29
at TicketsOpen->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 263
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('/home/jules/sites/tickets/public/index.php') in server.php line 21

My mailable class:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

use App\Event;
use App\Visitor;
use App\Organisation;

class OrderReceived extends Mailable
{
    use Queueable, SerializesModels;

    private $visitor;
    private $event;
    private $organisation;
    private $bankingCode;

    /**
     * Create a new message instance.
     * @param App\Visitor $visitor The visitor who bought the tickets
     * @param App\Event $event The event where the visitor bought tickets from
     * @param App\Organisation $organisation The organisation that hosts the event
     * @param string $bankingCode The formatted banking code the user should use for payement
     * @return void
     */
    public function __construct(Visitor $visitor, Event $event, Organisation $organisation, $bankingCode)
    {
        $this->visitor = $visitor;
        $this->event = $event;
        $this->organisation = $organisation;
        $this->bankingCode;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.visitor.payementRequestEmail')
            ->subject(trans('messages.emailPayementRequest'))
            ->with([
            'langCode' => \App::getLocale(),
            'eventName' => $this->event->name,
            'organisationName' => $this->organisation->name,
            'name' => $this->visitor->firstName.' '.$this->visitor->lastName,
            'bankAccount' => chunk_split($this->organisation->bankAccount,4,' '),//format to ISO 13616
            'bankingCode' => $this->bankingCode,      
            'url' => $this->organisation->url,
            'color' => $this->organisation->colorAsHex,
            'ticketAmount' => $this->visitor->seats()->count(),
            'totalPrice' => $this->visitor->calculateTotalPrice(),
            'email' => $this->organisation->email,
            'userEmail' => $this->visitor->email,
            'printedByOrganisation' => $this->visitor->printTicketsByOrganisation,
        ]);
    }
}

And finally, the call to send the e-mail:
Mail::to($visitor->email)->queue(new OrderReceived($visitor, $event, $event->organisation()->first(), $humanBankingCode));

The issue seems to be related to the queue method, as the send method does not throw the exception.

@themsaid
Copy link
Member

Unable to regenerate the issue on a fresh laravel 5.3 installation, however you seem to be using the sync queue driver rather than the database driver though.

@GrahamCampbell
Copy link
Member

Please make sure you restart the queue worker after upgrading.

@JValck
Copy link
Author

JValck commented Aug 27, 2016

@themsaid I just changed my .env file to use the database driver. This doesn't seem to solve the issue. So I started narrowing down the issue. I looked in my jobs table and saw that the payload of the job equals 0.

@themsaid
Copy link
Member

I suspect something in your Mail object is causing json_encode to fail, when it fails it'll return false which will be saved in the DB as 0.

@JValck
Copy link
Author

JValck commented Aug 28, 2016

@themsaid The json_encode method indeed failed, as I'm using a binary id in my models. I just changed my models, now the json_encode doesn't fail.
Unfortunately the payload in my db table is still 0. I think this issue seems to be related to #12194

@themsaid
Copy link
Member

If the payload is still zero it means json_encode is still failing, not sure it's related to that issue or not though. You'll need to debug more until you find why json_encode fails

@JValck
Copy link
Author

JValck commented Aug 28, 2016

The strange thing is, when I call $model->toJson() it doesn't throw any error.

@themsaid
Copy link
Member

You need debug at this line: https://github.com/laravel/framework/blob/5.3/src/Illuminate/Queue/Queue.php#L78

@silasrm
Copy link

silasrm commented May 14, 2017

What is a solution @JValck ?

@JValck
Copy link
Author

JValck commented May 15, 2017 via email

@silasrm
Copy link

silasrm commented May 15, 2017

Hi @JValck ,

I'm using 5.4 and my problem was because my models using UUID in binary.
I change my toArray() because my model using default (Eloquen\Model) toArray() instead of from my traits (I'm using this package alsofronie/eloquent-uuid):

    public function toArray()
    {
        $parentArray = parent::toArray();
        return $this->deepArray($parentArray);
    }

@JValck
Copy link
Author

JValck commented May 17, 2017 via email

@silasrm
Copy link

silasrm commented May 17, 2017

I'm add this method to my User model, its using UUID traits and this method is the same of the trait (https://github.com/alsofronie/eloquent-uuid/blob/master/src/UuidBinaryModelTrait.php#L93-L97):

public function toArray()
    {
        $parentArray = parent::toArray();
        return $this->deepArray($parentArray);
    }

@JValck
Copy link
Author

JValck commented May 17, 2017

I have the same in my models. Currently I've a problem with encoding them to add them to the queue. I noticed that the toArray()-method is never called.

What is the error that you received? Maybe I'm encountering another issue than you.

@silasrm
Copy link

silasrm commented May 17, 2017

In my case the serialization process cause error.
I'm add implementation of \Serializable in my user model:

    public function serialize()
    {
        return [
            'id' => $this->id_string,
            'name' => $this->name,
            'email' => $this->email,
            'password' => $this->password,
            'role' => $this->role,
        ];
    }

    public function unserialize($data)
    {
        list(
            $this->id_string,
            $this->name,
            $this->email,
            $this->password,
            $this->role
        ) = $this->unserialize($data);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants