Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

migrate_category_tree_to_nodes()

Parameters

ColumnTypeDefaultDescription
$resource_type_field_ref
$category_tree_options

Location

include/migration_functions.php lines 63 to 106

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 4th December 2024 08:35 Europe/London time based on the source file dated 15th April 2024 16:05 Europe/London time.