public function beforeSave()
{
/** @var BaseActiveRecord $model */
$model = $this->owner;
if (in_array($model->scenario, $this->scenarios)) {
if ($this->_file instanceof UploadedFile) {
if (!$model->getIsNewRecord() && $model->isAttributeChanged($this->attribute)) {
if ($this->unlinkOnSave === true) {
$this->delete($this->attribute, true);
}
}
$model->setAttribute($this->attribute, $this->_file->name);
} else {
// Protect attribute
unset($model->{$this->attribute});
}
} else {
if (!$model->getIsNewRecord() && $model->isAttributeChanged($this->attribute)) {
if ($this->unlinkOnSave === true) {
$this->delete($this->attribute, true);
}
}
}
}