How to create a Cron Entry to move threads (with options!)

How to create a Cron Entry to move threads (with options!) 1.0

No permission to download

Fuhrmann

Well-known member
Fuhrmann submitted a new resource:

How to create a Cron Entry to move threads (with options!) (version 1.0) - I will teach you how to create a new cron to move threads from a forum to another.

Objective:
This tutorial was made based on this thread.

I will teach you how to create a new cron entry to move all threads with a specified prefix from forum X to forum Y and run it once a day.

I strongly recommend you to read my others tutorials to know better how XenForo works:...

Read more about this resource...
 
thanks, is it possible to setup a cron job where all x days old && soft deleted thread get move to a separate section ?
 
Excellent tutorial, @Fuhrmann , thanks for posting.

I notice that it has been 2 years since the tutorial was updated. Has anything changed in terms of best practices since then?

In particular, is it still a good idea to use a datawriter object to change the 'node_id' to move a thread from one forum to another? Or is there a higher level way of doing it?
 
Thanks a lot @Fuhrmann . I've a (noob) doubt -

PHP:
$threads = $threadModel->getThreads($conditionals, $fetchOptions);

The arguments $conditionals and $fetchOptions basically hold the values set in the AdminCP and have already been fetched into $cronOptions array. Why not simply reference them in getThreads instead of first separating them out in '$conditionals' and '$fetchOptions'?

Something like
PHP:
getThreads($cronOptions['fromForum'],$cronOptions['fromPrefix'],$cronOptions['amount'])
?

PS: Not sure if above line makes any sense :) Would appreciate your response.
 
Thank you so much for making and sharing that tutorial! It got me over one of the hurdles for an add-on I'm working on.

I do have one technical question: when I update the code in CronEntry.php, do I need to do anything to make xenForo refresh, or does it always read the latest version of that file?

UPDATE: never mind, I just figured it out empirically by inserting a typo. In case anyone else has the same question: I can confirm that at least every time I manually run the cron job, the code is reloaded.
 
Does anyone else get the following error when they run this addon?
Code:
Server Error Log
Error Info
ErrorException: Cannot modify header information - headers already sent by (output started at /home/ouruser/public_html/forum/library/MoveThreadCron/CronEntry.php:1) - deferred.php:26
Generated By: Unknown Account, Wednesday at 8:01 AM
Stack Trace

#0 [internal function]: XenForo_Application::handlePhpError(2, 'Cannot modify h...', '/home/ouruser/publ...', 26, Array)
#1 /home/ouruser/public_html/forum/deferred.php(26): header('Content-Type: a...')
#2 {main}

Request State

array(3) {
  ["url"] => string(41) "http://www.ourdomain.org/forum/deferred.php"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(3) {
    ["_xfRequestUri"] => string(7) "/forum/"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfResponseType"] => string(4) "json"
  }
}

I'd love to know how to modify the code to avoid it.
 
Back
Top Bottom