Example #1
0
 /**
  * Delete the user from the system
  *
  * User data is never 'hard deleted' from the database. Instead the 'is_active' flag is set to 1
  *
  */
 public static function delete($user_id, $true_delete = FALSE)
 {
     Logger::log("Enter: function User::delete");
     // check whether user is already deleted
     if ($true_delete) {
         $sql = 'SELECT * from {users} WHERE user_id=?';
         $data = array($user_id);
     } else {
         $sql = 'SELECT * from {users} WHERE user_id=? AND is_active = ?';
         $data = array($user_id, DELETED);
     }
     $res = Dal::query($sql, $data);
     if ($res->numRows() > 0 && !$true_delete) {
         Logger::log("Throwing exception USER_ALREADY_DELETED | message: Can not delete a deleted user");
         throw new PAException(USER_ALREADY_DELETED, "Can not delete a deleted user.");
     } else {
         if ($true_delete) {
             $sql = 'DELETE FROM {users} WHERE user_id = ?';
             $sql1 = 'DELETE FROM {user_profile_data} WHERE user_id = ?';
             $data = array($user_id);
             $res = Dal::query($sql, $data);
             $res = Dal::query($sql1, $data);
         } else {
             $sql = 'UPDATE {users} SET login_name = CONCAT(?, login_name), email = CONCAT(?, email), is_active = ? WHERE user_id = ?';
             $data = array(MARK_DELETED_USER . $user_id . MARK_DELETED_USER, MARK_DELETED_USER . $user_id . MARK_DELETED_USER, DELETED, $user_id);
             //updated login_name will be of the kind #17#gurpreet.Here 17 is the user_id, gurpreet is login_name and
             # is serving as delimiter.
             $res = Dal::query($sql, $data);
         }
     }
     // make sure there aren't any lingering entries in networks_users or groups_users
     Network::leave_all_networks($user_id);
     Group::leave_all_groups($user_id);
     Logger::log("Exit: function User::delete");
 }