File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JForum and the fly likes Can't delete user. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JForum
Bookmark "Can Watch "Can New topic
Author

Can't delete user.

Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
In administration interface, the user list has "delete selected" button at bottom, but I have no idea on how to select someone. No checkboxes, etc. I think it's a bug.
[originally posted on jforum.net by Daniil]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Anyway, how can I delete user from the MySQL console just in case?
[originally posted on jforum.net by Daniil]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424


of any other sql you want.

Please note that, if you remove an user that have posted any message, the forum will crash. So, in fact, if you delete an user, you must also delete his messages.
There is a flag named "deleted", that I'm not using ( but I will ), that, when set to "1", will "block" the user account, instead of deleting it.

Rafael
[originally posted on jforum.net by Rafael Steil]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Got it, thanks!

In fact, deleting users with no posts is a pretty common procedure for a forum admin, I think (a.k.a. user-list clean-up).
[originally posted on jforum.net by Daniil]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Yep, you're right.

Probably jforum will do some thing like "remove the user if he doesn't have any posts; lock his account if number of posts > 0"

Rafael
[originally posted on jforum.net by Rafael Steil]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Registered on JIRA as JF-6
[originally posted on jforum.net by smota]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Hi Rafael,
I made a JIRA request at http://www.jforum.net/jira/browse/JF-228

A physical cleanup tool should be provided for administrators.

1. Delete all users with no messages and has been not logined for a specific period(eg. 3 months, maybe setting in SystemGlobals or somewhere) automatically;
2. Delete selected users and remove all references (messages, private messages and so on) (usefull when change forum from testing phase to production phase to delete some test users.)

I need to physically delete the user from database for preparing for production purpose. How do you think about them?
[originally posted on jforum.net by andowson]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Ok. I'm not sure when I'll implement this feature, as I'm working now with karma, bookmarks and fileupload ( which is specially complex ).

Rafael
[originally posted on jforum.net by Rafael Steil]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
I don't see any button to delete a user.
I think the operation should delete all topics and messages posted by the user.

So, how to delete a user?

BTW, as admin I changed the user "login" name in profile, but the user name remains old in the "last registered memeber", and (unless I forgot password), this user cannot login after the change. I think this worked in 2.1.4. I used to "remember password" in order to change password to be able to login.
[originally posted on jforum.net by Evgeny]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
You don't delete users yet. All you can do is lock his account.

The "Last registered member" is just a cache issue - that user is hold on a different area, and only for showing in the first page.

If the username was correctly changed in the database, and you're sure the password is correct, it was supposed to login without any problems, because all authentication is done againts the database.

Rafael
[originally posted on jforum.net by Rafael Steil]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
I have added a method for delete definitively a User and his posts, topics, private Messages(From and To) and other data in the Db, i have tried to use all the methods that are just present in the code for deletion:

in UserAction:



// Delete Phisically
public void deletePhisically() {
String id = String.valueOf(this.request.getParameter("id"));
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
int userId = Integer.parseInt(id);

if (um.isDeleted(userId)) {
um.undelete(userId);
} else {
String sessionId = SessionFacade.isUserInSession(userId);

if (sessionId != null) {
SessionFacade.remove(sessionId);
}

um.deletePhisically(userId);
}

this.list();
}

IN GenericUserDAO:


public void deletePhisically(int userId) {

if (userId != 1 && userId != 2) {
PreparedStatement p = null;
ResultSet rs = null;
try {

/**
* TODO implementare la cancellazione completa utente.
* Le Tabelle da considerare sono:
* posts
* topics
* privmsgs
* votes
* banlist
* userGroups
* attachment
*
*/

// Posts to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.selectPostsByUserId"));
p.setInt(1, userId);
rs = p.executeQuery();
PostDAO postDAO = DataAccessDriver.getInstance().newPostDAO();
while (rs.next()) {
Post post = postDAO.selectById(rs.getInt("post_id"));
postDAO.delete(post);
}

// Topics to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.selectTopicsByUserId"));
p.setInt(1, userId);
rs = p.executeQuery();
TopicDAO topicDAO = DataAccessDriver.getInstance().newTopicDAO();
while (rs.next()) {
Topic topic = topicDAO.selectById(rs.getInt("topic_id"));
topicDAO.delete(topic);
}

// Private Messager to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.selectPrivmsgByUserId"));
p.setInt(1, userId);
rs = p.executeQuery();
PrivateMessageDAO dao = DataAccessDriver.getInstance().newPrivateMessageDAO();
PrivateMessage[] deletePmsList = new PrivateMessage[getRowCount(rs)];
int indexRs = 0;
while (rs.next()) {
if (0 != rs.getInt("privmsgs_id")) {
PrivateMessage pm = dao.selectById(new PrivateMessage(rs.getInt("privmsgs_id")));
deletePmsList[indexRs] = pm;
indexRs++;
}
}
if (deletePmsList.length == 0) {
dao.delete(deletePmsList, userId);
deletePmsList = null;
}

// Private Message(from) to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.selectPrivmsgToByUserId"));
p.setInt(1, userId);
rs = p.executeQuery();
PrivateMessageDAO daoTo = DataAccessDriver.getInstance().newPrivateMessageDAO();

while (rs.next()) {
if (0 != rs.getInt("privmsgs_id")) {
PrivateMessage pm = dao.selectById(new PrivateMessage(rs.getInt("privmsgs_id")));
deletePmsList[indexRs] = pm;
indexRs++;
}
}
if (deletePmsList.length == 0) {
dao.delete(deletePmsList, userId);
deletePmsList = null;
}

// BanList to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.selectBanlistByUserId"));
p.setInt(1, userId);
rs = p.executeQuery();
BanlistDAO banlistDAO = DataAccessDriver.getInstance().newBanlistDAO();
while (rs.next()) {
banlistDAO.delete(rs.getInt("banlist_id"));
}

// Attachments to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.deleteAttachmentByUserId"));
p.setInt(1, userId);
p.executeUpdate();

// User Groups to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.deleteUserGroupsByUserId"));
p.setInt(1, userId);
p.executeUpdate();

// Users to delete By User
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("UserModel.deleteUserByUserId"));
p.setInt(1, userId);
p.executeUpdate();


}
catch (SQLException e) {
throw new DatabaseException(e);
}
finally {
DbUtils.close(rs, p);
}
}
}



and i have added the queries that i need in the generic_queries.sql:

# ##########

UserModel.selectPostsByUserId = SELECT po.post_id, u.user_id \
FROM jforum_users u \
LEFT JOIN jforum_posts po ON po.user_id = u.user_id \
WHERE u.user_id = ? \
GROUP BY po.post_id,u.user_id;

UserModel.selectTopicsByUserId = SELECT top.topic_id, u.user_id \
FROM jforum_users u \
LEFT JOIN jforum_topics top ON top.user_id = u.user_id \
WHERE u.user_id = ? \
GROUP BY top.topic_id,u.user_id;

UserModel.selectPrivmsgByUserId = SELECT pvm.privmsgs_id, u.user_id \
FROM jforum_users u \
LEFT JOIN jforum_privmsgs pvm ON pvm.privmsgs_from_userid = u.user_id \
WHERE u.user_id = ? \
GROUP BY pvm.privmsgs_id,u.user_id;

UserModel.selectPrivmsgToByUserId = SELECT pvm.privmsgs_id, u.user_id \
FROM jforum_users u \
LEFT JOIN jforum_privmsgs pvm ON pvm.privmsgs_to_userid = u.user_id \
WHERE u.user_id = ? \
GROUP BY pvm.privmsgs_id,u.user_id;

UserModel.selectBanlistByUserId = SELECT ban.banlist_id, ban.user_id from jforum_banlist ban \
WHERE ban.user_id = ? ;

UserModel.deleteAttachmentByUserId = DELETE FROM jforum_attach att WHERE att.user_id = ?;

UserModel.deleteUserGroupsByUserId = DELETE FROM jforum_user_groups ug WHERE ug.user_id = ?;

UserModel.deleteUserByUserId = DELETE FROM jforum_users ug WHERE ug.user_id = ?;


... i hope you find this useful

Federico
[originally posted on jforum.net by fscanu]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't delete user.