PDA

View Full Version : How to decrease count in database automatically?


Simon Lloyd
06-08-2009, 07:29 AM
Hi all,
Currently i have two plug-ins to count "Top Tips" that are submitted by a form to a specific forum, every member of my forums has a "My Top Tips" count in their info bar along with a button to submit more if they wish.

My problem is they can submit a tip and the count increases fine, so mine shows 5, joe bloggs will show 3....etc however if the post is deleted the figure doesn't decrease and i have to go to the database and change the count manually, can anyone tweak my plugins to do this automatic please?


PRODUCT: VBulletin
HOOK LOCATION: postbit_display_start
EXECUTION ORDER: 5
eval('$template_hook[postbit_userinfo_right] .= " ' . fetch_template('postbit_ctoptip') . '";');
PRODUCT: VBulletin
HOOK LOCATION: newthread_post_complete
EXECUTION ORDER: 5
if (in_array($foruminfo['forumid'], array('52'))) {
$db->query_write("UPDATE vb_user SET ctoptip = ctoptip + 1 WHERE userid=" . $vbulletin->userinfo['userid']);
}and this is the content of the template postbit_ctoptip
<if condition="$post['ctoptip']>= '1'">$post[ctoptip] Top Tips<br /></if>

Lynne
06-08-2009, 03:45 PM
You'll need to add a plugin that is called when the post is deleted and then change the count there. When in debug mode, go to delete a post and all the hook locations that are available on that page will be listed on the bottom of the page.

Simon Lloyd
06-08-2009, 04:09 PM
You'll need to add a plugin that is called when the post is deleted and then change the count there. When in debug mode, go to delete a post and all the hook locations that are available on that page will be listed on the bottom of the page.Lynne how do i set vbulletin in debug mode?

Lynne
06-08-2009, 04:28 PM
Add this at the top of your config.php file right under <?php :
$config['Misc']['debug'] = true;

I would suggest only doing this on your test site, or putting a condition around that to only show it to your IP.

Simon Lloyd
06-08-2009, 04:38 PM
Add this at the top of your config.php file right under <?php :
$config['Misc']['debug'] = true;

I would suggest only doing this on your test site, or putting a condition around that to only show it to your IP.
Thanks for that, i don't have a test site and i think it will be ok as it will only be for a few minutes :)

--------------- Added 1244483578 at 1244483578 ---------------

Lynne, could you tell me which hook i should use for the plugin?
Hooks Called:
init_startup
fetch_userinfo_query

style_fetch
cache_templates
global_start
parse_templates

notifications_list
global_setup_complete

I have this line to remove from the count:
if (in_array($foruminfo['forumid'], array('52'))) {
$db->query_write("UPDATE vb_user SET ctoptip = ctoptip -1 WHERE userid=" . $vbulletin->userinfo['userid'] . " and ctoptip > 0");


--------------- Added 1244485448 at 1244485448 ---------------

The above were the hooks called prior to me choosing soft or permanent delete!

Simon Lloyd
06-09-2009, 04:49 PM
Lynne any thoughts with this?

Lynne
06-09-2009, 05:04 PM
What script is it you are calling to delete the post? Are you talking about a user deleting it or a mod deleting it? Both of those are different scripts. You'll have different hooks called for each. If a user is doing it in the post, perhaps an editpost_ hook. Go see where those are and if one of them makes sense to use (do a search through your files for "editpost_"). If it's the Moderator dropdown box (so a moderator), then that takes you to the inlinemoderation.php page. Take a look at that page for which hooks are used.

Simon Lloyd
06-09-2009, 05:21 PM
What script is it you are calling to delete the post? Are you talking about a user deleting it or a mod deleting it? Both of those are different scripts. You'll have different hooks called for each. If a user is doing it in the post, perhaps an editpost_ hook. Go see where those are and if one of them makes sense to use (do a search through your files for "editpost_"). If it's the Thread Tools (so a moderator), then that takes you to the inlinemoderation.php page. Take a look at that page for which hooks are used.Its when a mod or admin deletes the post.....users do not hav ethe permissions to delete. If your sure its an editpost_...etc hook i'll try a few of them until it works :)
Thanks!

--------------- Added 1244572968 at 1244572968 ---------------

im going to try this hook: inlinemod_deletethread

--------------- Added 1244573206 at 1244573206 ---------------

It didnt work with the plugin code but didn't cause an error

Lynne
06-09-2009, 08:17 PM
What did you put in the inlinemod_deletethread plugin? Did you find that hook location in the code and verify the variables you are using are correct? (And I thought you were deleting a post, not a thread.)

Simon Lloyd
06-10-2009, 07:02 PM
Hi Lynne, the post/thread will be un answerable the thread is created by a form, users do not have permission to reply or post, so in effect im deleting the thread, im using this in the plugin
if (in_array($foruminfo['forumid'], array('52'))) {
$db->query_write("UPDATE vb_user SET ctoptip = ctoptip -1 WHERE userid=" . $vbulletin->userinfo['userid'] . " and ctoptip > 0");

Lynne
06-10-2009, 07:43 PM
If you locate that hook and look at the code above it, you won't see $foruminfo used at all, so I doubt that is a valid variable. Take a look at the script and see what they are using to define the forumid.