ROAResearch /
yii2-roa
| 1 | <?php |
||
| 2 | |||
| 3 | namespace roaresearch\yii2\roa\actions; |
||
| 4 | |||
| 5 | use Yii; |
||
| 6 | use yii\{base\Model, db\ActiveRecordInterface, web\ServerErrorHttpException}; |
||
| 7 | |||
| 8 | class ProfileUpdate extends \yii\rest\Action |
||
| 9 | { |
||
| 10 | use LoadFileTrait; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var string the scenario to be assigned to the model before it is validated and updated. |
||
| 14 | */ |
||
| 15 | public string $scenario = Model::SCENARIO_DEFAULT; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string[] that defines which columns will be recibe files |
||
| 19 | */ |
||
| 20 | public array $fileAttributes = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @inheritdoc |
||
| 24 | */ |
||
| 25 | 1 | public function init() |
|
| 26 | { |
||
| 27 | 1 | } |
|
| 28 | |||
| 29 | /** |
||
| 30 | * Updates the information of the logged user. |
||
| 31 | * |
||
| 32 | * @return ActiveRecordInterface |
||
| 33 | * @throws ServerErrorHttpException if there is any error when updating the model |
||
| 34 | */ |
||
| 35 | 1 | public function run(): ActiveRecordInterface |
|
| 36 | { |
||
| 37 | /* @var $model ActiveRecordInterface */ |
||
| 38 | 1 | $model = Yii::$app->user->identity; |
|
| 39 | 1 | $model->scenario = $this->scenario; |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 40 | 1 | $model->load( |
|
| 41 | 1 | Yii::$app->getRequest()->getBodyParams() + $this->parseFileAttributes(), |
|
| 42 | '' |
||
| 43 | ); |
||
| 44 | 1 | if ($model->save() === false && !$model->hasErrors()) { |
|
| 45 | throw new ServerErrorHttpException( |
||
| 46 | 'Failed to update the object for unknown reason.' |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | 1 | return $model; |
|
| 51 | } |
||
| 52 | } |
||
| 53 |