Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

migrate_category_tree_to_nodes()

Parameters

ColumnTypeDefaultDescription
$resource_type_field_ref
$category_tree_options

Location

include/migration_functions.php lines 47 to 90

Definition

 
function migrate_category_tree_to_nodes($resource_type_field_ref,$category_tree_options)
    {
    
$options = array();
    
$option_lines preg_split('/\r\n|\r|\n/',$category_tree_options);
    
$order 10;

    
// first pass insert current nodes into nodes table
    
foreach ($option_lines as $line)
        {
        
$line_fields preg_split('/\s*,\s*/'$line);
        if (
count($line_fields) != 3)
        {
            continue;
        }
        
$id trim($line_fields[0]);
        
$parent_id trim($line_fields[1]);
        
$name trim($line_fields[2]);
        
$ref set_node(null,$resource_type_field_ref,$name,null,$order);

        
$options['node_id_' $id] = array(
            
'id' => $id,
            
'name' => $name,
            
'parent_id' => $parent_id,
            
'order' => $order,
            
'ref' => $ref
        
);
        
$order+=10;
        }

    
// second pass is to set parent refs
    
foreach ($options as $option)
        {
        
$ref $option['ref'];
        
$name $option['name'];
        
$order$option['order'];
        
$parent_id $option['parent_id'];
        if (
$parent_id == '')
        {
            continue;
        }
        
$parent_ref = isset($options['node_id_' $parent_id]) ? $options['node_id_' $parent_id]['ref'] : null;
        
set_node($ref,$resource_type_field_ref,$name,$parent_ref,$order);
        }
    }

This article was last updated 10th July 2020 00:35 Europe/London time based on the source file dated 24th June 2020 15:23 Europe/London time.