public function actionChangeNode($id) { $request = Yii::$app->getRequest(); $model = $this->findTopicModel($id); $model->scenario = Topic::SCENARIO_ADMIN_CHGNODE; $ext['oldNode'] = $model->node->toArray(); if ($model->load($request->post()) && $model->save(false)) { unset($model->node); $ext['newNode'] = $model->node->toArray(); (new History(['user_id' => Yii::$app->getUser()->id, 'action' => History::ACTION_EDIT_TOPIC, 'action_time' => $model->updated_at, 'target' => $model->id, 'ext' => json_encode($ext)]))->save(false); Node::updateAllCounters(['topic_count' => 1], ['id' => $ext['newNode']['id']]); Node::updateAllCounters(['topic_count' => -1], ['id' => $ext['oldNode']['id']]); $url = ['topic/view', 'id' => $id]; if (($ip = $request->get('ip', 1)) > 1) { $url['ip'] = $ip; } return $this->redirect($url); } return $this->render('changeNode', ['model' => $model]); }