XenForo Deferred Pre-Execute?

Robust

Well-known member
Hey,

So I'm making a rebuilding task to rebuild quite a bit of data.

First, however, I need to reset data.

I have (sometimes multiple) columns in xf_post, xf_user and xf_thread.

If I'm rebuilding data of course I'm going to be generating new 'cached' data from the actual table with the data. So I'm going to need to reset the existing data in those 3 tables which is more 'quickhand' data.

The easiest way (and best way, probably) to do it would be if I could run a pre_execute task which is ran only once before the execute task is ran. Then I could just do:

Code:
        $db->query('
            UPDATE xf_post
            SET field = 0
        ');

        $db->query('
            UPDATE xf_thread
            SET field =0
        ');

        $db->query('
            UPDATE xf_user
            SET field = 0
        ');

Pretty generic and I'd imagine it'd be done relatively quickly. Then I can start rebuilding data and repopulating those fields of information for the data.

If I put this at the top of an execute, as far as I know, it'd be ran in every batch. So if an array is returned in a batch (not a boolean false) it would run the deferred task again until a false value is returned, I believe. So this query would keep getting re-ran and that's just pointless.

Sadly though, I don't think a pre execute function/ability exists. So what can I do to do this?
 
If you consider the default data you would generally have set up in a deferred task, e.g.
PHP:
$data = array_merge(array(
    'position' => 0,
    'batch' => 100
), $data);
Well if you were to store an additional value in the $data, e.g.
PHP:
$data = array_merge(array(
    'position' => 0,
    'batch' => 100,
    'preExecuteRan' => false
), $data);

So you could do:
PHP:
if (!$data['preExecuteRan'])
{
    // Run your pre-execute here.
    $data['preExecuteRan'] = true;
}

That 'true' value will be maintained across each batch so, effectively, that code will only run once.
 
Top Bottom