Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-10-2016, 08:06 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [HELP] Removing row from table plugin query

so ive got my plugin at showthread_complete, its working pretty good =)

but im trying to add a query to it that reverses something done in showthread.php

This is the code straight from showthread.php
Code:
$db->shutdown_query("
  INSERT INTO " . TABLE_PREFIX . "threadviews (threadid)
  VALUES (" . intval($threadinfo['threadid']) . ')'
);
So I would think to reverse that my plugin would have to be
Code:
$db->shutdown_query("
  DELETE FROM " . TABLE_PREFIX . "threadviews (threadid)
  VALUES (" . intval($threadinfo['threadid']) . ')'
);
This doesnt give me an error, but it's not working, and threadviews table still continues to grow.

i have also tried
Code:
$vbulletin->db->query
Code:
$db->query
both resulting in database errors.

The goal:
if vb options are not set to update view counts immediately, each view is stored in the threadviews table. this happens with that first block of code from showthread.php

so when you view a thread that query runs, i want my query to just delete the row that first query added.

i have got this all worked out if admins update threads immediately, but i don't want to dictate their having to choose that option.

--------------- Added [DATE]1457655461[/DATE] at [TIME]1457655461[/TIME] ---------------

this is working
Code:
$vbulletin->db->query_first("
DELETE FROM " . TABLE_PREFIX . "threadviews
WHERE threadid = $threadinfo[threadid]
LIMIT 1
");
is it proper?
Reply With Quote
  #2  
Old 03-10-2016, 10:19 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need something like:

PHP Code:
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "threadviews
    WHERE threadid = " 
intval($threadinfo['threadid'])
); 
Reply With Quote
  #3  
Old 03-10-2016, 11:05 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
so ive got my plugin at showthread_complete, its working pretty good =)

but im trying to add a query to it that reverses something done in showthread.php

This is the code straight from showthread.php
Code:
$db->shutdown_query("
  INSERT INTO " . TABLE_PREFIX . "threadviews (threadid)
  VALUES (" . intval($threadinfo['threadid']) . ')'
);
So I would think to reverse that my plugin would have to be
Code:
$db->shutdown_query("
  DELETE FROM " . TABLE_PREFIX . "threadviews (threadid)
  VALUES (" . intval($threadinfo['threadid']) . ')'
);
This doesnt give me an error, but it's not working, and threadviews table still continues to grow.

i have also tried
Code:
$vbulletin->db->query
Code:
$db->query
both resulting in database errors.

The goal:
if vb options are not set to update view counts immediately, each view is stored in the threadviews table. this happens with that first block of code from showthread.php

so when you view a thread that query runs, i want my query to just delete the row that first query added.

i have got this all worked out if admins update threads immediately, but i don't want to dictate their having to choose that option.

--------------- Added [DATE]1457655461[/DATE] at [TIME]1457655461[/TIME] ---------------

this is working
Code:
$vbulletin->db->query_first("
DELETE FROM " . TABLE_PREFIX . "threadviews
WHERE threadid = $threadinfo[threadid]
LIMIT 1
");
is it proper?
The original code will throw a database error, you just wont see it because its being run as a shutdown query.

You final code is fine, but you dont actually need the LIMIT 1.
Reply With Quote
  #4  
Old 03-11-2016, 01:53 AM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Paul M View Post
The original code will throw a database error, you just wont see it because its being run as a shutdown query.

You final code is fine, but you dont actually need the LIMIT 1.
without the limit 1 it erases every entry of that that thread id

thread views table looks like
Code:
8
8
8
8
3
1
6
8
8
8
if i remove limit 1 and view thread 8, all of its instances get removed and when the cron runs to update thread view its not accurate.


update****

the problem with the method im using
Code:
$vbulletin->db->query_write("
  DELETE FROM " . TABLE_PREFIX . "threadviews
  WHERE threadid = $threadinfo[threadid]
  LIMIT 1
");
is if there is no row with that threadID in the threadviews table it adds the original view to the table.

Attached Images
File Type: jpg 2016-03-10_23-17-49.jpg (52.4 KB, 0 views)
Reply With Quote
  #5  
Old 03-11-2016, 03:49 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
without the limit 1 it erases every entry of that that thread id
Is that not what you are trying to do ?
I guess I dont understand your actual objective then.

Quote:
Originally Posted by Dr.CustUmz View Post
the problem with the method im using
Code:
$vbulletin->db->query_write("
  DELETE FROM " . TABLE_PREFIX . "threadviews
  WHERE threadid = $threadinfo[threadid]
  LIMIT 1
");
is if there is no row with that threadID in the threadviews table it adds the original view to the table.
A delete query cannot add anything, ever.

You are using shutdown queries, which quite possibly get run backwards to how you define them (there isnt any guarantee what order they will run). So more likely the delete is running first, then the insert. You wont notice this if there is at least one existing record, but you will if there are none.
Reply With Quote
  #6  
Old 03-11-2016, 04:45 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

the goal is to remove the insert that showthread.php adds through a plugin

this is the query in showthread.php
Code:
$db->shutdown_query("
  INSERT INTO " . TABLE_PREFIX . "threadviews (threadid)
  VALUES (" . intval($threadinfo['threadid']) . ')'
);
i can make it do what i want by editing the showthread.php using if conditions, but im trying make it so there are no file edits.

so i have my plugin set to
Code:
if  ($thread['postuserid']==$vbulletin->userinfo['userid']){
  $vbulletin->db->query_first("
    DELETE FROM " . TABLE_PREFIX . "threadviews
    WHERE threadid = $threadinfo[threadid]
    LIMIT 1
");
}
this is saying if thread viewer is thread starter remove the view that the showthread query added.

BUT

if the thread has no views in the time the cron keeps them in the threadviews table (before placing them in thread table >views column) on the hour for most forums. it will add a view to the threadviews table even if it is thread starter viewing.
Reply With Quote
  #7  
Old 03-11-2016, 08:27 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still dont understand the objective, why do you want to remove that record ?

Two things ;

1. Dont use db->query_first() on the delete, thats for table reads. I believe its db->query_write() you need, but Im unable to check that where I am located atm.

2. What you are doing atm isnt going to work properly, because you are running the delete before the insert.

You need to remember that shutdown queries are run when all the page processing has completed - just before vb sends the actual html back to the client (and shuts down).
Reply With Quote
  #8  
Old 03-12-2016, 01:40 AM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Paul M View Post
I still dont understand the objective, why do you want to remove that record ?

Two things ;

1. Dont use db->query_first() on the delete, thats for table reads. I believe its db->query_write() you need, but Im unable to check that where I am located atm.

2. What you are doing atm isnt going to work properly, because you are running the delete before the insert.

You need to remember that shutdown queries are run when all the page processing has completed - just before vb sends the actual html back to the client (and shuts down).
the recored is being removed, so if thread starter views his own thread the view counter does not go up

this is how i came up with this, i edited showthread.php (search for // update views counter)
and came up with this.
Code:
// update views counter
if ($vbulletin->options['threadviewslive']) {
  // doing it as they happen; for optimization purposes, this cannot use a DM!
  if ($vbulletin->userinfo['userid'] == 0) {
    // ignore guest
  } elseif ($thread['postuserid']==$vbulletin->userinfo['userid']) {
    // ignore thread poster
  } else {
    $db->shutdown_query("
      UPDATE " . TABLE_PREFIX . "thread
      SET views = views + 1
      WHERE threadid = " . intval($threadinfo['threadid'])
    );
  }
} else {
  // or doing it once an hour
  if ($vbulletin->userinfo['userid'] == 0) {
    // ignore guest
  } elseif ($thread['postuserid']==$vbulletin->userinfo['userid']) {
    // ignore thread poster
  } else {
    $db->shutdown_query("
      INSERT INTO " . TABLE_PREFIX . "threadviews (threadid)
      VALUES (" . intval($threadinfo['threadid']) . ')'
    );
  }
}
works 100%

im trying to do the same exact thing only without having to edit the showthread.php
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 03:22 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06602 seconds
  • Memory Usage 2,276KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (16)bbcode_code
  • (1)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (1)postbit_attachment
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete