The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
[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']) . ')' ); Code:
$db->shutdown_query(" DELETE FROM " . TABLE_PREFIX . "threadviews (threadid) VALUES (" . intval($threadinfo['threadid']) . ')' ); i have also tried Code:
$vbulletin->db->query Code:
$db->query 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 "); |
#2
|
||||
|
||||
You need something like:
PHP Code:
|
#3
|
||||
|
||||
Quote:
You final code is fine, but you dont actually need the LIMIT 1. |
#4
|
||||
|
||||
Quote:
thread views table looks like Code:
8 8 8 8 3 1 6 8 8 8 update**** the problem with the method im using Code:
$vbulletin->db->query_write(" DELETE FROM " . TABLE_PREFIX . "threadviews WHERE threadid = $threadinfo[threadid] LIMIT 1 "); |
#5
|
||||
|
||||
Quote:
I guess I dont understand your actual objective then. Quote:
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. |
#6
|
||||
|
||||
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']) . ')' ); 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 "); } 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. |
#7
|
||||
|
||||
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). |
#8
|
||||
|
||||
Quote:
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']) . ')' ); } } im trying to do the same exact thing only without having to edit the showthread.php |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|