Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature to allow deleting of all of a user's given thanks/likes #198

Open
lairdshaw opened this issue Jul 25, 2018 · 9 comments
Open

Comments

@lairdshaw
Copy link
Collaborator

This feature was requested by floriaN here:

Is there a query or feature to wipe/remove all likes from a User? Like setting his likes to 0.

And further explained here:

I have members abusing the like system with creating multi accounts and liking their own post to reach a new usergroup or to bypass limitation. Perm banning them is not the solution here, I'd rather just delete all of their likes as a punishment.

floriaN has offered to pay me to develop this feature at a mutually-agreed price - the feature would then be available as usual as part of the freely-licensed public version of the plugin. This scenario has been OKed by Eldenroot so long as the feature is first discussed publicly as a GitHub issue - and this is it.

So, here's my suggestion as to how to implement this feature:

Add a new moderation permission which can be toggled on/off for any given usergroup via a checkbox, "Can delete users' thanks/likes?", at the bottom of the "Moderator CP" tab when editing a usergroup.

When viewing a member's profile, members of a usergroup with this option toggled on will be shown an additional link in the "Moderator Options" pane: "Delete thanks/likes given by this user".

When viewing the Mod CP, members of a usergroup with this option toggled on will be shown an additional link in the left navigation panel under "Users": "Delete Thanks/Likes By" (with the thumbs-up image as its icon).

Clicking on either of these links will lead to a page with a username field (pre-filled when arriving via a member profile). Filling in a valid username (autocomplete will as usual be enabled) and clicking "Delete" will delete all thanks/likes given by the user.

And that's it. Let me know what you think!

@Eldenroot
Copy link
Member

I agree, good approach! Feel free to work on it.

Is possible to send a PM to user automatically when his thanks/likes were deleted with reason?

@lairdshaw
Copy link
Collaborator Author

Yes, an automated PM would be possible - good idea, let's add it. Something else to add is logging the action to the moderator log.

@Eldenroot
Copy link
Member

Yes, logging is useful.

You can start with coding and during that there might be more ideas what to add or improve.

@lairdshaw
Copy link
Collaborator Author

An overdue update: floriaN and I couldn't agree on a price. I no longer plan to implement this feature - it's open to anybody else to do.

@Eldenroot
Copy link
Member

@SvePu - please check this branch, it is not correctly integrated (because we have to handle deletion thx/likes in a correct way which will not bug the recounting thx/likes)... anyway could be used somehow maybe?

https://github.com/Eldenroot/thankyoulikeold/commit/b05d5ae4efcd22de83827403d4b0b962ff558e9c

@SvePu
Copy link
Collaborator

SvePu commented Dec 28, 2022

I'll take a look

@Eldenroot
Copy link
Member

Thank you!

@SvePu
Copy link
Collaborator

SvePu commented Dec 28, 2022

@Eldenroot Why you don't use an adapted thankyoulike_delete_user() fuction??

function thankyoulike_delete_user()
{
global $db, $user;
$prefix = 'g33k_thankyoulike_';
// Only delete/update if the user had tyls
if($user['tyl_unumtyls'] != 0)
{
// Find all tyl data for this user
$query = $db->query("
SELECT tyl.*, p.tid
FROM ".TABLE_PREFIX.$prefix."thankyoulike tyl
LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=tyl.pid)
WHERE tyl.uid='".$user['uid']."'
");
$tlids = array();
$post_tyls = array();
$user_tyls = array();
while($tyl_user = $db->fetch_array($query))
{
$tlids[] = $tyl_user['tlid'];
// Count the tyl counts for each post to be subtracted
if($post_tyls[$tyl_user['pid']])
{
$post_tyls[$tyl_user['pid']]--;
}
else
{
$post_tyls[$tyl_user['pid']] = -1;
}
// Count tyls received by this user to be removed
if($user_tyls[$tyl_user['puid']])
{
$user_tyls[$tyl_user['puid']]--;
}
else
{
$user_tyls[$tyl_user['puid']] = -1;
}
}
// Remove tyl count from posts
if(is_array($post_tyls))
{
foreach($post_tyls as $pid => $subtract)
{
$db->write_query("UPDATE ".TABLE_PREFIX."posts SET tyl_pnumtyls=tyl_pnumtyls$subtract WHERE pid='$pid'");
}
}
// Remove tyl received count from users
if(is_array($user_tyls))
{
foreach($user_tyls as $puid => $subtract)
{
$db->write_query("UPDATE ".TABLE_PREFIX."users SET tyl_unumrcvtyls=tyl_unumrcvtyls$subtract WHERE uid='$puid'");
}
}
// Delete the tyls, update total
if($tlids)
{
$tlids_count = count($tlids);
$tlids = implode(',', $tlids);
$db->write_query("UPDATE ".TABLE_PREFIX.$prefix."stats SET value=value-$tlids_count WHERE title='total'");
$db->delete_query($prefix."thankyoulike", "tlid IN ($tlids)");
}
}
}

@Eldenroot
Copy link
Member

Do not ask me :D this was just a try... hidden in my private repo :) feel free to adjust it or whatever (or ignore it) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants