CTOlet / yii2-attachments

Yii2 extension for uploading and attaching the files to the models
66 stars 57 forks source link

Problem when using AR in console #63

Closed tsdogs closed 6 years ago

tsdogs commented 7 years ago

If I use the AR in console commands I always get

#0 /home/alex/public_html/cvn/gestione/vendor/yiisoft/yii2/di/ServiceLocator.php(75): yii\base\Component->__get('session')
#1 /home/alex/public_html/cvn/gestione/vendor/nemmo/yii2-attachments/src/Module.php(92): yii\di\ServiceLocator->__get('session')
#2 /home/alex/public_html/cvn/gestione/vendor/nemmo/yii2-attachments/src/behaviors/FileBehavior.php(45): nemmo\attachments\Module->getUserDirPath()
#3 [internal function]: nemmo\attachments\behaviors\FileBehavior->saveUploads(Object(yii\db\AfterSaveEvent))
#4 /home/alex/public_html/cvn/gestione/vendor/yiisoft/yii2/base/Component.php(545): call_user_func(Array, Object(yii\db\AfterSaveEvent))
#5 /home/alex/public_html/cvn/gestione/vendor/yiisoft/yii2/db/BaseActiveRecord.php(964): yii\base\Component->trigger('afterInsert', Object(yii\db\AfterSaveEvent))

no matter if I turn off the behaviour with detach or detach the events.

tsdogs commented 7 years ago

hmm, maybe this is because I have overridden the afterSave function, adding this to the behaviours() function of the AR solved the issue.

 if(is_a(Yii::$app,'yii\console\Application')) return [];