Log in

View Full Version : HELP - auto move thread back when redirect expires


Mutt
04-04-2009, 07:49 PM
I often make a thread, move it w/ redirect for a week, & then move it back. I'd love to use the "Leave Expiring Redirect" option to automatically move the thread back

Just above hook cron_script_cleanup_hourly in /include/cron/cleanup.php there's this code that deletes the moved redirect at expiration
// delete expired thread redirects
$threads = $vbulletin->db->query_read("
SELECT threadid
FROM " . TABLE_PREFIX . "threadredirect
WHERE expires < " . TIMENOW . "
");

while ($thread = $vbulletin->db->fetch_array($threads))
{
$thread['open'] = 10;
$threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
$threadman->set_existing($thread);
$threadman->delete(false, true, NULL, false);
unset($threadman);
}


I've looked at how redirects work. here's my understanding of it

when you move a thread, it changes the forumid field for the row in thread with that thread ID. It's my understanding that it then updates the forum thread & post counts for both forums.
when you leave a redirect it makes a duplicate of the above row in thread with a new thread ID & the above thread ID stored under pollid.
when you set the redirect to expire, it makes a new entry to threadredirect w/ the above threadID & the time it should be expired
when cleanup.php is run via cron, the above code checks the dates of threadredirect & deletes the entry in thread for that threadid


I just don't understand all the datamanager_init / set_existing stuff. I know what it's doing but I don't know how / why. i don't know how to set it or use it.


My plan is to add a field to threadredirect called "return" & use it to store the old forumid & the real threadid. (threadid|forumid)
then I'd modify the above code in cleanup.php (just inside the while) to look for "return". if it's there split it & update the original thread row with the returning forum id.

Doing that via an UPDATE, SET= thing would be easy but I'd like to update the row using the datamanager_init deal so the forum post & thread counts are corrected. can someone tell me how that thing works?

I known I need to change it to something like the following but need some feedback. is it ok to use varname $threadman because of the unset line? do I need to do more?
$threads = $vbulletin->db->query_read("
SELECT threadid, return
FROM " . TABLE_PREFIX . "threadredirect
WHERE expires < " . TIMENOW . "
");

while ($thread = $vbulletin->db->fetch_array($threads))
{
if ($thread['return']) {
list($returntid, $returnfid) = split('|', $thread['return']);
$returnthread['threadid']=$returntid;
$threadman=&datamanager_init('Thread', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$threadman->set_existing($returnthread);
$threadman->set('forumid', $returnfid);
$threadman->save();
unset($threadman);
}
$thread['open'] = 10;
$threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
$threadman->set_existing($thread);
$threadman->delete(false, true, NULL, false);
unset($threadman);
}

any help understanding this would be greatly appreciated. even if it's just recommending an existing hack that I can look at as an example.

forgive my ignorance. I love hacking the VB code but I'm still learning v3 & my brain is still stuck in v2. the new ways still confuse me a little

thanks in advance