/**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userTokens first to handle foreign key constraint
     $user = $this->findModel($id);
     $profile = $user->profile;
     UserToken::deleteAll(['user_id' => $user->id]);
     UserAuth::deleteAll(['user_id' => $user->id]);
     $profile->delete();
     $user->delete();
     return $this->redirect(['index']);
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function upManual()
 {
     // delete neo user that the migration automatically adds
     UserKey::deleteAll(['user_id' => 1]);
     UserAuth::deleteAll(['user_id' => 1]);
     Profile::deleteAll(['user_id' => 1]);
     User::deleteAll(['id' => 1]);
 }
 /**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if ((Yii::$app->user->can("delete-user") || Yii::$app->user->can("user")) && $id != 1) {
         //Guarda a mensagem
         $mensagem = "";
         $transaction = \Yii::$app->db->beginTransaction();
         try {
             // delete profile and userTokens first to handle foreign key constraint
             $user = $this->findModel($id);
             $profile = $user->profile;
             UserToken::deleteAll(['user_id' => $user->id]);
             UserAuth::deleteAll(['user_id' => $user->id]);
             $profile->delete();
             if ($user->delete()) {
                 $transaction->commit();
             }
         } catch (\Exception $exception) {
             $transaction->rollBack();
             $mensagem = "Ocorreu uma falha inesperada ao tentar salvar ";
         }
         /** @var \amnah\yii2\user\models\search\UserSearch $searchModel */
         $searchModel = $this->module->model("UserSearch");
         $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());
         return $this->render('index', compact('searchModel', 'dataProvider'));
     } else {
         throw new ForbiddenHttpException("Acesso negado!");
     }
 }
 /**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userkeys first to handle foreign key constraint
     $user = $this->findModel($id);
     $profile = $user->profile;
     $userabonnement = $user->abonnement;
     $company = Yii::$app->getModule("user")->model("Company");
     $company = $company::findOne(['user_id' => $id]);
     $tariefDag = Yii::$app->getModule("user")->model("UserTarievenDag");
     $tariefDag = $tariefDag::findOne(['user_id' => $id]);
     $tariefNacht = Yii::$app->getModule("user")->model("UserTarievenNacht");
     $tariefNacht = $tariefNacht::findOne(['user_id' => $id]);
     $tariefWeekend = Yii::$app->getModule("user")->model("UserTarievenWeekend");
     $tariefWeekend = $tariefWeekend::findOne(['user_id' => $id]);
     $reistarief = Yii::$app->getModule("user")->model("UserReistarief");
     $reistarief = $reistarief::findOne(['user_id' => $id]);
     $invoice = Yii::$app->getModule("user")->model("UserInvoice");
     $invoice = $invoice::findOne(['user_id' => $id]);
     $activedays = Yii::$app->getModule("user")->model("UserActivedays");
     $activedays = $activedays::findOne(['user_id' => $id]);
     UserKey::deleteAll(['user_id' => $user->id]);
     UserAuth::deleteAll(['user_id' => $user->id]);
     if (isset($profile)) {
         $profile->delete();
     }
     if (isset($userabonnement)) {
         $userabonnement->delete();
     }
     if (isset($tariefDag)) {
         $tariefDag->delete();
     }
     if (isset($tariefNacht)) {
         $tariefNacht->delete();
     }
     if (isset($tariefWeekend)) {
         $tariefWeekend->delete();
     }
     if (isset($reistarief)) {
         $reistarief->delete();
     }
     $this->deleteZoHoContact($user);
     if (isset($invoice)) {
         $invoice->delete();
     }
     if (isset($activedays)) {
         $activedays->delete();
     }
     $this->deleteDependentUsers($user);
     $user->delete();
     return $this->redirect(['index']);
 }