public function actionRestore()
    {
        $post = Yii::$app->request->post();
        $query = new Query;
        $audit = $query
            ->from("audits.{$post['table']}")
            ->where('audit_id = :audit_id', ['audit_id' => $post['audit_id']])
            ->one();
        $this->setCurrentModel($post['table']);
        $criteria = [];
        /** @var \yii\db\ActiveRecord $model */
        $model = $this->_currentModel;
        foreach ($model->primaryKey() as $primaryKey) {
            $criteria[$primaryKey] = $audit[$primaryKey];
        }
        foreach ($this->module->tables[$post['table']]['updateSkip'] as $column) {
            if (isset($audit[$column])) {
                unset($audit[$column]);
            }
        }
        /** @var \yii\db\ActiveRecord $record */
        $record = $model->findOne($criteria);
        $record->setAttributes($audit, false);
        if ($record->save()) {
            Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been restored.'));
        } else {
            Yii::$app->session->setFlash('danger', Yii::t('app', 'Failed to restore record.'));
        }
        return $this->redirect(Yii::$app->request->referrer);
    }
public function actionRestore()
    {
        $post = Yii::$app->request->post();
        $query = new Query;
        $audit = $query
            ->from("audits.{$post['table']}")
            ->where('audit_id = :audit_id', ['audit_id' => $post['audit_id']])
            ->one();
        $this->setCurrentModel($post['table']);
        $criteria = [];
        /** @var \yii\db\ActiveRecord $model */
        $model = $this->_currentModel;
        foreach ($model->primaryKey() as $primaryKey) {
            $criteria[$primaryKey] = $audit[$primaryKey];
        }
        foreach ($this->module->tables[$post['table']]['updateSkip'] as $column) {
            if (isset($audit[$column])) {
                unset($audit[$column]);
            }
        }
        /** @var \yii\db\ActiveRecord $record */
        $record = $model->findOne($criteria);
        $record->setAttributes($audit, false);
        if ($record->save()) {
            Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been restored.'));
        } else {
            Yii::$app->session->setFlash('danger', Yii::t('app', 'Failed to restore record.'));
        }
        return $this->redirect(Yii::$app->request->referrer);
    }
public function actionRestore ( ) { $ post = Yii :: $ app -> request -> post ( ) ; $ query = new Query ; $ audit = $ query -> from ( "audits.{$post['table']}" ) -> where ( 'audit_id = :audit_id' , [ 'audit_id' => $ post [ 'audit_id' ] ] ) -> one ( ) ; $ this -> setCurrentModel ( $ post [ 'table' ] ) ; $ criteria = [ ] ; /** @var \yii\db\ActiveRecord $model */ $ model = $ this -> _currentModel ; foreach ( $ model -> primaryKey ( ) as $ primaryKey ) { $ criteria [ $ primaryKey ] = $ audit [ $ primaryKey ] ; } foreach ( $ this -> module -> tables [ $ post [ 'table' ] ] [ 'updateSkip' ] as $ column ) { if ( isset ( $ audit [ $ column ] ) ) { unset ( $ audit [ $ column ] ) ; } } /** @var \yii\db\ActiveRecord $record */ $ record = $ model -> findOne ( $ criteria ) ; $ record -> setAttributes ( $ audit , false ) ; if ( $ record -> save ( ) ) { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( 'app' , 'Record has been restored.' ) ) ; } else { Yii :: $ app -> session -> setFlash ( 'danger' , Yii :: t ( 'app' , 'Failed to restore record.' ) ) ; } return $ this -> redirect ( Yii :: $ app -> request -> referrer ) ; }
Restores record from audit

@return Response last visited page
Restores record from audit