Z
Z
zifmezin2021-08-25 20:35:01
Yii
zifmezin, 2021-08-25 20:35:01

Yii2 SluggableBehavior not generating slug when creating object from queue?

Hello.
For many days I have been struggling with the problem of generating a slug (CNC) when generating an article in queues (

There is an array, I go through it and send each element to the UpdatePlaceJob task

foreach ($array as $object) {
$object = $object->data->general;
Yii::$app->queue->push(new UpdatePlaceJob([
   'object' => $object,
]));


In this task, I create an article and save it.
public $place;

    public function execute($queue)
    {
        $object = $this->object;
        $place = Place::findOne(['title' => $object->name]);
        $place->status = Place::STATUS_UPDATED;
        $place->text = $object->description;
        $place->save();


The model itself has behavior for generating a slug
public function behaviors()
    {
        return [
            [
                'class' => SluggableBehavior::class,
                'attribute' => 'title',
                'slugAttribute' => 'slug',
                'ensureUnique' => true,
                'immutable' => true,
            ],


As a result, everything works, the article is created / updated, but the slug is not generated.
If all the same is done without sending the queue (directly in the controller), then everything works. Doesn't work from the queue. What with validation ($place->validate();), what without.

Who can suggest what? Or at least how to get an error, because I don’t know how to catch an error from queue systems (if there is one at all)
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-08-27
@zifmezin

This has nothing to do with the SluggableBehavior itself . The difference is obvious - the first is launched through the Web Controller, and the second through the queue from the Console Controller . This means that some php configurations in the console and on the web are different.
SluggableBehaviorheavily dependent on the PHP extension php*-intl . Most likely, you do not have it in the console, and therefore it does not work properly. Try to install it for php which works with queues.
Well, if this does not help, look at the logs not only of Yii, but also of php.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question