confide icon indicating copy to clipboard operation
confide copied to clipboard

Mailing Queue Insufficient data for unserializing

Open Austinb opened this issue 9 years ago • 9 comments

When I try to use mailing via queue with the latest 4.0 version I receive an error like the following "Insufficient data for unserializing...". This is due to objects being serialized that can not be unserialized when the queue is processed. In this case I found the issue to be in the ./src/Confide/EloquentPasswordService.php file in the sendEmail() function. The callback function is passing object versions of the User model and the Lang classes which can not be rebuilt upon the queue processing. Am I missing something or is this a bug? Basically I changed the code in the above file to the following:

    protected function sendEmail($user, $token)
    {
        $config = $this->app['config'];
        $lang   = $this->app['translator'];

        $user = (object) $user->toArray(); // Flatten to array then make it an object again
        $subject = $lang->get('confide::confide.email.password_reset.subject');

        $this->app['mailer']->queueOn(
            $config->get('confide::email_queue'),
            $config->get('confide::email_reset_password'),
            compact('user', 'token'),
            function ($message) use ($user, $token, $subject) {
                $message
                    ->to($user->email, $user->username)
                    ->subject($subject);
            }
        );
    }

This change allows emails to be sent again. If the above is wrong please provide the correct way to utilize the mailing via queue with confide. Thanks in advance.

Settings in configs: ./config/zizaco/confide/config.php

'email_queue' => 'default',

./config/queue.php

'default'     => 'sync', // Usually use iron.io for queue

Austinb avatar Dec 15 '14 20:12 Austinb

Also this same issue occurs in the generated UsersController.php file in the function store(). Adding the following line

$user = (object) $user->toArray();

after

if ($user->id)

changes the Eloquent model into a simple object.

Austinb avatar Dec 15 '14 21:12 Austinb

NB, this is improved in laravel 5 with queuable entities.

GrahamCampbell avatar Dec 15 '14 21:12 GrahamCampbell

I just created a pull request for this very issue for Laravel 4 users: https://github.com/Zizaco/confide/pull/502

hotmeteor avatar Jan 23 '15 15:01 hotmeteor

I'll check out the pull request

andrewelkins avatar Jan 26 '15 18:01 andrewelkins

@hotmeteor i tried your changes locally but it doesn't solve the problem

MoamenAbdelwahed avatar Jan 26 '15 19:01 MoamenAbdelwahed

@MoamenAbdelwahed What is your problem?

hotmeteor avatar Jan 26 '15 20:01 hotmeteor

@hotmeteor Getting "Insufficient data for unserializing" all the time with beanstalked

MoamenAbdelwahed avatar Jan 26 '15 20:01 MoamenAbdelwahed

@hotmeteor The issue with that pull request (#502) is you have to pull the Lang part out as well. The same issue as with the User as it cant rebuild the class so it dies out.

Note in my snippet I moved the $lang out and made a new variable $subject which holds the real subject to be sent.

Austinb avatar Jan 26 '15 20:01 Austinb

@Austinb Good call, thanks. I updated the pull with that bit.

hotmeteor avatar Jan 27 '15 18:01 hotmeteor