コード例 #1
0
 public function actionRollBack($id)
 {
     $model = $this->findModel($id);
     $table = (new $model->category())->tableName();
     $attributes = $model['data']['attributes'];
     $updated = 0;
     $inserted = 0;
     try {
         $query = new \yii\db\Query();
         $oldRow = $query->from($table)->andWhere(['id' => $attributes['id']])->one();
         if ($oldRow) {
             $updated = Yii::$app->db->createCommand()->update($table, $attributes, ['id' => $attributes['id']])->execute();
         }
         if (!$oldRow) {
             $inserted = Yii::$app->db->createCommand()->insert($table, $attributes)->execute();
         }
     } catch (\yii\db\Exception $exc) {
         Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-error'], 'body' => Yii::t('backend', 'Can\'t roll back. ') . $exc->getMessage()]);
     }
     if (empty($exc)) {
         Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('backend', 'Updated: {u}. Inserted: {i}.', ['u' => $updated, 'i' => $inserted])]);
     }
     TimelineEvent::log($model->category, 'afterRollBack', ['attributes' => $attributes, 'uid' => Yii::$app->user->identity->id]);
     $redirectUrlParams = ['index'];
     if (Yii::$app->request->get('TimelineEventSearch')) {
         $redirectUrlParams['TimelineEventSearch'] = Yii::$app->request->get('TimelineEventSearch');
     }
     $this->redirect($redirectUrlParams);
 }
コード例 #2
0
ファイル: User.php プロジェクト: efabrikov/qreachers
 /**
  * Creates user profile and application event
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     TimelineEvent::log('user', 'signup', ['publicIdentity' => $this->getPublicIdentity(), 'userId' => $this->getId(), 'created_at' => $this->created_at]);
     $profile = new UserProfile();
     $profile->locale = Yii::$app->language;
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     $this->trigger(self::EVENT_AFTER_SIGNUP);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_USER), $this->getId());
 }
コード例 #3
0
ファイル: ChangeLogBehavior.php プロジェクト: allhaze/renault
 public function afterUpdate()
 {
     TimelineEvent::log($this->owner->className(), 'afterUpdate', ['attributes' => $this->owner->getAttributes(), 'uid' => Yii::$app->user->identity->id]);
     return true;
 }