confide
confide copied to clipboard
Mailing Queue Insufficient data for unserializing
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
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.
NB, this is improved in laravel 5 with queuable entities.
I just created a pull request for this very issue for Laravel 4 users: https://github.com/Zizaco/confide/pull/502
I'll check out the pull request
@hotmeteor i tried your changes locally but it doesn't solve the problem
@MoamenAbdelwahed What is your problem?
@hotmeteor Getting "Insufficient data for unserializing" all the time with beanstalked
@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 Good call, thanks. I updated the pull with that bit.