PDA

View Full Version : Deleting Duplicate Threads That Do NOT Share The Same Timestamp


TruthElixirX
01-13-2009, 03:22 PM
I need to delete some duplicate threads, but they do not have the same time stamp.

I opened up admincp/misc.php and went to:


$threads = $db->query_read("
SELECT threadid, title, forumid, postusername, dateline
FROM " . TABLE_PREFIX . "thread WHERE threadid >= " . $vbulletin->GPC['startat'] . "
ORDER BY threadid
LIMIT " . $vbulletin->GPC['perpage']
);

$finishat = $vbulletin->GPC['startat'];

while ($thread = $db->fetch_array($threads))
{
$deletethreads = $db->query_read("
SELECT *
FROM " . TABLE_PREFIX . "thread
WHERE title = '" . $db->escape_string($thread['title']) . "' AND
forumid = $thread[forumid] AND
postusername = '" . $db->escape_string($thread['postusername']) . "' AND
dateline = $thread[dateline] AND
threadid > $thread[threadid]
");


and changed it to (I removed what was colored blue above) :


$threads = $db->query_read("
SELECT threadid, title, forumid, postusername
FROM " . TABLE_PREFIX . "thread WHERE threadid >= " . $vbulletin->GPC['startat'] . "
ORDER BY threadid
LIMIT " . $vbulletin->GPC['perpage']
);

$finishat = $vbulletin->GPC['startat'];

while ($thread = $db->fetch_array($threads))
{
$deletethreads = $db->query_read("
SELECT *
FROM " . TABLE_PREFIX . "thread
WHERE title = '" . $db->escape_string($thread['title']) . "' AND
forumid = $thread[forumid] AND
postusername = '" . $db->escape_string($thread['postusername']) . "' AND
threadid > $thread[threadid]
");


This gets rid of the time stamp requirement, but now, I need to limit it to a specific username/id. How do I do this?

Bellardia
01-13-2009, 03:30 PM
AND postuserid = $thread[postuserid]
but it's already limited by..
postusername = '" . $db->escape_string($thread['postusername']) . "'

TruthElixirX
01-13-2009, 03:44 PM
AND postuserid = $thread[postuserid]
but it's already limited by..
postusername = '" . $db->escape_string($thread['postusername']) . "'

So I would put the username I wish to limit it to in

$thread['postusername']

So it would look like:

$thread['test']

for example?

Bellardia
01-13-2009, 07:54 PM
$thread['test'] would have no value because there's no column 'test' on the thread database. You could just replace the whole string by
postusername = 'test' but depending on where you run the script it would always delete threads from test even if it was someone else's fault..

Where do you plan on placing this?

TruthElixirX
01-13-2009, 08:14 PM
$thread['test'] would have no value because there's no column 'test' on the thread database. You could just replace the whole string by
postusername = 'test' but depending on where you run the script it would always delete threads from test even if it was someone else's fault..

Where do you plan on placing this?

I plan putting it in that section of admincp/misc.php and altering it for this one time use to cull some duplicate content, then reverting back to how it should be.


What do you mean by "would always delete threads from test even if it was someone else's fault." ?

Bellardia
01-13-2009, 11:51 PM
Well I wasn't sure where you were pulling the code from.
It uses a variable as the username based on the thread that it's being performed on, so if you defined the name explicitly it would only work on threads based on the title of the thread you're using this on made by the user you've defined. Depending on how you do that it could be 0 threads.