Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 15 Dec 2015, 21:36
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
Infraction Hook

Hello,

It's me again - I was wondering if anyone could tell me which hook to latch my plugin onto if I wanted to modify a column within the users table.

I have tried the hooks 'infractiondata_postsave, infractiondata_presave, and memberinfraction_complete".

Either I have the wrong hook, or something in my code is wrong (which is probably the case)


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #2  
Old 15 Dec 2015, 23:26
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Real name: Mark
Okay, the first thing is, in a plugin you don't want to include the PHP tags. If your code is in an external file called by a plugin, then you do need the tags.

The hook location "infractiondata_postsave" is a good one (assuming you want this code to execute after the infraction is given), and you'll need to make the $userinfo array global to access it. This array will contain information regarding the user receiving the infraction.

You first query looks like it needs some tweaking, but please let me know exactly what you want to accomplish with this code, and I will try to point you in the right direction.
__________________
Former vBulletin.org Staff Member



Support for my products (as well as updates/new product publishing) has been moved to MHB - vBulletin Products and TAZ - Add-ons
Reply With Quote
  #3  
Old 15 Dec 2015, 23:58
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
Originally Posted by MarkFL View Post
Okay, the first thing is, in a plugin you don't want to include the PHP tags. If your code is in an external file called by a plugin, then you do need the tags.

The hook location "infractiondata_postsave" is a good one (assuming you want this code to execute after the infraction is given), and you'll need to make the $userinfo array global to access it. This array will contain information regarding the user receiving the infraction.

You first query looks like it needs some tweaking, but please let me know exactly what you want to accomplish with this code, and I will try to point you in the right direction.
I want to deduct reputation points from the user that is receiving the infraction.

The base amount is 150 points, but each active infraction point (ipoints in users table as far as I know) will apply a 2.5x multiplier. For example, someone with 4 infraction points will receive 1500 points deduction from their reputation column.

I hope that makes sense.
Reply With Quote
  #4  
Old 16 Dec 2015, 02:41
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Real name: Mark
Originally Posted by Chris.08i View Post
I want to deduct reputation points from the user that is receiving the infraction.

The base amount is 150 points, but each active infraction point (ipoints in users table as far as I know) will apply a 2.5x multiplier. For example, someone with 4 infraction points will receive 1500 points deduction from their reputation column.

I hope that makes sense.
Yes, makes perfect sense. What we can do is get this done with just one query. While this code (hopefully) won't be called often, it's a good idea to get in the practice of minimizing the number of queries for any operation.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
Former vBulletin.org Staff Member



Support for my products (as well as updates/new product publishing) has been moved to MHB - vBulletin Products and TAZ - Add-ons

Last edited by MarkFL; 16 Dec 2015 at 03:01.
Reply With Quote
  #5  
Old 16 Dec 2015, 06:13
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
Originally Posted by MarkFL View Post
Yes, makes perfect sense. What we can do is get this done with just one query. While this code (hopefully) won't be called often, it's a good idea to get in the practice of minimizing the number of queries for any operation.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

What if ipoints = 0?

I still want to deduct 150 from their reputation.
Reply With Quote
  #6  
Old 16 Dec 2015, 06:49
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Real name: Mark
Originally Posted by Chris.08i View Post
What if ipoints = 0?

I still want to deduct 150 from their reputation.
Your original code indicated that a deduction only occurs when ipoints > 0. But, if you want 150 rep deducted when ipoints = 0, and otherwise 375 * ipoints rep deducted then our code would be (since we don't have a nice linear relationship):


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
Former vBulletin.org Staff Member



Support for my products (as well as updates/new product publishing) has been moved to MHB - vBulletin Products and TAZ - Add-ons
Reply With Quote
  #7  
Old 16 Dec 2015, 09:38
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
Originally Posted by MarkFL View Post
Your original code indicated that a deduction only occurs when ipoints > 0. But, if you want 150 rep deducted when ipoints = 0, and otherwise 375 * ipoints rep deducted then our code would be (since we don't have a nice linear relationship):


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
Well that sums it up nicely!

I was going to use if statements to create the effect I needed, turns out I don't need to!

Thanks so much for your help Mark, definitely learned a lot these couple days.

Edit: I just tried it - I'm getting a Server 500 error when I try infract someone. Any ideas?

Edit #2: So I globalised $vbulletin as well and it started running the code properly. However it isn't properly deducting from the table.

Edit #3: I got it to deduct!

It turns out we were missing an 'END' to the case which cause an MySQL syntax error.

However it now seems like it's going through both cases and deducting a total of 525 every time, no matter what! Not sure why the case rules aren't working!

Edit #4:
Okay - I got fed up so I ended up going with this. However, this code for some reason deducts double what I calculate it should do. For example, those with 0 ipoints, gets deducted 300 instead of 150, and those with 1 ipoint get deducted 750 instead of 375.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I know this isn't the most efficient way - but it's the most working I could get it to so far!

Last edited by Chris.08i; 16 Dec 2015 at 11:51.
Reply With Quote
  #8  
Old 17 Dec 2015, 16:05
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Real name: Mark
This plugin works correctly on my local dev site:

Product: vBulletin

Hook Location: infractiondata_postsave

Title: Deduct Rep When Infracting

Execution Order: 5

Plugin PHP Code:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Plugin is Active: Yes
__________________
Former vBulletin.org Staff Member



Support for my products (as well as updates/new product publishing) has been moved to MHB - vBulletin Products and TAZ - Add-ons
Reply With Quote
  #9  
Old 19 Dec 2015, 11:33
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
I had an adaptation of mine that I have been using for the past couple days that have been working for me.

I have changed over to your code as it's much neater! Thank you again Mark for your time and help!

I was wondering if it was possible to only trigger the above deduction when an actual point is issued, and no deduction for warnings?
Reply With Quote
  #10  
Old 19 Dec 2015, 11:54
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Real name: Mark
Originally Posted by Chris.08i View Post
I had an adaptation of mine that I have been using for the past couple days that have been working for me.

I have changed over to your code as it's much neater! Thank you again Mark for your time and help!

I was wondering if it was possible to only trigger the above deduction when an actual point is issued, and no deduction for warnings?
Do you mean then a deduction based only on the points being issued at the time, and not on the cumulative total of active points? If so, I would have to investigate to see how to retrieve that value.

The code I posted does exactly the opposite of that...it uses $userinfo['ipoints'] which does not include the points currently being given, but rather the number of points accumulated by the user before the current infraction.

edit: Try using the hook location "infraction_update_complete", and at that hook, the points for the current infraction is in $vbulletin->GPC['points']. Then you can base the rep deduction on that and update the user table.
__________________
Former vBulletin.org Staff Member



Support for my products (as well as updates/new product publishing) has been moved to MHB - vBulletin Products and TAZ - Add-ons

Last edited by MarkFL; 19 Dec 2015 at 12:04.
Reply With Quote
  #11  
Old 19 Dec 2015, 23:59
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
Originally Posted by MarkFL View Post
Do you mean then a deduction based only on the points being issued at the time, and not on the cumulative total of active points? If so, I would have to investigate to see how to retrieve that value.

The code I posted does exactly the opposite of that...it uses $userinfo['ipoints'] which does not include the points currently being given, but rather the number of points accumulated by the user before the current infraction.

edit: Try using the hook location "infraction_update_complete", and at that hook, the points for the current infraction is in $vbulletin->GPC['points']. Then you can base the rep deduction on that and update the user table.
No, the current script works fine. I want it to deduct based on the current active points, so using ipoints is correct.

However, I don't want to issue and deduction when the user is only issued a warning (infraction without points).
Reply With Quote
  #12  
Old 20 Dec 2015, 02:27
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Real name: Mark
If you use the code I posted in post #8, then the deduction will be based on the accumulated active points prior to the infraction being issued. So, for example, suppose a user has 3 active points, and you then issue a warning...$userinfo['ipoints'] will be equal to 3.

But, if you use the hook location and variable I suggested in post #10, then $vbulletin->GPC['points'] will be equal to 0.
__________________
Former vBulletin.org Staff Member



Support for my products (as well as updates/new product publishing) has been moved to MHB - vBulletin Products and TAZ - Add-ons
Reply With Quote
  #13  
Old 22 Dec 2015, 21:40
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
Hi Mark


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This is what my revised code looked like, on the hook that you suggested. I'm getting a server 500 error when I try to issue a warning.

Any ideas?
Reply With Quote
  #14  
Old 22 Dec 2015, 21:57
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Real name: Eric
why are you using continue without a loop?

I would remove this, it is rather pointless in that code:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

or comment it out until you are ready to do something with it. This might be the cause of your 500 error
Reply With Quote
  #15  
Old 23 Dec 2015, 00:23
Chris.08i Chris.08i is offline
 
Join Date: Oct 2008
Originally Posted by Dragonsys View Post
why are you using continue without a loop?

I would remove this, it is rather pointless in that code:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

or comment it out until you are ready to do something with it. This might be the cause of your 500 error
I am trying to prevent the bottom code from running if the infraction points being handed out = 0.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 01:56.

Layout Options | Width: Wide Color: