phpBB

Development Wiki

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

From phpBB Development Wiki

(Created page with "Custom calls allow you to specify the callable to your own function to be called. ==How it works== <php>array('custom', array( array(/* Callable function, sent to call_us...")
 
m
Line 19: Line 19:
  
 
===Example===
 
===Example===
Call a function within the migrations file named some_function
 
 
<php>public function update_data()
 
<php>public function update_data()
 
{
 
{

Revision as of 23:29, 13 January 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')
)),

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;
}