phpBB

Development Wiki

Difference between revisions of "Migrations/Data Changes/Custom"

From phpBB Development Wiki

m
(Note: the function called, must be public accessible)
 
Line 11: Line 11:
 
     array(&$this, 'some_function')
 
     array(&$this, 'some_function')
 
)),</php>
 
)),</php>
 +
'''Note:''' the function called, must be public accessible
  
 
==Multi step processes==
 
==Multi step processes==

Latest revision as of 09:54, 7 May 2013

Custom calls allow you to specify the callable to your own function to be called.

How it works

array('custom', array(
    array(
/* Callable function, sent to call_user_func_array */)
)),

Example

Call a function within the migrations file named some_function

array('custom', array(
    array(&
$this'some_function')
)),

Note: the function called, must be public accessible

Multi step processes

If you have a function that needs to be called multiple times to complete, returning anything except null or true will cause the function to be called until null or true is returned.

When this should be used

This should be used when something needs to be run that can take longer than the time limit (for example, resyncing topics).

Example

public function update_data()
{
    return array(
        array(
'custom', array(
            array(&
$this'some_function')
        )),
    );
}

// $value is equal to the value returned on the previous call (false if this is the first time it is run)
public function some_function($value)
{
    
$limit 500;
    
$i 0;

    
// Select all topics, starting at $value, limit $limit
    
while ($topic fetchrow)
    {
        
$i++;

        
// Do something
    
}

    if (
$i $limit)
    {
        
// There are no more topics, we are done
        
return;
    }

    
// There are still more topics to query, return the next start value
    
return $value $limit;
}