Beispiel #1
0
 public function delete($id)
 {
     $pdo = Connection::connect();
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $q = $pdo->prepare($this->deleteUserQuery);
     $q->execute(array($id));
     Connection::disconnect();
 }
 public function upsert()
 {
     $user = AuthController::auth();
     if ($this->isValid($_POST)) {
         $instanceRepo = new InstanceRepository();
         $pdo = Connection::connect();
         $pdo->beginTransaction();
         try {
             if ($_POST['id'] != "") {
                 $instance = $instanceRepo->get($_POST['id']);
                 $instance->name = $_POST['name'];
                 $instance->description = $_POST['description'];
                 $instanceRepo->update($instance);
                 $_SESSION['success'] = ['Successfully update an instance.'];
             } else {
                 $instance = new Instance();
                 $instance->id = $this->generateId();
                 $instance->password = $this->generatePassword();
                 $instance->userId = $user->id;
                 $instance->name = $_POST['name'];
                 $instance->description = $_POST['description'];
                 $instanceRepo->insert($instance);
                 $_SESSION['success'] = ['Successfully add an instance.'];
             }
             $pdo->commit();
         } catch (\Exception $e) {
             $pdo->rollBack();
             unset($_SESSION['success']);
         }
         header('Location: /');
     } else {
         if ($_POST['id'] != "") {
             header('Location: /instance/edit?id=' . $_POST['id']);
         } else {
             header('Location: /instance/edit');
         }
     }
 }